EUDAT-B2HANDLE / B2HANDLE

B2Handle Python library for interaction with Handle services
https://eudat-b2handle.github.io/
Apache License 2.0
22 stars 24 forks source link

Loading credentials file from path #112

Closed chStaiger closed 7 years ago

chStaiger commented 7 years ago

The current version of b2handle does not allow to load the credentials json file from a path:

cred = PIDClientCredentials.load_from_JSON('/home/ubuntu/HandleCerts/cred.json')
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-19-53471f787ce4> in <module>()
----> 1 cred = PIDClientCredentials.load_from_JSON('HandleCerts/cred_21.T12995.json')

/usr/local/lib/python2.7/dist-packages/b2handle-1.0.3-py2.7.egg/b2handle/clientcredentials.pyc in load_from_JSON(json_filename)
     53
     54         jsonfilecontent = json.loads(open(json_filename, 'r').read())
---> 55         instance = PIDClientCredentials(credentials_filename=json_filename,**jsonfilecontent)
     56         return instance
     57

/usr/local/lib/python2.7/dist-packages/b2handle-1.0.3-py2.7.egg/b2handle/clientcredentials.pyc in __init__(self, **args)
    141         # Some checks:
    142         self.__check_handle_syntax()
--> 143         self.__check_file_existence()
    144         self.__check_if_enough_args_for_revlookup_auth(args)
    145         self.__check_if_enough_args_for_hs_auth()

/usr/local/lib/python2.7/dist-packages/b2handle-1.0.3-py2.7.egg/b2handle/clientcredentials.pyc in __check_file_existence(self)
    179         if self.__certificate_only:
    180             try:
--> 181                 self.__certificate_only = self.__get_path_and_check_file_existence(self.__certificate_only)
    182             except ValueError as e:
    183                 msg = '(certficate file): '+e.message

/usr/local/lib/python2.7/dist-packages/b2handle-1.0.3-py2.7.egg/b2handle/clientcredentials.pyc in __get_path_and_check_file_existence(self, path)
    203
    204         except ValueError: # not a valid path
--> 205             thisdir = utilsget_this_directory(self.__credentials_filename)
    206             msg = ('Please provide an absolute path or a path relative to '
    207                    'the location of the credentials file\'s location (%s), '

NameError: global name 'utilsget_this_directory' is not defined
chStaiger commented 7 years ago

The error is thrown when the files in "private_key" or "certificate_only" do not exist.

cookie33 commented 7 years ago

The problem is following:

So the error message is NOT as expected if an error is made concerning the paths of these files.

The documentation http://eudat-b2safe.github.io/B2HANDLE/handleclient.html?highlight=load_from_json#b2handle.clientcredentials.PIDClientCredentials.load_from_JSON does not include an error for such a case.

It is a very minor feature.

TobiasWeigel commented 7 years ago

I believe this was fixed in 77476f7d.