From 6f56d2c8d72dd96dfd8f1032d9fb182e7fd8dec5 Mon Sep 17 00:00:00 2001 From: David Douard Date: Fri, 30 Aug 2019 10:24:51 +0200 Subject: [PATCH] core: move credentials' docstring from request_params to request_instance_credentials and fix empty values returned by this later (empty list instead of ampty dict). --- swh/lister/core/lister_transports.py | 57 +++++++++++++++------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/swh/lister/core/lister_transports.py b/swh/lister/core/lister_transports.py index fac3b7e..2bacb6c 100644 --- a/swh/lister/core/lister_transports.py +++ b/swh/lister/core/lister_transports.py @@ -53,33 +53,10 @@ class ListerHttpTransport(abc.ABC): """Returns dictionary of any credentials configuration needed by the forge instance to list. - Returns: - dict of credentials per instance lister or {} if none. - - """ - all_creds = self.config.get('credentials') - if not all_creds: - return {} - lister_creds = all_creds.get(self.LISTER_NAME, {}) - creds = lister_creds.get(self.instance, {}) - return creds - - def request_uri(self, identifier): - """Get the full request URI given the transport_request identifier. - - MAY BE OVERRIDDEN if something more complex than the PATH_TEMPLATE is - required. - """ - path = self.PATH_TEMPLATE % identifier - return self.api_baseurl + path - - def request_params(self, identifier): - """Get the full parameters passed to requests given the - transport_request identifier. - - This uses credentials if any are provided. The 'credentials' - configuration is expected to be a dict of multiple levels. The first - level is the lister's name, the second is the lister's instance name. + The 'credentials' configuration is expected to be a dict of multiple + levels. The first level is the lister's name, the second is the + lister's instance name, which value is expected to be a list of + credential structures (typically a couple username/password). For example: @@ -101,6 +78,32 @@ class ListerHttpTransport(abc.ABC): password: ... - ... + Returns: + list of credential dicts for the current lister. + + """ + all_creds = self.config.get('credentials') + if not all_creds: + return [] + lister_creds = all_creds.get(self.LISTER_NAME, {}) + creds = lister_creds.get(self.instance, []) + return creds + + def request_uri(self, identifier): + """Get the full request URI given the transport_request identifier. + + MAY BE OVERRIDDEN if something more complex than the PATH_TEMPLATE is + required. + """ + path = self.PATH_TEMPLATE % identifier + return self.api_baseurl + path + + def request_params(self, identifier): + """Get the full parameters passed to requests given the + transport_request identifier. + + This uses credentials if any are provided (see + request_instance_credentials). MAY BE OVERRIDDEN if something more complex than the request headers is needed.