Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
SermetPekin committed Apr 20, 2024
1 parent df19623 commit 2b23134
Show file tree
Hide file tree
Showing 7 changed files with 250 additions and 58 deletions.
41 changes: 34 additions & 7 deletions evdspy/EVDSlocal/config/apikey_class.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@

from ..common.common_imports import *
from dataclasses import dataclass, field
from typing import Union
from enum import Enum, auto
from ..config.config import config
from ..messages.error_classes import ApiKeyNotSetError


class ApiKeyType(Enum):
runtime = auto()
from_file = auto()
from_file_options = auto()


@dataclass
class ApiKeyValue:
name: str
value: Union[str, bool] = False
type_: ApiKeyType = ApiKeyType.runtime


class ApiKeyDict:
runtime_apikey: ApiKeyValue
from_file_apikey: ApiKeyValue
from_file_options_api_key: ApiKeyValue

def __init__(self):
self.runtime_apikey = ApiKeyValue("runtime", False, ApiKeyType.runtime)
self.from_file_apikey = ApiKeyValue("fromfile", False, ApiKeyType.from_file)
self.from_file_options_api_key = ApiKeyValue("fromfile_options", False, ApiKeyType.from_file_options)

def set_value(self, type_: Union[str, ApiKeyType], value):
if type_ in ["runtime", ApiKeyType.runtime]:
self.runtime_apikey.value = value
Expand All @@ -30,23 +37,30 @@ def set_value(self, type_: Union[str, ApiKeyType], value):
self.from_file_apikey.value = value
return
self.from_file_options_api_key = value


import time


class ApikeyClass(object):
def __new__(cls):
if not hasattr(cls, 'instance'):
cls.instance = super(ApikeyClass, cls).__new__(cls)
cls.post_init(cls)
return cls.instance

def __repr__(cls):
return f"""
cls.now_testing_is_key_is_valid: {cls.now_testing_is_key_is_valid:}
cls.current_key_using : {cls.current_key_using}
cls.APIKEYDict : {cls.APIKEYDict}
"""

def post_init(cls):
cls.APIKEYDict: ApiKeyDict = ApiKeyDict()
cls.now_testing_is_key_is_valid: Union[str, bool] = False
cls.current_key_using: Union[str, bool] = cls.APIKEYDict.runtime_apikey.value

def no_api_msg(self):
template = f"""
Api Key not set yet.
Expand All @@ -65,6 +79,7 @@ def no_api_msg(self):
python> save()
"""
print(template)

def get_valid_api_key(cls, check=False):
if cls.now_testing_is_key_is_valid:
return cls.now_testing_is_key_is_valid
Expand All @@ -78,14 +93,18 @@ def get_valid_api_key(cls, check=False):
return "VALID_KEY_FOR_TEST"
return False
return key_objs[0].value

@property
def key(self):
if config.current_mode_is_test:
return "VALID_KEY_FOR_TEST"
key = self.get_valid_api_key(check=True)
return key
def obscure(self):
key = self.key

@staticmethod
def obscure(key=None):
if key is None:
key = ApikeyClass().key
if not isinstance(key, str):
return "..."
strings = []
Expand All @@ -95,27 +114,35 @@ def obscure(self):
else:
strings.append(i)
return "".join(strings)

def set_api_key_runtime(cls, value: str):
cls.instance.APIKEYDict.set_value(ApiKeyType.runtime, value)
return cls.instance.APIKEYDict.runtime_apikey.value

def set_api_key_filetype(cls, value: str):
cls.instance.APIKEYDict.set_value(ApiKeyType.from_file, value)
return cls.instance.APIKEYDict.from_file_apikey.value

def set_api(cls, key: str):
print("set api not implemented")
raise "set api not implemented"

def get_api_keys(cls):
keys = [
cls.instance.APIKEYDict.runtime_apikey,
cls.instance.APIKEYDict.from_file_apikey,
cls.instance.APIKEYDict.from_file_options_api_key,
cls.instance.APIKEYDict.runtime_apikey,
cls.instance.APIKEYDict.from_file_apikey,
cls.instance.APIKEYDict.from_file_options_api_key,
]
return [x for x in keys if x.value is not False]

def get_api_keys_dict(cls):
return cls.instance.APIKEYDict

def get_api_key_runtime(cls):
return cls.instance.APIKEYDict.runtime_apikey.value

def get_api_key_fromfile(cls):
return cls.instance.APIKEYDict.from_file_apikey.value

def get_api_key_fromfile_options(cls):
return cls.instance.APIKEYDict.from_file_options_api_key
return cls.instance.APIKEYDict.from_file_options_api_key
5 changes: 4 additions & 1 deletion evdspy/EVDSlocal/index_requests/get_series_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import pandas as pd
from evdspy.EVDSlocal.config.apikey_class import ApikeyClass
from evdspy.EVDSlocal.index_requests.get_series_indexes_utils import default_start_date_fnc, default_end_date_fnc
from evdspy.EVDSlocal.index_requests.user_requests import ProxyManager, UrlBuilder, ApiRequester, \
from evdspy.EVDSlocal.index_requests.user_requests.user_requests import ProxyManager, UrlBuilder, ApiRequester, \
DataProcessor, RequestConfig



def initial_api_process_when_given(api_key: Optional[str] = None) -> None:
if api_key is None:
return
Expand Down
Empty file.
Loading

0 comments on commit 2b23134

Please sign in to comment.