Changeset View
Changeset View
Standalone View
Standalone View
swh/lister/phabricator/lister.py
Show All 31 Lines | class PhabricatorLister(IndexingHttpLister): | ||||
@property | @property | ||||
def default_min_bound(self): | def default_min_bound(self): | ||||
"""Starting boundary when `min_bound` is not defined (db empty). This | """Starting boundary when `min_bound` is not defined (db empty). This | ||||
is used within the fn:`run` call. | is used within the fn:`run` call. | ||||
""" | """ | ||||
return self._bootstrap_repositories_listing() | return self._bootstrap_repositories_listing() | ||||
def _build_query_params(self, params, api_token): | |||||
"""Build query params to include the forge's api token | |||||
Returns: | |||||
updated params dict with 'params' entry. | |||||
""" | |||||
params.update({'params': {'api.token': api_token}}) | |||||
return params | |||||
def request_params(self, identifier): | def request_params(self, identifier): | ||||
"""Override the default params behavior to retrieve the api token | """Override the default params behavior to retrieve the api token | ||||
Credentials are stored as: | Credentials are stored as: | ||||
credentials: | credentials: | ||||
phabricator: | phabricator: | ||||
<instance>: | <instance>: | ||||
- username: <account> | - username: <account> | ||||
password: <api-token> | password: <api-token> | ||||
""" | """ | ||||
params = {} | |||||
params['headers'] = self.request_headers() or {} | |||||
instance_creds = self.request_instance_credentials() | instance_creds = self.request_instance_credentials() | ||||
if not instance_creds: | if not instance_creds: | ||||
raise ValueError( | raise ValueError( | ||||
'Phabricator forge needs authentication credential to list.') | 'Phabricator forge needs authentication credential to list.') | ||||
api_token = instance_creds[0]['password'] | api_token = instance_creds[0]['password'] | ||||
return self._build_query_params(params, api_token) | |||||
return {'headers': self.request_headers() or {}, | |||||
'params': {'api.token': api_token}} | |||||
def request_headers(self): | def request_headers(self): | ||||
""" | """ | ||||
(Override) Set requests headers to send when querying the | (Override) Set requests headers to send when querying the | ||||
Phabricator API | Phabricator API | ||||
""" | """ | ||||
return {'User-Agent': 'Software Heritage phabricator lister', | return {'User-Agent': 'Software Heritage phabricator lister', | ||||
'Accept': 'application/json'} | 'Accept': 'application/json'} | ||||
▲ Show 20 Lines • Show All 89 Lines • Show Last 20 Lines |