Skip to content

Commit

Permalink
Add cache invalidation route to delivery client
Browse files Browse the repository at this point in the history
  • Loading branch information
8R0WNI3 committed Nov 12, 2024
1 parent 91e212f commit c2b9fdc
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions delivery/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ def components_metadata(self):
'metadata',
)

def cache(self):
return ci.util.urljoin(
self._base_url,
'cache',
)


class DeliveryServiceClient:
def __init__(
Expand Down Expand Up @@ -716,6 +722,32 @@ def metadata(
continue
yield metadata

def mark_cache_for_deletion(
self,
id: str | None=None,
descriptor: dict | None=None,
delete_after: datetime.datetime | None=None,
):
if not id and not descriptor:
raise ValueError('either `id` or `descriptor` must be specified')

params = dict()

if id:
params['id'] = id

if delete_after:
params['deleteAfter'] = delete_after.isoformat()

res = self.request(
url=self._routes.cache(),
method='DELETE',
params=params,
json=descriptor,
)

res.raise_for_status()


def _normalise_github_hostname(github_url: str):
# hack: for github.com, we might get a different subdomain (api.github.com)
Expand Down

0 comments on commit c2b9fdc

Please sign in to comment.