def __init__(self, **args): util.log_instantiation(LOGGER, 'HandleSystemConnector', args, ['password','reverselookup_password']) # Possible arguments: optional_args = [ 'handle_server_url', 'REST_API_url_extension', 'HTTPS_verify', 'username', 'password', 'private_key', 'certificate_only', 'certificate_and_key' ] util.add_missing_optional_args_with_value_none(args, optional_args) # Defaults for args: defaults = { 'handle_server_url': 'https://hdl.handle.net', 'REST_API_url_extension': '/api/handles/', 'HTTPS_verify': True, } # Args that the constructor understands: self.__handle_server_url = None self.__REST_API_url_extension = None self.__HTTPS_verify = None self.__username = None self.__password = None self.__private_key = None self.__certificate_only = None self.__certificate_and_key = None self.__handle_connector = None # Other attributes: self.__basic_authentication_string = None self.__cert_object = None self.__has_write_access = False self.__auth_methods = dict(user_pw='user_pw', cert='client_cert') self.__authentication_method = None self.__session = requests.Session() self.__no_auth_message = 'No credentials passed. Read access only.' self.__first_request = True # Needed for read and write access: self.__store_args_or_set_to_defaults(args, defaults) # If write access, do some additional setup: if self.__check_if_write_access(args): self.__setup_for_writeaccess(args) LOGGER.debug('End of instantiation of the handle system connector.')
def __init__(self, **args): util.log_instantiation(LOGGER, 'Searcher', args, ['password','reverselookup_password']) optional_args = [ 'reverselookup_baseuri', 'reverselookup_url_extension', 'handle_server_url', 'reverselookup_username', 'username', 'reverselookup_password', 'password', 'allowed_search_keys', 'HTTPS_verify' ] util.add_missing_optional_args_with_value_none(args, optional_args) # Args that the constructor understands: self.__reverselookup_baseuri = None self.__reverselookup_url_extension = None self.__allowed_search_keys = None self.__HTTPS_verify = None self.__user = None self.__password = None # Other attributes: self.__has_search_access = False self.__handle_system_username_used = False self.__handle_system_password_used = False self.__revlookup_auth_string = None self.__header = None self.__session = None # Defaults: defaults = { 'allowed_search_keys': ['URL', 'CHECKSUM'], 'HTTPS_verify': True, 'reverselookup_url_extension': '/hrls/handles/', } # Set them: self.__store_args_or_set_to_defaults(args, defaults) if self.__has_search_access: self.__setup_search_access() LOGGER.debug('End of instantiation of the search module.')
def __init__(self, **args): ''' Initialize client credentials instance. The constructor checks if enough arguments are passed to authenticate at a handle server or search servlet. For this, the following parameters are checked. Depending on the chosen authentication method, only a subset of them are required. All other parameters passed are stored and can be retrieved using 'get_config()'. If a credentials objects is used to initialize the client, these key-value pairs are passed on to the client constructor. :param handle_server_url: Optional. The URL of the Handle System server to read from. Defaults to 'https://hdl.handle.net' :param username: Optional. This must be a handle value reference in the format "index:prefix/suffix". The method will throw an exception upon bad syntax or non-existing Handle. The existence or validity of the password in the handle is not checked at this moment. :param password: Optional. This is the password stored as secret key in the actual Handle value the username points to. :param handleowner: Optional. The username that will be given admin permissions over every newly created handle. By default, it is '200:0.NA/xyz' (where xyz is the prefix of the handle being created. :param private_key: Optional. The path to a file containing the private key that will be used for authentication in write mode. If this is specified, a certificate needs to be specified too. :param certificate_only: Optional. The path to a file containing the client certificate that will be used for authentication in write mode. If this is specified, a private key needs to be specified too. :param certificate_and_key: Optional. The path to a file containing both certificate and private key, used for authentication in write mode. :param prefix: Prefix. This is not used by the library, but may be retrieved by the user. :param \**args: Any other key-value pairs are stored and can be accessed using 'get_config()'. :raises: :exc:`~b2handle.handleexceptions.HandleSyntaxError` ''' util.log_instantiation(LOGGER, 'PIDClientCredentials', args, ['password','reverselookup_password']) # Possible arguments: useful_args = [ 'handle_server_url', 'username', 'password', 'private_key', 'certificate_only', 'certificate_and_key', 'prefix', 'handleowner', 'reverselookup_password', 'reverselookup_username', 'reverselookup_baseuri' ] util.add_missing_optional_args_with_value_none(args, useful_args) # Args that the constructor understands: self.__handle_server_url = args['handle_server_url'] self.__username = args['username'] self.__password = args['password'] self.__prefix = args['prefix'] self.__handleowner = args['handleowner'] self.__private_key = args['private_key'] self.__certificate_only = args['certificate_only'] self.__certificate_and_key = args['certificate_and_key'] # Other attributes: self.__additional_config = None # All the other args collected as "additional config": self.__additional_config = self.__collect_additional_arguments(args, useful_args) # Some checks: self.__check_handle_syntax() self.__check_file_existence() self.__check_if_enough_args_for_revlookup_auth(args) self.__check_if_enough_args_for_hs_auth()