def from_dict(authentication_dict: Any): """ Create a Basic authentication object from a dictionary. :param authentication_dict: A dictionary that contains the keys of a Basic object. :type authentication_dict: Any :rtype: ibmpairs.authentication.Basic :raises Exception: if not a dictionary. """ username = None password = None password_file = None host = None common.check_dict(authentication_dict) if "host" in authentication_dict: host = common.check_str(authentication_dict.get("host")) if "username" in authentication_dict: username = common.check_str(authentication_dict.get("username")) if "password" in authentication_dict: password = common.check_str(authentication_dict.get("password")) if "password_file" in authentication_dict: password_file = common.check_str(authentication_dict.get("password_file")) return Basic(host = host, username = username, password = password, password_file = password_file )
def from_dict(query_registration_return_dict: Any): """ Create a QueryRegistrationReturn object from a dictionary. :param query_registration_return_dict: A dictionary that contains the keys of a QueryRegistrationReturn. :type query_registration_return_dict: Any :rtype: ibmpairs.dashboard.QueryRegistrationReturn """ analytics_uuid = None layer_id = None base_computation_id = None #common.check_dict(query_dict) if "analyticsUuid" in query_registration_return_dict: if query_registration_return_dict.get("analyticsUuid") is not None: analytics_uuid = common.check_str( query_registration_return_dict.get("analyticsUuid")) if "layerId" in query_registration_return_dict: if query_registration_return_dict.get("layerId") is not None: layer_id = common.check_str( query_registration_return_dict.get("layerId")) if "baseComputationId" in query_registration_return_dict: if query_registration_return_dict.get( "baseComputationId") is not None: base_computation_id = common.check_str( query_registration_return_dict.get("baseComputationId")) return QueryRegistrationReturn(analytics_uuid=analytics_uuid, layer_id=layer_id, base_computation_id=base_computation_id)
def from_dict(authentication_dict: Any): access_token = None expires_in = None token_type = None refresh_token = None scope = None error = None common.check_dict(authentication_dict) if "access_token" in authentication_dict: if authentication_dict.get("access_token") is not None: access_token = common.check_str( authentication_dict.get("access_token")) if "expires_in" in authentication_dict: if authentication_dict.get("expires_in") is not None: expires_in = common.check_int( authentication_dict.get("expires_in")) if "token_type" in authentication_dict: if authentication_dict.get("token_type") is not None: token_type = common.check_str( authentication_dict.get("token_type")) if "refresh_token" in authentication_dict: if authentication_dict.get("refresh_token") is not None: refresh_token = common.check_str( authentication_dict.get("refresh_token")) if "scope" in authentication_dict: if authentication_dict.get("scope") is not None: scope = common.check_str(authentication_dict.get("scope")) if "error" in authentication_dict: if authentication_dict.get("error") is not None: error = common.check_str(authentication_dict.get("error")) return OAuth2Return(access_token, expires_in, token_type, refresh_token, scope, error)
def from_dict(oauth2_return_dict: Any): """ Create an OAuth2Return object from a dictionary. :param oauth2_return_dict: A dictionary that contains the keys of an OAuth2Return object. :type oauth2_return_dict: Any :rtype: ibmpairs.authentication.OAuth2Return :raises Exception: if not a dictionary. """ access_token = None expires_in = None token_type = None refresh_token = None scope = None error = None common.check_dict(oauth2_return_dict) if "access_token" in oauth2_return_dict: if oauth2_return_dict.get("access_token") is not None: access_token = common.check_str(oauth2_return_dict.get("access_token")) if "expires_in" in oauth2_return_dict: if oauth2_return_dict.get("expires_in") is not None: expires_in = common.check_int(oauth2_return_dict.get("expires_in")) if "token_type" in oauth2_return_dict: if oauth2_return_dict.get("token_type") is not None: token_type = common.check_str(oauth2_return_dict.get("token_type")) if "refresh_token" in oauth2_return_dict: if oauth2_return_dict.get("refresh_token") is not None: refresh_token = common.check_str(oauth2_return_dict.get("refresh_token")) if "scope" in oauth2_return_dict: if oauth2_return_dict.get("scope") is not None: scope = common.check_str(oauth2_return_dict.get("scope")) if "error" in oauth2_return_dict: if oauth2_return_dict.get("error") is not None: error = common.check_str(oauth2_return_dict.get("error")) return OAuth2Return(access_token = access_token, expires_in = expires_in, token_type = token_type, refresh_token = refresh_token, scope = scope, error = error )
def set_api_key_file(self, api_key_file): if os.path.isfile(os.path.join(os.getcwd(), api_key_file)): self._api_key_file = os.path.join(os.getcwd(), api_key_file) elif os.path.isfile(api_key_file): self._api_key_file = common.check_str(api_key_file) else: msg = messages.ERROR_AUTHENTICATION_COULD_NOT_FIND_API_KEY_FILE.format(api_key_file) logger.info(msg) raise common.PAWException(msg)
def set_password_file(self, password_file): if os.path.isfile(os.path.join(os.getcwd(), password_file)): self._password_file = os.path.join(os.getcwd(), password_file) elif os.path.isfile(password_file): self._password_file = common.check_str(password_file) else: raise ValueError( "The file '{}' could not be found.".format( password_file ) )
def from_dict(client_response_dict: Any): status = None body = None common.check_dict(client_response_dict) if "status" in client_response_dict: if client_response_dict.get("status") is not None: status = common.check_int(client_response_dict.get("status")) if "body" in client_response_dict: if client_response_dict.get("body") is not None: if isinstance(body, str): body = common.check_str(client_response_dict.get("body")) elif isinstance(body, bytes): body = client_response_dict.get("body") return ClientResponse(status=status, body=body)
def from_dict(authentication_dict: Any): """ Create a OAuth2 authentication object from a dictionary. :param authentication_dict: A dictionary that contains the keys of a OAuth2 object. :type authentication_dict: Any :rtype: ibmpairs.authentication.OAuth2 :raises Exception: if not a dictionary. """ host = None username = None api_key = None api_key_file = None client_id = None endpoint = None jwt_token = None common.check_dict(authentication_dict) if "host" in authentication_dict: if authentication_dict.get("host") is not None: host = common.check_str(authentication_dict.get("host")) if "username" in authentication_dict: if authentication_dict.get("username") is not None: username = common.check_str(authentication_dict.get("username")) if "api_key" in authentication_dict: if authentication_dict.get("api_key") is not None: api_key = common.check_str(authentication_dict.get("api_key")) if "api_key_file" in authentication_dict: if authentication_dict.get("api_key_file") is not None: api_key_file = common.check_str(authentication_dict.get("api_key_file")) if "client_id" in authentication_dict: if authentication_dict.get("client_id") is not None: client_id = common.check_str(authentication_dict.get("client_id")) if "endpoint" in authentication_dict: if authentication_dict.get("endpoint") is not None: endpoint = common.check_str(authentication_dict.get("endpoint")) if "jwt_token" in authentication_dict: if authentication_dict.get("jwt_token") is not None: jwt_token = common.check_str(authentication_dict.get("jwt_token")) return OAuth2(host, username, api_key, api_key_file, client_id, endpoint, jwt_token )
def from_dict(authentication_dict: Any): host = None username = None api_key = None api_key_file = None client_id = None endpoint = None jwt_token = None common.check_dict(authentication_dict) if "host" in authentication_dict: if authentication_dict.get("host") is not None: host = common.check_str(authentication_dict.get("host")) if "username" in authentication_dict: if authentication_dict.get("username") is not None: username = common.check_str( authentication_dict.get("username")) if "api_key" in authentication_dict: if authentication_dict.get("api_key") is not None: api_key = common.check_str(authentication_dict.get("api_key")) if "api_key_file" in authentication_dict: if authentication_dict.get("api_key_file") is not None: api_key_file = common.check_str( authentication_dict.get("api_key_file")) if "client_id" in authentication_dict: if authentication_dict.get("client_id") is not None: client_id = common.check_str( authentication_dict.get("client_id")) if "endpoint" in authentication_dict: if authentication_dict.get("endpoint") is not None: endpoint = common.check_str( authentication_dict.get("endpoint")) if "jwt_token" in authentication_dict: if authentication_dict.get("jwt_token") is not None: jwt_token = common.check_str( authentication_dict.get("jwt_token")) return OAuth2(host, username, api_key, api_key_file, client_id, endpoint, jwt_token)
def test_check_str(self): self.logger.info('test_check_str') self.assertEqual(common.check_str(0), '0') self.assertEqual(common.check_str(1000), '1000') self.assertEqual(common.check_str('0'), '0') self.assertEqual(common.check_str('1000'), '1000') self.assertEqual(common.check_str('Hello World!'), 'Hello World!') got_exception = False try: common.check_str(None) except Exception as ex: self.logger.error(ex) got_exception = True self.assertTrue(got_exception)
def set_token_type(self, token_type): self._token_type = common.check_str(token_type)
def set_jwt_token(self, jwt_token): self._jwt_token = common.check_str(jwt_token)
def set_endpoint(self, endpoint): self._endpoint = common.check_str(endpoint)
def set_client_id(self, client_id): self._client_id = common.check_str(client_id)
def set_api_key(self, api_key): self._api_key = common.check_str(api_key)
def set_username(self, username): self._username = common.check_str(username)
def set_host(self, host): self._host = common.check_str(host)
def set_analytics_uuid(self, analytics_uuid): self._analytics_uuid = common.check_str(analytics_uuid)
def set_layer_id(self, layer_id): self._layer_id = common.check_str(layer_id)
def set_host(self, host): self._host = common.ensure_protocol(common.check_str(host))
def set_access_token(self, access_token): self._access_token = common.check_str(access_token)
def set_password(self, password): self._password = common.check_str(password)
def set_host(self, host): self._host = common.check_str(common.strip_protocol(host))
def set_refresh_token(self, refresh_token): self._refresh_token = common.check_str(refresh_token)
def set_scope(self, scope): self._scope = common.check_str(scope)
def set_body(self, body): if isinstance(body, str): self._body = common.check_str(body) elif isinstance(body, bytes): self._body = body
def set_error(self, error): self._error = common.check_str(error)
def set_string(self, string): self._string = common.check_str(string)
def set_base_computation_id(self, base_computation_id): self._base_computation_id = common.check_str(base_computation_id)