1414from arcsecond .config import (config_file_path ,
1515 config_file_read_api_key ,
1616 config_file_save_api_key ,
17+ config_file_read_username ,
18+ config_file_read_organisation_memberships ,
1719 config_file_save_organisation_membership )
1820
1921from arcsecond .options import State
@@ -81,8 +83,16 @@ def factory(endpoint_class, state, **kwargs):
8183@set_api_factory
8284class Arcsecond (object ):
8385 @classmethod
84- def is_logged_in (cls , state = None ):
85- return ArcsecondAPI .is_logged_in (state )
86+ def is_logged_in (cls , state = None , ** kwargs ):
87+ return ArcsecondAPI .is_logged_in (state , ** kwargs )
88+
89+ @classmethod
90+ def username (cls , state = None , ** kwargs ):
91+ return ArcsecondAPI .username (state , ** kwargs )
92+
93+ @classmethod
94+ def memberships (cls , state = None , ** kwargs ):
95+ return ArcsecondAPI .memberships (state , ** kwargs )
8696
8797 @classmethod
8898 def login (cls , username , password , subdomain , state = None ):
@@ -200,7 +210,7 @@ def delete(self, id_name_uuid, **headers):
200210 def _check_organisation_membership (cls , state , username , subdomain ):
201211 if state .verbose :
202212 click .echo ('Checking Membership of Organisation with subdomain "{}"...' .format (subdomain ))
203- profile , error = PersonalProfileAPIEndPoint (State ( verbose = False , debug = state .debug )).read (username )
213+ profile , error = PersonalProfileAPIEndPoint (state .make_new_silent ( )).read (username )
204214 if error :
205215 ArcsecondAPI ._echo_error (state , error )
206216 else :
@@ -209,7 +219,7 @@ def _check_organisation_membership(cls, state, username, subdomain):
209219 if state .verbose :
210220 click .echo ('Membership confirmed. Role is "{}", stored in {}.'
211221 .format (memberships [subdomain ], config_file_path ()))
212- config_file_save_organisation_membership (subdomain , memberships [subdomain ], state .debug )
222+ config_file_save_organisation_membership (subdomain , memberships [subdomain ], state .config_section () )
213223 else :
214224 if state .verbose :
215225 click .echo ('Membership denied.' )
@@ -223,15 +233,25 @@ def _get_and_save_api_key(cls, state, username, auth_token):
223233 return ArcsecondAPI ._echo_error (state , error )
224234 if result :
225235 api_key = result ['api_key' ]
226- config_file_save_api_key (api_key , username , state .debug )
236+ config_file_save_api_key (api_key , username , state .config_section () )
227237 if state .verbose :
228238 click .echo ('Successful API key retrieval and storage in {}. Enjoy.' .format (config_file_path ()))
229239 return result
230240
231241 @classmethod
232- def is_logged_in (cls , state = None ):
233- state = get_api_state (state )
234- return config_file_read_api_key (debug = state .debug ) is not None
242+ def is_logged_in (cls , state = None , ** kwargs ):
243+ state = get_api_state (state , ** kwargs )
244+ return config_file_read_api_key (section = state .config_section ()) is not None
245+
246+ @classmethod
247+ def username (cls , state = None , ** kwargs ):
248+ state = get_api_state (state , ** kwargs )
249+ return config_file_read_username (section = state .config_section ()) or ''
250+
251+ @classmethod
252+ def memberships (cls , state = None , ** kwargs ):
253+ state = get_api_state (state , ** kwargs )
254+ return config_file_read_organisation_memberships (section = state .config_section ())
235255
236256 @classmethod
237257 def login (cls , username , password , subdomain , state = None ):
0 commit comments