Changeset View
Changeset View
Standalone View
Standalone View
swh/lister/core/lister_transports.py
Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | def request_uri(self, identifier): | ||||
""" | """ | ||||
path = self.PATH_TEMPLATE % identifier | path = self.PATH_TEMPLATE % identifier | ||||
return self.api_baseurl + path | return self.api_baseurl + path | ||||
def request_params(self, identifier): | def request_params(self, identifier): | ||||
"""Get the full parameters passed to requests given the | """Get the full parameters passed to requests given the | ||||
transport_request identifier. | 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. | |||||
For example: | |||||
credentials: | |||||
github: # github lister | |||||
github: # has only one instance (so far) | |||||
- username: some | |||||
password: somekey | |||||
- username: one | |||||
password: onekey | |||||
- ... | |||||
gitlab: # gitlab lister | |||||
riseup: # has many instances | |||||
- username: someone | |||||
password: ... | |||||
- ... | |||||
gitlab: | |||||
- username: someone | |||||
password: ... | |||||
- ... | |||||
MAY BE OVERRIDDEN if something more complex than the request headers | MAY BE OVERRIDDEN if something more complex than the request headers | ||||
is needed. | is needed. | ||||
""" | """ | ||||
params = {} | params = {} | ||||
params['headers'] = self.request_headers() or {} | params['headers'] = self.request_headers() or {} | ||||
creds = self.config['credentials'] | all_creds = self.config['credentials'] | ||||
lister_creds = all_creds.get(self.LISTER_NAME, {}) | |||||
creds = lister_creds.get(self.instance, {}) | |||||
auth = random.choice(creds) if creds else None | auth = random.choice(creds) if creds else None | ||||
if auth: | if auth: | ||||
params['auth'] = (auth['username'], auth['password']) | params['auth'] = (auth['username'], auth['password']) | ||||
return params | return params | ||||
def transport_quota_check(self, response): | def transport_quota_check(self, response): | ||||
"""Implements SWHListerBase.transport_quota_check with standard 429 | """Implements SWHListerBase.transport_quota_check with standard 429 | ||||
code check for HTTP with Requests library. | code check for HTTP with Requests library. | ||||
▲ Show 20 Lines • Show All 101 Lines • Show Last 20 Lines |