diff --git a/delivery/client.py b/delivery/client.py index b423dc9ee..2290f3a40 100644 --- a/delivery/client.py +++ b/delivery/client.py @@ -126,6 +126,20 @@ def cache(self): 'cache', ) + def scan_cfgs(self): + return ci.util.urljoin( + self._base_url, + 'service-extensions', + 'scan-configurations', + ) + + def backlog_items(self): + return ci.util.urljoin( + self._base_url, + 'service-extensions', + 'backlog-items', + ) + class DeliveryServiceClient: def __init__( @@ -745,6 +759,50 @@ def mark_cache_for_deletion( res.raise_for_status() + def create_backlog_item( + self, + service: str, + cfg_name: str, + artefacts: collections.abc.Iterable[dso.model.ComponentArtefactId]=(), + priority: str | None=None, # see delivery-service k8s/backlog for allowed priorities + ): + headers = { + 'Content-Type': 'application/json', + } + + params = dict() + + params['service'] = service + params['cfg_name'] = cfg_name + + if priority: + params['priority'] = priority + + data, headers = http_requests.encode_request( + json={'artefacts': [ + dataclasses.asdict(artefact) + for artefact in artefacts + ]}, + headers=headers, + ) + + res = self.request( + url=self._routes.backlog_items(), + method='POST', + headers=headers, + data=data, + params=params, + ) + res.raise_for_status() + + def scan_cfgs(self) -> list: + res = self.request( + url=self._routes.scan_cfgs(), + method='GET', + ) + res.raise_for_status() + return res.json() + def _normalise_github_hostname(github_url: str): # hack: for github.com, we might get a different subdomain (api.github.com)