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 42f3020 commit e1a7843
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 @@ -2498,11 +2498,13 @@ def path(self, which=None):
/content_view_versions/incremental_update
promote
/content_view_versions/<id>/promote
republish_repositories
/content_view_versions/<id>/republish_repositories
``super`` is called otherwise.
"""
if which in ("incremental_update", "promote"):
if which in ("incremental_update", "promote", "republish_repositories"):
prefix = "base" if which == "incremental_update" else "self"
return f"{super().path(prefix)}/{which}"
return super().path(which)
Expand Down Expand Up @@ -2545,6 +2547,25 @@ def promote(self, synchronous=True, timeout=None, **kwargs):
response = client.post(self.path('promote'), **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 @@ -6668,6 +6689,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 @@ -6777,6 +6799,25 @@ def create_missing(self):
self._fields['docker_upstream_name'].required = True
super().create_missing()

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 @@ -310,6 +310,7 @@ def test_id_and_which(self):
(entities.ContentView, 'copy'),
(entities.ContentView, 'publish'),
(entities.ContentViewVersion, 'promote'),
(entities.ContentViewVersion, 'republish_repositories'),
(entities.DiscoveredHost, 'auto_provision'),
(entities.DiscoveredHost, 'refresh_facts'),
(entities.DiscoveredHost, 'reboot'),
Expand Down Expand Up @@ -342,6 +343,7 @@ def test_id_and_which(self):
(entities.Organization, 'repo_discover'),
(entities.Product, 'sync'),
(entities.PuppetClass, 'smart_class_parameters'),
(entities.Repository, 'delete_with_args'),
(entities.Repository, 'errata'),
(entities.Repository, 'packages'),
(entities.Repository, 'remove_content'),
Expand Down

0 comments on commit e1a7843

Please sign in to comment.