From b00b62fa96997f1f3c318b48635e68085f13e22a Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Mon, 25 Nov 2024 14:09:36 +0530 Subject: [PATCH] SK-1731: Fixed unit test cases --- skyflow/utils/_skyflow_messages.py | 260 +++++++++++++++-------------- skyflow/utils/_utils.py | 10 +- skyflow/vault/client/client.py | 19 +-- tests/constants/test_constants.py | 4 +- tests/utils/test__utils.py | 21 +-- tests/vault/client/test__client.py | 4 +- 6 files changed, 156 insertions(+), 162 deletions(-) diff --git a/skyflow/utils/_skyflow_messages.py b/skyflow/utils/_skyflow_messages.py index fd1eaa6..8a8e8dd 100644 --- a/skyflow/utils/_skyflow_messages.py +++ b/skyflow/utils/_skyflow_messages.py @@ -3,6 +3,8 @@ from ._version import SDK_VERSION error_prefix = f"Skyflow Python SDK {SDK_VERSION}" +INFO = "INFO" +ERROR = "ERROR" class SkyflowMessages: class ErrorCodes(Enum): @@ -141,137 +143,137 @@ class Error(Enum): INVALID_JSON_FORMAT_IN_CREDENTIALS_ENV = f"{error_prefix} Validation error. Invalid JSON format in SKYFLOW_CREDENTIALS environment variable." class Info(Enum): - CLIENT_INITIALIZED = f"INFO: [{error_prefix}] Initialized skyflow client." - VALIDATING_VAULT_CONFIG = f"INFO: [{error_prefix}] Validating vault config." - VALIDATING_CONNECTION_CONFIG = f"INFO: [{error_prefix}] Validating connection config." - UNABLE_TO_GENERATE_SDK_METRIC = f"INFO: [{error_prefix}] Unable to generate {{}} metric." - VAULT_CONTROLLER_INITIALIZED = f"INFO: [{error_prefix}] Initialized vault controller with vault ID {{}}." - CONNECTION_CONTROLLER_INITIALIZED = f"INFO: [{error_prefix}] Initialized connection controller with connection ID {{}}." - VAULT_CONFIG_EXISTS = f"INFO: [{error_prefix}] Vault config with vault ID {{}} already exists." - VAULT_CONFIG_DOES_NOT_EXIST = f"INFO: [{error_prefix}] Vault config with vault ID {{}} doesn't exist." - CONNECTION_CONFIG_EXISTS = f"INFO: [{error_prefix}] Connection config with connection ID {{}} already exists." - CONNECTION_CONFIG_DOES_NOT_EXIST = f"INFO: [{error_prefix}] Connection config with connection ID {{}} doesn't exist." - LOGGER_SETUP_DONE = f"INFO: [{error_prefix}] Set up logger." - CURRENT_LOG_LEVEL = f"INFO: [{error_prefix}] Current log level is {{}}." - - BEARER_TOKEN_EXPIRED = f"INFO: [{error_prefix}] Bearer token is expired." - GET_BEARER_TOKEN_TRIGGERED = f"INFO: [{error_prefix}] generate_bearer_token method triggered." - GET_BEARER_TOKEN_SUCCESS = f"INFO: [{error_prefix}] Bearer token generated." - GET_SIGNED_DATA_TOKENS_TRIGGERED = f"INFO: [{error_prefix}] generate_signed_data_tokens method triggered." - GET_SIGNED_DATA_TOKEN_SUCCESS = f"INFO: [{error_prefix}] Signed data tokens generated." - GENERATE_BEARER_TOKEN_FROM_CREDENTIALS_STRING_TRIGGERED = f"INFO: [{error_prefix}] generate bearer_token_from_credential_string method triggered ." - REUSE_BEARER_TOKEN = f"INFO: [{error_prefix}] Reusing bearer token." - - - VALIDATE_INSERT_REQUEST = f"INFO: [{error_prefix}] Validating insert request." - INSERT_TRIGGERED = f"INFO: [{error_prefix}] Insert method triggered." - INSERT_SUCCESS = f"INFO: [{error_prefix}] Data inserted." - INSERT_REQUEST_RESOLVED = f"INFO: [{error_prefix}] Insert request resolved." - - VALIDATE_UPDATE_REQUEST = f"INFO: [{error_prefix}] Validating update request." - UPDATE_REQUEST_RESOLVED = f"INFO: [{error_prefix}] Update request resolved." - UPDATE_SUCCESS = f"INFO: [{error_prefix}] Data updated." - UPDATE_TRIGGERED = f"INFO: [{error_prefix}] Update method triggered." - - DELETE_TRIGGERED = f"INFO: [{error_prefix}] Delete method triggered." - VALIDATING_DELETE_REQUEST = f"INFO: [{error_prefix}] Validating delete request." - DELETE_REQUEST_RESOLVED = f"INFO: [{error_prefix}] Delete request resolved." - DELETE_SUCCESS = f"INFO: [{error_prefix}] Data deleted." - - GET_TRIGGERED = f"INFO: [{error_prefix}] Get method triggered." - VALIDATE_GET_REQUEST = f"INFO: [{error_prefix}] Validating get request." - GET_REQUEST_RESOLVED = f"INFO: [{error_prefix}] Get request resolved." - GET_SUCCESS = f"INFO: [{error_prefix}] Data revealed." - - QUERY_TRIGGERED = f"INFO: [{error_prefix}] Query method triggered." - VALIDATING_QUERY_REQUEST = f"INFO: [{error_prefix}] Validating query request." - QUERY_REQUEST_RESOLVED = f"INFO: [{error_prefix}] Query request resolved." - QUERY_SUCCESS = f"INFO: [{error_prefix}] Query executed." - - DETOKENIZE_TRIGGERED = f"INFO: [{error_prefix}] Detokenize method triggered." - VALIDATE_DETOKENIZE_REQUEST = f"INFO: [{error_prefix}] Validating detokenize request." - DETOKENIZE_REQUEST_RESOLVED = f"INFO: [{error_prefix}] Detokenize request resolved." - DETOKENIZE_SUCCESS = f"INFO: [{error_prefix}] Data detokenized." - - TOKENIZE_TRIGGERED = f"INFO: [{error_prefix}] Tokenize method triggered." - VALIDATING_TOKENIZE_REQUEST = f"INFO: [{error_prefix}] Validating tokenize request." - TOKENIZE_REQUEST_RESOLVED = f"INFO: [{error_prefix}] Tokenize request resolved." - TOKENIZE_SUCCESS = f"INFO: [{error_prefix}] Data tokenized." - - INVOKE_CONNECTION_TRIGGERED = f"INFO: [{error_prefix}] Invoke connection method triggered." - VALIDATING_INVOKE_CONNECTION_REQUEST = f"INFO: [{error_prefix}] Validating invoke connection request." - INVOKE_CONNECTION_REQUEST_RESOLVED = f"INFO: [{error_prefix}] Invoke connection request resolved." - INVOKE_CONNECTION_SUCCESS = f"INFO: [{error_prefix}] Invoke Connection Success." + CLIENT_INITIALIZED = f"{INFO}: [{error_prefix}] Initialized skyflow client." + VALIDATING_VAULT_CONFIG = f"{INFO}: [{error_prefix}] Validating vault config." + VALIDATING_CONNECTION_CONFIG = f"{INFO}: [{error_prefix}] Validating connection config." + UNABLE_TO_GENERATE_SDK_METRIC = f"{INFO}: [{error_prefix}] Unable to generate {{}} metric." + VAULT_CONTROLLER_INITIALIZED = f"{INFO}: [{error_prefix}] Initialized vault controller with vault ID {{}}." + CONNECTION_CONTROLLER_INITIALIZED = f"{INFO}: [{error_prefix}] Initialized connection controller with connection ID {{}}." + VAULT_CONFIG_EXISTS = f"{INFO}: [{error_prefix}] Vault config with vault ID {{}} already exists." + VAULT_CONFIG_DOES_NOT_EXIST = f"{INFO}: [{error_prefix}] Vault config with vault ID {{}} doesn't exist." + CONNECTION_CONFIG_EXISTS = f"{INFO}: [{error_prefix}] Connection config with connection ID {{}} already exists." + CONNECTION_CONFIG_DOES_NOT_EXIST = f"{INFO}: [{error_prefix}] Connection config with connection ID {{}} doesn't exist." + LOGGER_SETUP_DONE = f"{INFO}: [{error_prefix}] Set up logger." + CURRENT_LOG_LEVEL = f"{INFO}: [{error_prefix}] Current log level is {{}}." + + BEARER_TOKEN_EXPIRED = f"{INFO}: [{error_prefix}] Bearer token is expired." + GET_BEARER_TOKEN_TRIGGERED = f"{INFO}: [{error_prefix}] generate_bearer_token method triggered." + GET_BEARER_TOKEN_SUCCESS = f"{INFO}: [{error_prefix}] Bearer token generated." + GET_SIGNED_DATA_TOKENS_TRIGGERED = f"{INFO}: [{error_prefix}] generate_signed_data_tokens method triggered." + GET_SIGNED_DATA_TOKEN_SUCCESS = f"{INFO}: [{error_prefix}] Signed data tokens generated." + GENERATE_BEARER_TOKEN_FROM_CREDENTIALS_STRING_TRIGGERED = f"{INFO}: [{error_prefix}] generate bearer_token_from_credential_string method triggered ." + REUSE_BEARER_TOKEN = f"{INFO}: [{error_prefix}] Reusing bearer token." + + + VALIDATE_INSERT_REQUEST = f"{INFO}: [{error_prefix}] Validating insert request." + INSERT_TRIGGERED = f"{INFO}: [{error_prefix}] Insert method triggered." + INSERT_SUCCESS = f"{INFO}: [{error_prefix}] Data inserted." + INSERT_REQUEST_RESOLVED = f"{INFO}: [{error_prefix}] Insert request resolved." + + VALIDATE_UPDATE_REQUEST = f"{INFO}: [{error_prefix}] Validating update request." + UPDATE_REQUEST_RESOLVED = f"{INFO}: [{error_prefix}] Update request resolved." + UPDATE_SUCCESS = f"{INFO}: [{error_prefix}] Data updated." + UPDATE_TRIGGERED = f"{INFO}: [{error_prefix}] Update method triggered." + + DELETE_TRIGGERED = f"{INFO}: [{error_prefix}] Delete method triggered." + VALIDATING_DELETE_REQUEST = f"{INFO}: [{error_prefix}] Validating delete request." + DELETE_REQUEST_RESOLVED = f"{INFO}: [{error_prefix}] Delete request resolved." + DELETE_SUCCESS = f"{INFO}: [{error_prefix}] Data deleted." + + GET_TRIGGERED = f"{INFO}: [{error_prefix}] Get method triggered." + VALIDATE_GET_REQUEST = f"{INFO}: [{error_prefix}] Validating get request." + GET_REQUEST_RESOLVED = f"{INFO}: [{error_prefix}] Get request resolved." + GET_SUCCESS = f"{INFO}: [{error_prefix}] Data revealed." + + QUERY_TRIGGERED = f"{INFO}: [{error_prefix}] Query method triggered." + VALIDATING_QUERY_REQUEST = f"{INFO}: [{error_prefix}] Validating query request." + QUERY_REQUEST_RESOLVED = f"{INFO}: [{error_prefix}] Query request resolved." + QUERY_SUCCESS = f"{INFO}: [{error_prefix}] Query executed." + + DETOKENIZE_TRIGGERED = f"{INFO}: [{error_prefix}] Detokenize method triggered." + VALIDATE_DETOKENIZE_REQUEST = f"{INFO}: [{error_prefix}] Validating detokenize request." + DETOKENIZE_REQUEST_RESOLVED = f"{INFO}: [{error_prefix}] Detokenize request resolved." + DETOKENIZE_SUCCESS = f"{INFO}: [{error_prefix}] Data detokenized." + + TOKENIZE_TRIGGERED = f"{INFO}: [{error_prefix}] Tokenize method triggered." + VALIDATING_TOKENIZE_REQUEST = f"{INFO}: [{error_prefix}] Validating tokenize request." + TOKENIZE_REQUEST_RESOLVED = f"{INFO}: [{error_prefix}] Tokenize request resolved." + TOKENIZE_SUCCESS = f"{INFO}: [{error_prefix}] Data tokenized." + + INVOKE_CONNECTION_TRIGGERED = f"{INFO}: [{error_prefix}] Invoke connection method triggered." + VALIDATING_INVOKE_CONNECTION_REQUEST = f"{INFO}: [{error_prefix}] Validating invoke connection request." + INVOKE_CONNECTION_REQUEST_RESOLVED = f"{INFO}: [{error_prefix}] Invoke connection request resolved." + INVOKE_CONNECTION_SUCCESS = f"{INFO}: [{error_prefix}] Invoke Connection Success." class ErrorLogs(Enum): - VAULTID_IS_REQUIRED = f"ERROR: [{error_prefix}] Invalid vault config. Vault ID is required." - EMPTY_VAULTID = f"ERROR: [{error_prefix}] Invalid vault config. Vault ID can not be empty." - CLUSTER_ID_IS_REQUIRED = f"ERROR: [{error_prefix}] Invalid vault config. Cluster ID is required." - EMPTY_CLUSTER_ID = f"ERROR: [{error_prefix}] Invalid vault config. Cluster ID can not be empty." - ENV_IS_REQUIRED = f"ERROR: [{error_prefix}] Invalid vault config. Env is required." - CONNECTION_ID_IS_REQUIRED = f"ERROR: [{error_prefix}] Invalid connection config. Connection ID is required." - EMPTY_CONNECTION_ID = f"ERROR: [{error_prefix}] Invalid connection config. Connection ID can not be empty." - CONNECTION_URL_IS_REQUIRED = f"ERROR: [{error_prefix}] Invalid connection config. Connection URL is required." - EMPTY_CONNECTION_URL = f"ERROR: [{error_prefix}] Invalid connection config. Connection URL can not be empty." - INVALID_CONNECTION_URL = f"ERROR: [{error_prefix}] Invalid connection config. Connection URL is not a valid URL." - EMPTY_CREDENTIALS_PATH = f"ERROR: [{error_prefix}] Invalid credentials. Credentials path can not be empty." - EMPTY_CREDENTIALS_STRING = f"ERROR: [{error_prefix}] Invalid credentials. Credentials string can not be empty." - EMPTY_TOKEN_VALUE = f"ERROR: [{error_prefix}] Invalid credentials. Token can not be empty." - EMPTY_API_KEY_VALUE = f"ERROR: [{error_prefix}] Invalid credentials. Api key can not be empty." - INVALID_API_KEY = f"ERROR: [{error_prefix}] Invalid credentials. Api key is invalid." - - INVALID_BEARER_TOKEN = f"ERROR: [{error_prefix}] Bearer token is invalid or expired." - INVALID_CREDENTIALS_FILE = f"ERROR: [{error_prefix}] Credentials file is either null or an invalid file." - INVALID_CREDENTIALS_STRING_FORMAT = f"ERROR: [{error_prefix}] Credentials string in not in a valid JSON string format." - PRIVATE_KEY_IS_REQUIRED = f"ERROR: [{error_prefix}] Private key is required." - CLIENT_ID_IS_REQUIRED = f"ERROR: [{error_prefix}] Client ID is required." - KEY_ID_IS_REQUIRED = f"ERROR: [{error_prefix}] Key ID is required." - TOKEN_URI_IS_REQUIRED = f"ERROR: [{error_prefix}] Token URI is required." - INVALID_TOKEN_URI = f"ERROR: [{error_prefix}] Invalid value for token URI in credentials." - - - TABLE_IS_REQUIRED = f"ERROR: [{error_prefix}] Invalid {{}} request. Table is required." - EMPTY_TABLE_NAME =f"ERROR: [{error_prefix}] Invalid {{}} request. Table name can not be empty." - VALUES_IS_REQUIRED = f"ERROR: [{error_prefix}] Invalid {{}} request. Values are required." - EMPTY_VALUES = f"ERROR: [{error_prefix}] Invalid {{}} request. Values can not be empty." - EMPTY_OR_NULL_VALUE_IN_VALUES = f"ERROR: [{error_prefix}] Invalid {{}} request. Value can not be null or empty in values for key {{}}." - EMPTY_OR_NULL_KEY_IN_VALUES = f"ERROR: [{error_prefix}] Invalid {{}} request. Key can not be null or empty in values." - EMPTY_UPSERT = f"ERROR: [{error_prefix}] Invalid {{}} request. Upsert can not be empty." - HOMOGENOUS_NOT_SUPPORTED_WITH_UPSERT = f"ERROR: [{error_prefix}] Invalid {{}} request. Homogenous is not supported when upsert is passed." - EMPTY_TOKENS = f"ERROR: [{error_prefix}] Invalid {{}} request. Tokens can not be empty." - EMPTY_OR_NULL_VALUE_IN_TOKENS = f"ERROR: [{error_prefix}] Invalid {{}} request. Value can not be null or empty in tokens for key {{}}." - EMPTY_OR_NULL_KEY_IN_TOKENS = f"ERROR: [{error_prefix}] Invalid {{}} request. Key can not be null or empty in tokens." - MISMATCH_OF_FIELDS_AND_TOKENS = f"ERROR: [{error_prefix}] Invalid {{}} request. Keys for values and tokens are not matching." - - EMPTY_IDS = f"ERROR: [{error_prefix}] Invalid {{}} request. Ids can not be empty." - EMPTY_OR_NULL_ID_IN_IDS = f"ERROR: [{error_prefix}] Invalid {{}} request. Id can not be null or empty in ids at index {{}}." - TOKENIZATION_NOT_SUPPORTED_WITH_REDACTION= f"ERROR: [{error_prefix}] Invalid {{}} request. Tokenization is not supported when redaction is applied." - TOKENIZATION_SUPPORTED_ONLY_WITH_IDS=f"ERROR: [{error_prefix}] Invalid {{}} request. Tokenization is not supported when column name and values are passed." - TOKENS_NOT_ALLOWED_WITH_BYOT_DISABLE = f"ERROR: [{error_prefix}] Invalid {{}} request. Tokens are not allowed when token_strict is DISABLE." - INSUFFICIENT_TOKENS_PASSED_FOR_BYOT_ENABLE_STRICT =f"ERROR: [{error_prefix}] Invalid {{}} request. For tokenStrict as ENABLE_STRICT, tokens should be passed for all fields." - TOKENS_REQUIRED = f"ERROR: [{error_prefix}] Invalid {{}} request. Tokens are required." - EMPTY_FIELDS = f"ERROR: [{error_prefix}] Invalid {{}} request. Fields can not be empty." - EMPTY_OFFSET = f"ERROR: [{error_prefix}] Invalid {{}} request. Offset ca not be empty." - NEITHER_IDS_NOR_COLUMN_NAME_PASSED = f"ERROR: [{error_prefix}] Invalid {{}} request. Neither ids nor column name and values are passed." - BOTH_IDS_AND_COLUMN_NAME_PASSED = f"ERROR: [{error_prefix}] Invalid {{}} request. Both ids and column name and values are passed." - COLUMN_NAME_IS_REQUIRED = f"ERROR: [{error_prefix}] Invalid {{}} request. Column name is required when column values are passed." - COLUMN_VALUES_IS_REQUIRED_GET = f"ERROR: [{error_prefix}] Invalid {{}} request. Column values are required when column name is passed." - SKYFLOW_ID_IS_REQUIRED = f"ERROR: [{error_prefix}] Invalid {{}} request. Skyflow Id is required." - EMPTY_SKYFLOW_ID = f"ERROR: [{error_prefix}] Invalid {{}} request. Skyflow Id can not be empty." - - COLUMN_VALUES_IS_REQUIRED_TOKENIZE = f"ERROR: [{error_prefix}] Invalid {{}} request. ColumnValues are required." - EMPTY_COLUMN_GROUP_IN_COLUMN_VALUES = f"ERROR: [{error_prefix}] Invalid {{}} request. Column group can not be null or empty in column values at index %s2." - - EMPTY_QUERY= f"ERROR: [{error_prefix}] Invalid {{}} request. Query can not be empty." - QUERY_IS_REQUIRED = f"ERROR: [{error_prefix}] Invalid {{}} request. Query is required." - - INSERT_RECORDS_REJECTED = f"ERROR: [{error_prefix}] Insert call resulted in failure." - DETOKENIZE_REQUEST_REJECTED = f"ERROR: [{error_prefix}] Detokenize request resulted in failure." - DELETE_REQUEST_REJECTED = f"ERROR: [{error_prefix}] Delete request resulted in failure." - TOKENIZE_REQUEST_REJECTED = f"ERROR: [{error_prefix}] Tokenize request resulted in failure." - UPDATE_REQUEST_REJECTED = f"ERROR: [{error_prefix}] Update request resulted in failure." - QUERY_REQUEST_REJECTED = f"ERROR: [{error_prefix}] Query request resulted in failure." - GET_REQUEST_REJECTED = f"ERROR: [{error_prefix}] Get request resulted in failure." + VAULTID_IS_REQUIRED = f"{ERROR}: [{error_prefix}] Invalid vault config. Vault ID is required." + EMPTY_VAULTID = f"{ERROR}: [{error_prefix}] Invalid vault config. Vault ID can not be empty." + CLUSTER_ID_IS_REQUIRED = f"{ERROR}: [{error_prefix}] Invalid vault config. Cluster ID is required." + EMPTY_CLUSTER_ID = f"{ERROR}: [{error_prefix}] Invalid vault config. Cluster ID can not be empty." + ENV_IS_REQUIRED = f"{ERROR}: [{error_prefix}] Invalid vault config. Env is required." + CONNECTION_ID_IS_REQUIRED = f"{ERROR}: [{error_prefix}] Invalid connection config. Connection ID is required." + EMPTY_CONNECTION_ID = f"{ERROR}: [{error_prefix}] Invalid connection config. Connection ID can not be empty." + CONNECTION_URL_IS_REQUIRED = f"{ERROR}: [{error_prefix}] Invalid connection config. Connection URL is required." + EMPTY_CONNECTION_URL = f"{ERROR}: [{error_prefix}] Invalid connection config. Connection URL can not be empty." + INVALID_CONNECTION_URL = f"{ERROR}: [{error_prefix}] Invalid connection config. Connection URL is not a valid URL." + EMPTY_CREDENTIALS_PATH = f"{ERROR}: [{error_prefix}] Invalid credentials. Credentials path can not be empty." + EMPTY_CREDENTIALS_STRING = f"{ERROR}: [{error_prefix}] Invalid credentials. Credentials string can not be empty." + EMPTY_TOKEN_VALUE = f"{ERROR}: [{error_prefix}] Invalid credentials. Token can not be empty." + EMPTY_API_KEY_VALUE = f"{ERROR}: [{error_prefix}] Invalid credentials. Api key can not be empty." + INVALID_API_KEY = f"{ERROR}: [{error_prefix}] Invalid credentials. Api key is invalid." + + INVALID_BEARER_TOKEN = f"{ERROR}: [{error_prefix}] Bearer token is invalid or expired." + INVALID_CREDENTIALS_FILE = f"{ERROR}: [{error_prefix}] Credentials file is either null or an invalid file." + INVALID_CREDENTIALS_STRING_FORMAT = f"{ERROR}: [{error_prefix}] Credentials string in not in a valid JSON string format." + PRIVATE_KEY_IS_REQUIRED = f"{ERROR}: [{error_prefix}] Private key is required." + CLIENT_ID_IS_REQUIRED = f"{ERROR}: [{error_prefix}] Client ID is required." + KEY_ID_IS_REQUIRED = f"{ERROR}: [{error_prefix}] Key ID is required." + TOKEN_URI_IS_REQUIRED = f"{ERROR}: [{error_prefix}] Token URI is required." + INVALID_TOKEN_URI = f"{ERROR}: [{error_prefix}] Invalid value for token URI in credentials." + + + TABLE_IS_REQUIRED = f"{ERROR}: [{error_prefix}] Invalid {{}} request. Table is required." + EMPTY_TABLE_NAME =f"{ERROR}: [{error_prefix}] Invalid {{}} request. Table name can not be empty." + VALUES_IS_REQUIRED = f"{ERROR}: [{error_prefix}] Invalid {{}} request. Values are required." + EMPTY_VALUES = f"{ERROR}: [{error_prefix}] Invalid {{}} request. Values can not be empty." + EMPTY_OR_NULL_VALUE_IN_VALUES = f"{ERROR}: [{error_prefix}] Invalid {{}} request. Value can not be null or empty in values for key {{}}." + EMPTY_OR_NULL_KEY_IN_VALUES = f"{ERROR}: [{error_prefix}] Invalid {{}} request. Key can not be null or empty in values." + EMPTY_UPSERT = f"{ERROR}: [{error_prefix}] Invalid {{}} request. Upsert can not be empty." + HOMOGENOUS_NOT_SUPPORTED_WITH_UPSERT = f"{ERROR}: [{error_prefix}] Invalid {{}} request. Homogenous is not supported when upsert is passed." + EMPTY_TOKENS = f"{ERROR}: [{error_prefix}] Invalid {{}} request. Tokens can not be empty." + EMPTY_OR_NULL_VALUE_IN_TOKENS = f"{ERROR}: [{error_prefix}] Invalid {{}} request. Value can not be null or empty in tokens for key {{}}." + EMPTY_OR_NULL_KEY_IN_TOKENS = f"{ERROR}: [{error_prefix}] Invalid {{}} request. Key can not be null or empty in tokens." + MISMATCH_OF_FIELDS_AND_TOKENS = f"{ERROR}: [{error_prefix}] Invalid {{}} request. Keys for values and tokens are not matching." + + EMPTY_IDS = f"{ERROR}: [{error_prefix}] Invalid {{}} request. Ids can not be empty." + EMPTY_OR_NULL_ID_IN_IDS = f"{ERROR}: [{error_prefix}] Invalid {{}} request. Id can not be null or empty in ids at index {{}}." + TOKENIZATION_NOT_SUPPORTED_WITH_REDACTION= f"{ERROR}: [{error_prefix}] Invalid {{}} request. Tokenization is not supported when redaction is applied." + TOKENIZATION_SUPPORTED_ONLY_WITH_IDS=f"{ERROR}: [{error_prefix}] Invalid {{}} request. Tokenization is not supported when column name and values are passed." + TOKENS_NOT_ALLOWED_WITH_BYOT_DISABLE = f"{ERROR}: [{error_prefix}] Invalid {{}} request. Tokens are not allowed when token_strict is DISABLE." + INSUFFICIENT_TOKENS_PASSED_FOR_BYOT_ENABLE_STRICT =f"{ERROR}: [{error_prefix}] Invalid {{}} request. For tokenStrict as ENABLE_STRICT, tokens should be passed for all fields." + TOKENS_REQUIRED = f"{ERROR}: [{error_prefix}] Invalid {{}} request. Tokens are required." + EMPTY_FIELDS = f"{ERROR}: [{error_prefix}] Invalid {{}} request. Fields can not be empty." + EMPTY_OFFSET = f"{ERROR}: [{error_prefix}] Invalid {{}} request. Offset ca not be empty." + NEITHER_IDS_NOR_COLUMN_NAME_PASSED = f"{ERROR}: [{error_prefix}] Invalid {{}} request. Neither ids nor column name and values are passed." + BOTH_IDS_AND_COLUMN_NAME_PASSED = f"{ERROR}: [{error_prefix}] Invalid {{}} request. Both ids and column name and values are passed." + COLUMN_NAME_IS_REQUIRED = f"{ERROR}: [{error_prefix}] Invalid {{}} request. Column name is required when column values are passed." + COLUMN_VALUES_IS_REQUIRED_GET = f"{ERROR}: [{error_prefix}] Invalid {{}} request. Column values are required when column name is passed." + SKYFLOW_ID_IS_REQUIRED = f"{ERROR}: [{error_prefix}] Invalid {{}} request. Skyflow Id is required." + EMPTY_SKYFLOW_ID = f"{ERROR}: [{error_prefix}] Invalid {{}} request. Skyflow Id can not be empty." + + COLUMN_VALUES_IS_REQUIRED_TOKENIZE = f"{ERROR}: [{error_prefix}] Invalid {{}} request. ColumnValues are required." + EMPTY_COLUMN_GROUP_IN_COLUMN_VALUES = f"{ERROR}: [{error_prefix}] Invalid {{}} request. Column group can not be null or empty in column values at index %s2." + + EMPTY_QUERY= f"{ERROR}: [{error_prefix}] Invalid {{}} request. Query can not be empty." + QUERY_IS_REQUIRED = f"{ERROR}: [{error_prefix}] Invalid {{}} request. Query is required." + + INSERT_RECORDS_REJECTED = f"{ERROR}: [{error_prefix}] Insert call resulted in failure." + DETOKENIZE_REQUEST_REJECTED = f"{ERROR}: [{error_prefix}] Detokenize request resulted in failure." + DELETE_REQUEST_REJECTED = f"{ERROR}: [{error_prefix}] Delete request resulted in failure." + TOKENIZE_REQUEST_REJECTED = f"{ERROR}: [{error_prefix}] Tokenize request resulted in failure." + UPDATE_REQUEST_REJECTED = f"{ERROR}: [{error_prefix}] Update request resulted in failure." + QUERY_REQUEST_REJECTED = f"{ERROR}: [{error_prefix}] Query request resulted in failure." + GET_REQUEST_REJECTED = f"{ERROR}: [{error_prefix}] Get request resulted in failure." class Interface(Enum): INSERT = "INSERT" diff --git a/skyflow/utils/_utils.py b/skyflow/utils/_utils.py index ec5cd22..cea5729 100644 --- a/skyflow/utils/_utils.py +++ b/skyflow/utils/_utils.py @@ -28,14 +28,16 @@ def get_credentials(config_level_creds = None, common_skyflow_creds = None, logg load_dotenv(dotenv_path) env_skyflow_credentials = os.getenv("SKYFLOW_CREDENTIALS") if config_level_creds: - return config_level_creds, False + return config_level_creds if common_skyflow_creds: - return common_skyflow_creds, False + return common_skyflow_creds if env_skyflow_credentials: env_skyflow_credentials.strip() try: - env_creds = json.loads(env_skyflow_credentials.replace('\n', '\\n')) - return env_creds, True + env_creds = env_skyflow_credentials.replace('\n', '\\n') + return { + 'credentials_string': env_creds + } except json.JSONDecodeError: raise SkyflowError(SkyflowMessages.Error.INVALID_JSON_FORMAT_IN_CREDENTIALS_ENV.value, invalid_input_error_code) else: diff --git a/skyflow/vault/client/client.py b/skyflow/vault/client/client.py index 132be3e..34a9374 100644 --- a/skyflow/vault/client/client.py +++ b/skyflow/vault/client/client.py @@ -24,8 +24,8 @@ def set_logger(self, log_level, logger): self.__logger = logger def initialize_client_configuration(self): - credentials, env_creds = get_credentials(self.__config.get("credentials"), self.__common_skyflow_credentials, logger = self.__logger) - token = self.get_bearer_token(credentials, env_creds) + credentials = get_credentials(self.__config.get("credentials"), self.__common_skyflow_credentials, logger = self.__logger) + token = self.get_bearer_token(credentials) vault_url = get_vault_url(self.__config.get("cluster_id"), self.__config.get("env"), self.__config.get("vault_id"), @@ -48,7 +48,7 @@ def get_query_api(self): def get_vault_id(self): return self.__config.get("vault_id") - def get_bearer_token(self, credentials, env_creds): + def get_bearer_token(self, credentials): if 'api_key' in credentials: return credentials.get('api_key') elif 'token' in credentials: @@ -60,15 +60,7 @@ def get_bearer_token(self, credentials, env_creds): } if self.__bearer_token is None or self.__is_config_updated: - if env_creds: - log_info(SkyflowMessages.Info.GENERATE_BEARER_TOKEN_FROM_CREDENTIALS_STRING_TRIGGERED.value, - self.__logger) - self.__bearer_token, _ = generate_bearer_token_from_creds( - json.dumps(credentials), - options, - self.__logger - ) - elif 'path' in credentials: + if 'path' in credentials: path = credentials.get("path") self.__bearer_token, _ = generate_bearer_token( path, @@ -84,12 +76,13 @@ def get_bearer_token(self, credentials, env_creds): self.__logger ) self.__is_config_updated = False + else: + log_info(SkyflowMessages.Info.REUSE_BEARER_TOKEN.value, self.__logger) if is_expired(self.__bearer_token): self.__is_config_updated = True raise SyntaxError(SkyflowMessages.Error.EXPIRED_TOKEN.value, SkyflowMessages.ErrorCodes.INVALID_INPUT.value) - log_info(SkyflowMessages.Info.REUSE_BEARER_TOKEN.value, self.__logger) return self.__bearer_token def update_config(self, config): diff --git a/tests/constants/test_constants.py b/tests/constants/test_constants.py index fff3382..00155d3 100644 --- a/tests/constants/test_constants.py +++ b/tests/constants/test_constants.py @@ -64,7 +64,7 @@ EMPTY_URL = "" SCOPES_LIST = ["admin", "user", "viewer"] FORMATTED_SCOPES = "role:admin role:user role:viewer" -INVALID_JSON_FORMAT = '{"invalid": json}' +INVALID_JSON_FORMAT = '[{"invalid": "json"}]' TEST_ERROR_MESSAGE = "Test error message." @@ -90,6 +90,8 @@ CREDENTIALS_WITH_PATH = {"path": "/path/to/creds.json"} CREDENTIALS_WITH_STRING = {"credentials_string": "dummy_credentials_string"} +VALID_ENV_CREDENTIALS = {"clientID":"CLIENT_ID","clientName":"test_V2","tokenURI":"TOKEN_URI","keyID":"KEY_ID","privateKey":"PRIVATE_KEY","keyValidAfterTime":"2024-10-21T18:06:26.000Z","keyValidBeforeTime":"2025-10-21T18:06:26.000Z","keyAlgorithm":"KEY_ALG_RSA_2048"} + # connection controller constants diff --git a/tests/utils/test__utils.py b/tests/utils/test__utils.py index 6b8adf0..ef4bf26 100644 --- a/tests/utils/test__utils.py +++ b/tests/utils/test__utils.py @@ -15,33 +15,28 @@ from skyflow.vault.connection import InvokeConnectionResponse from skyflow.vault.data import InsertResponse, DeleteResponse, GetResponse, QueryResponse from skyflow.vault.tokens import DetokenizeResponse, TokenizeResponse -from tests.constants.test_constants import VALID_CREDENTIALS_STRING, INVALID_JSON_FORMAT, TEST_ERROR_MESSAGE +from tests.constants.test_constants import VALID_CREDENTIALS_STRING, INVALID_JSON_FORMAT, TEST_ERROR_MESSAGE, \ + VALID_ENV_CREDENTIALS class TestUtils(unittest.TestCase): - @patch.dict(os.environ, {"SKYFLOW_CREDENTIALS": VALID_CREDENTIALS_STRING}) + @patch.dict(os.environ, {"SKYFLOW_CREDENTIALS": json.dumps(VALID_ENV_CREDENTIALS)}) def test_get_credentials_env_variable(self): - creds, _ = get_credentials() - VALID_CREDENTIALS_STRING.strip() - self.assertEqual(creds, json.loads(VALID_CREDENTIALS_STRING.replace('\n', '\\n'))) + credentials = get_credentials() + credentials_string = credentials.get('credentials_string') + self.assertEqual(credentials_string, json.dumps(VALID_ENV_CREDENTIALS).replace('\n', '\\n')) def test_get_credentials_with_config_level_creds(self): test_creds = {"authToken": "test_token"} - creds, _ = get_credentials(config_level_creds=test_creds) + creds = get_credentials(config_level_creds=test_creds) self.assertEqual(creds, test_creds) def test_get_credentials_with_common_creds(self): test_creds = {"authToken": "test_token"} - creds, _ = get_credentials(common_skyflow_creds=test_creds) + creds = get_credentials(common_skyflow_creds=test_creds) self.assertEqual(creds, test_creds) - @patch.dict(os.environ, {"SKYFLOW_CREDENTIALS": INVALID_JSON_FORMAT}) - def test_get_credentials_invalid_json_format(self): - with self.assertRaises(SkyflowError) as context: - get_credentials() - self.assertIn(context.exception.message, SkyflowMessages.Error.INVALID_JSON_FORMAT_IN_CREDENTIALS_ENV.value) - def test_get_vault_url_valid(self): valid_cluster_id = "testCluster" valid_env = Env.DEV diff --git a/tests/vault/client/test__client.py b/tests/vault/client/test__client.py index 6de8f23..e26988f 100644 --- a/tests/vault/client/test__client.py +++ b/tests/vault/client/test__client.py @@ -26,7 +26,7 @@ def test_set_logger(self): @patch("skyflow.vault.client.client.VaultClient.initialize_api_client") def test_initialize_client_configuration(self, mock_init_api_client, mock_config, mock_get_vault_url, mock_get_credentials): - mock_get_credentials.return_value = (CREDENTIALS_WITH_API_KEY, False) + mock_get_credentials.return_value = (CREDENTIALS_WITH_API_KEY) mock_get_vault_url.return_value = "https://test-vault-url.com" self.vault_client.initialize_client_configuration() @@ -68,7 +68,7 @@ def test_get_vault_id(self): @patch("skyflow.vault.client.client.log_info") def test_get_bearer_token_with_api_key(self, mock_log_info, mock_generate_bearer_token, mock_generate_bearer_token_from_creds): - token = self.vault_client.get_bearer_token(CREDENTIALS_WITH_API_KEY, False) + token = self.vault_client.get_bearer_token(CREDENTIALS_WITH_API_KEY) self.assertEqual(token, CREDENTIALS_WITH_API_KEY["api_key"]) def test_update_config(self):