Skip to content

Commit

Permalink
Add support for delete with args, and republish_repositories endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
sambible committed Jul 30, 2024
1 parent 419e7f9 commit 0c3cb26
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
43 changes: 42 additions & 1 deletion nailgun/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2618,11 +2618,13 @@ def path(self, which=None):
/content_view_versions/<id>/promote
verify_checksum
/content_view_versions/<id>/verify_checksum
republish_repositories
/content_view_versions/<id>/republish_repositories
``super`` is called otherwise.
"""
if which in ("incremental_update", "promote", "verify_checksum"):
if which in ("incremental_update", "promote", "verify_checksum", "republish_repositories"):
prefix = "base" if which == "incremental_update" else "self"
return f"{super().path(prefix)}/{which}"
return super().path(which)
Expand Down Expand Up @@ -2684,6 +2686,25 @@ def verify_checksum(self, synchronous=True, timeout=None, **kwargs):
response = client.post(self.path('verify_checksum'), **kwargs)
return _handle_response(response, self._server_config, synchronous, timeout)

def republish_repositories(self, synchronous=True, timeout=None, **kwargs):
"""Force a republish of the version's repositories' metadata.
:param synchronous: What should happen if the server returns an HTTP
202 (accepted) status code? Wait for the task to complete if
``True``. Immediately return the server's response otherwise.
:param timeout: Maximum number of seconds to wait until timing out.
Defaults to ``nailgun.entity_mixins.TASK_TIMEOUT``.
:param kwargs: Arguments to pass to requests.
:returns: The server's response, with all JSON decoded.
:raises: ``requests.exceptions.HTTPError`` If the server responds with
an HTTP 4XX or 5XX message.
"""
kwargs = kwargs.copy() # shadow the passed-in kwargs
kwargs.update(self._server_config.get_client_kwargs())
response = client.put(self.path('republish_repositories'), **kwargs)
return _handle_response(response, self._server_config, synchronous, timeout)


class ContentViewFilterRule(
Entity,
Expand Down Expand Up @@ -6839,6 +6860,7 @@ def __init__(self, server_config=None, **kwargs):
default='yum',
required=True,
),
'is_container_push': entity_fields.BooleanField(default=False),
'container_repository_name': entity_fields.StringField(),
# Just setting `str_type='alpha'` will fail with this error:
# {"docker_upstream_name":["must be a valid docker name"]}}
Expand Down Expand Up @@ -6973,6 +6995,25 @@ def docker_manifests(self, synchronous=True, timeout=None, **kwargs):
response = client.get(self.path('docker_manifests'), **kwargs)
return _handle_response(response, self._server_config, synchronous, timeout)

def delete_with_args(self, synchronous=True, timeout=None, **kwargs):
"""Delete a repository, and respect args passed to it.
:param synchronous: What should happen if the server returns an HTTP
202 (accepted) status code? Wait for the task to complete if
``True``. Immediately return the server's response otherwise.
:param timeout: Maximum number of seconds to wait until timing out.
Defaults to ``nailgun.entity_mixins.TASK_TIMEOUT``.
:param kwargs: Arguments to pass to requests.
:returns: The server's response, with all JSON decoded.
:raises: ``requests.exceptions.HTTPError`` If the server responds with
an HTTP 4XX or 5XX message.
"""
kwargs = kwargs.copy() # shadow the passed-in kwargs
kwargs.update(self._server_config.get_client_kwargs())
response = client.delete(self.path(), **kwargs)
return _handle_response(response, self._server_config, synchronous, timeout)

def errata(self, synchronous=True, timeout=None, **kwargs):
"""List errata inside repository.
Expand Down
2 changes: 2 additions & 0 deletions tests/test_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ def test_id_and_which(self):
(entities.ContentView, 'publish'),
(entities.ContentViewVersion, 'promote'),
(entities.ContentViewVersion, 'verify_checksum'),
(entities.ContentViewVersion, 'republish_repositories'),
(entities.DiscoveredHost, 'auto_provision'),
(entities.DiscoveredHost, 'refresh_facts'),
(entities.DiscoveredHost, 'reboot'),
Expand Down Expand Up @@ -344,6 +345,7 @@ def test_id_and_which(self):
(entities.Product, 'sync'),
(entities.PuppetClass, 'smart_class_parameters'),
(entities.Repository, 'docker_manifests'),
(entities.Repository, 'delete_with_args'),
(entities.Repository, 'errata'),
(entities.Repository, 'packages'),
(entities.Repository, 'remove_content'),
Expand Down

0 comments on commit 0c3cb26

Please sign in to comment.