ALBS-931 Added integration with AlmaLinux Build System (errata feed) #3
@ -1,6 +1,7 @@
|
|||||||
"""
|
"""
|
||||||
albs.py contains ALBS class
|
albs.py contains ALBS class
|
||||||
"""
|
"""
|
||||||
|
from urllib.parse import urljoin
|
||||||
from typing import Union, Dict
|
from typing import Union, Dict
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
@ -12,8 +13,6 @@ class ALBS:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, url: str, token: str, timeout: int):
|
def __init__(self, url: str, token: str, timeout: int):
|
||||||
kzhukov marked this conversation as resolved
|
|||||||
if url.endswith('/'):
|
|
||||||
url = url[:-1]
|
|
||||||
self.url = url
|
self.url = url
|
||||||
self.token = token
|
self.token = token
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
@ -27,13 +26,12 @@ class ALBS:
|
|||||||
endpoint = '/api/v1/platforms/'
|
endpoint = '/api/v1/platforms/'
|
||||||
headers = {'accept': 'application/json',
|
headers = {'accept': 'application/json',
|
||||||
'Authorization': f'Bearer {self.token}'}
|
'Authorization': f'Bearer {self.token}'}
|
||||||
response = requests.get(url=self.url+endpoint,
|
response = requests.get(url=urljoin(self.url, endpoint),
|
||||||
headers=headers,
|
headers=headers,
|
||||||
kzhukov marked this conversation as resolved
soksanichenko
commented
That code join part of an URL right in all cases `self.url+endpoint` don't do the same, please :)
```
from urllib.parse import urljoin
urljoin(url + '/', some_uri)
```
That code join part of an URL right in all cases
|
|||||||
timeout=self.timeout)
|
timeout=self.timeout)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
res = {}
|
res = {platform['name']: platform['id']
|
||||||
for platform in response.json():
|
for platform in response.json()}
|
||||||
soksanichenko
commented
That looks more pretty I guess
That looks more pretty I guess
```
res = {platform['name']: platform['id'] for platform in response.json()}
```
|
|||||||
res[platform['name']] = platform['id']
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def get_errata_status(self, errata_id: str, platform_name: str) -> Union[str, None]:
|
def get_errata_status(self, errata_id: str, platform_name: str) -> Union[str, None]:
|
||||||
@ -60,7 +58,7 @@ class ALBS:
|
|||||||
params = {'id': errata_id, 'platformId': platform_id}
|
params = {'id': errata_id, 'platformId': platform_id}
|
||||||
headers = {'accept': 'application/json',
|
headers = {'accept': 'application/json',
|
||||||
'Authorization': f'Bearer {self.token}'}
|
'Authorization': f'Bearer {self.token}'}
|
||||||
response = requests.get(url=self.url+endpoint,
|
response = requests.get(url=urljoin(self.url, endpoint),
|
||||||
params=params, headers=headers,
|
params=params, headers=headers,
|
||||||
timeout=self.timeout)
|
timeout=self.timeout)
|
||||||
kzhukov marked this conversation as resolved
soksanichenko
commented
same as above same as above
|
|||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
@ -68,5 +66,5 @@ class ALBS:
|
|||||||
|
|
||||||
# errata_id was not found
|
# errata_id was not found
|
||||||
if response_json['total_records'] == 0:
|
if response_json['total_records'] == 0:
|
||||||
return None
|
return
|
||||||
return response_json['records'][0]['release_status']
|
return response_json['records'][0]['release_status']
|
||||||
|
Loading…
Reference in New Issue
Block a user
It's not necessary if you fix comments below.