Storage

lib.User

User

User(self, username:str)

Represents a user, which can access services via tokens.

to_json

User.to_json(self)

Returns this object as a json string.

to_dict

User.to_dict(self)

Returns this object as a dict.

from_json

User.from_json(user:str)

Returns an user object from a json string.

from_dict

User.from_dict(userDict:dict)

Returns an user object from a dict.

lib.Token

Token

Token(self, servicename:str, access_token:str)

This token represents a simple password.

to_json

Token.to_json(self)

Returns this object as a json string.

to_dict

Token.to_dict(self)

Returns this object as a dict.

from_json

Token.from_json(tokenStr:str)

Returns a token object from a json string.

from_dict

Token.from_dict(tokenDict:dict)

Returns a token object from a dict.

OAuth2Token

OAuth2Token(self, servicename:str, access_token:str, refresh_token:str='', expiration_date:datetime.datetime=None)

Represents a token object.

from_token

OAuth2Token.from_token(token:lib.Token.Token, refresh_token:str='', expiration_date:datetime.datetime=None)

Convert the given Token into an oauth2token.

to_json

OAuth2Token.to_json(self)

Returns this object as a json string.

to_dict

OAuth2Token.to_dict(self)

Returns this object as a dict.

from_json

OAuth2Token.from_json(tokenStr:str)

Returns an oauthtoken object from a json string.

from_dict

OAuth2Token.from_dict(tokenDict:dict)

Returns an oauthtoken object from dict.

lib.Service

Service

Service(self, servicename:str)

Represents a service, which can be used in RDS. This service only allows username:password authentication.

to_json

Service.to_json(self)

Returns this object as a json string.

to_dict

Service.to_dict(self)

Returns this object as a dict.

from_json

Service.from_json(serviceStr:str)

Returns an service object from a json string.

from_dict

Service.from_dict(serviceDict:dict)

Returns an service object from a dict string.

OAuth2Service

OAuth2Service(self, servicename:str, authorize_url:str, refresh_url:str, client_id:str, client_secret:str)

Represents an OAuth2 service, which can be used in RDS. This service enables the oauth2 workflow.

refresh

OAuth2Service.refresh(self, token:lib.Token.OAuth2Token)

Refresh the given oauth2 token for specified user.

from_service

OAuth2Service.from_service(service:lib.Service.Service, authorize_url:str, refresh_url:str, client_id:str, client_secret:str)

Converts the given Service to an oauth2service.

to_json

OAuth2Service.to_json(self)

Returns this object as a json string.

to_dict

OAuth2Service.to_dict(self)

Returns this object as a dict.

from_json

OAuth2Service.from_json(serviceStr:str)

Returns an oauthservice object from a json string.

from_dict

OAuth2Service.from_dict(serviceDict:dict)

Returns an oauthservice object from a dict.

lib.Storage

Storage

Storage(self)

Represents a Safe for Tokens.

getUsers

Storage.getUsers(self)

Returns a list of all registered users.

getUser

Storage.getUser(self, user_id:str)

Returns the user with user_id.

Raise a UserNotExistsError, if user not found.

getTokens

Storage.getTokens(self, user_id:Union[str, lib.User.User]=None)

Returns a list of all managed tokens.

If user_id (String or User) was given, then the tokens are filtered to this user.

Raise a UserNotExistsError, if the given user not exists.

getToken

Storage.getToken(self, user_id:Union[str, lib.User.User], token_id:int)

Returns only the token with token_id from user_id (String or User).

Raise ValueError if token_id not found and UserNotExistsError if user_id was not found.

getServices

Storage.getServices(self)

Returns a list of all registered services.

getService

Storage.getService(self, service:Union[str, lib.Service.Service], index:bool=False)

Returns the service object with the given servicename. If not found, returns None

This function can be used to check, if an object is already a member of the list of services.

Set parameter index to True to get the index as the second return value in tuple.

addService

Storage.addService(self, service:lib.Service.Service, Force=False)

Add the given service to the list of services.

Returns True if success. Otherwise raises a ServiceExistsAlreadyError if there is already a service with the same name.

To force an update, you have to set the parameter Force to True.

Raise an error, if parameter not a service object.

removeService

Storage.removeService(self, service:Union[str, lib.Service.Service])

Removes the service with servicename.

Returns True if a service was found and removed. Otherwise false.

addUser

Storage.addUser(self, user:lib.User.User)

Add user to the storage.

If a User with the same username already exists, it raises UserExistsAlreadyError.

removeUser

Storage.removeUser(self, user:lib.User.User)

Remove given user from storage.

If user not in storage, it raises an UserNotExistsError.

internal_removeUser

Storage.internal_removeUser(self, user:lib.User.User)

Remove a user to _storage.

This is an internal function. Please look at the external one.

removeToken

Storage.removeToken(self, user:lib.User.User, token:lib.Token.Token)

Remove a token from user.

internal_removeToken

Storage.internal_removeToken(self, user:lib.User.User, token:lib.Token.Token)

Remove a token from user.

This is an internal function. Please look at the external one.

internal_addUser

Storage.internal_addUser(self, user:lib.User.User)

Add a user to the _storage.

This is an internal function. Please take a look to the external one.

addTokenToUser

Storage.addTokenToUser(self, token:lib.Token.Token, user:lib.User.User, Force:bool=False)

Add a token to an existing user. If user not exists already in the _storage, it raises an UserNotExistsError. If token was added to user specific storage, then it returns True.

If a token is there for the same token provider, then a UserHasTokenAlreadyError.

Use Force Parameter (boolean) to create User, if not already exists and overwrite any existing Token.

refresh_service

Storage.refresh_service(self, service:lib.Service.Service)

Refresh all tokens, which corresponds to given service.

Returns True, if one or more Tokens were found in the storage to refresh.

refresh_services

Storage.refresh_services(self, services:list=None)

Refresh all tokens, which corresponds to given list of services.

If no services were given, it will be used the stored one.

Returns True, if one or more Tokens were found in the storage to refresh.

internal_refresh_services

Storage.internal_refresh_services(self, services:list)

Only for internal use. Do not use it in another class.

Refresh all tokens, which corresponds to given list of services.

Returns True, if one or more Tokens were found in the storage to refresh.

internal_find_service

Storage.internal_find_service(self, servicename:str, services:list)

Tries to find the given servicename in the list of services.

Returns the index of the first found service with equal servicename.

Otherwise raise an ValueError.

lib.Exceptions.ServiceException

lib.Exceptions.StorageException

Util

load_class_from_json

load_class_from_json(jsonStr:str)

Returns the class of the given json string.

load_class_from_dict

load_class_from_dict(data:dict)

Returns the class of the given dict.

initialize_object_from_json

initialize_object_from_json(jsonStr:str)

Initialize and returns an object of the given json string.

This is the easiest way to reverse the to_json method for objects from our lib folder.

internal_load_class

internal_load_class(data:dict)

For internal use only.

try_function_on_dict

try_function_on_dict(func:list)

This method trys the given functions on the given dictionary. Returns the first function, which returns a value for given dict.

Main purpose of this is the initialization of multiple Classes from json dicts.

Usage:

func_list = [func1, func2, func3]
x = Util.try_function_on_dict(func_list)
object = x(objDict)

equals to:

try:
    try:
        func1(objDict)
    except:
        pass
    try:
        func2(objDict)
    except:
        pass
    try:
        func3(objDict)
    except:
        pass
except:
    raise Exception(...)

Raise an Exception with all raised exception as strings, if no function returns a value for the given jsonDict.