Skip to content

Commit

Permalink
Add flatpak support
Browse files Browse the repository at this point in the history
  • Loading branch information
vsedmik committed Nov 21, 2024
1 parent fdca212 commit 3449e68
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 0 deletions.
112 changes: 112 additions & 0 deletions nailgun/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3469,6 +3469,118 @@ def update_payload(self, fields=None):
return {'filter': super().update_payload(fields)}


class FlatpakRemoteRepository(
Entity,
EntityReadMixin,
EntitySearchMixin,
):
"""A representation of a Flatpak remote repository entity."""

def __init__(self, server_config=None, **kwargs):
self._fields = {
'flatpak_remote_id': entity_fields.IntegerField(required=True),
'name': entity_fields.StringField(),
'label': entity_fields.StringField(),
}
self._meta = {
'api_path': 'katello/api/flatpak_remote_repositories',
}
super().__init__(server_config=server_config, **kwargs)

def path(self, which=None):
"""Extend ``nailgun.entity_mixins.Entity.path``.
The format of the returned path depends on the value of ``which``:
mirror
/katello/api/flatpak_remote_repositories/:id/mirror
"""
if which == "mirror":
return f'{super().path(which="self")}/{which}'
return super().path(which)

def mirror(self, product_id, synchronous=True, timeout=None, **kwargs):
"""Mirror a flatpak remote repository.
: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()
if 'data' not in kwargs:
kwargs['data'] = {}
if 'product_id' not in kwargs['data']:
kwargs['data']['product_id'] = product_id
kwargs.update(self._server_config.get_client_kwargs())
response = client.post(self.path('mirror'), **kwargs)
return _handle_response(response, self._server_config, synchronous, timeout)


class FlatpakRemote(
Entity,
EntityCreateMixin,
EntityDeleteMixin,
EntityReadMixin,
EntitySearchMixin,
EntityUpdateMixin,
):
"""A representation of a Flatpak remote entity."""

def __init__(self, server_config=None, **kwargs):
self._fields = {
'name': entity_fields.StringField(
required=True, str_type='alpha', length=(6, 12), unique=True
),
'url': entity_fields.URLField(required=True),
'organization': entity_fields.OneToOneField(Organization, required=True),
'description': entity_fields.StringField(),
'username': entity_fields.StringField(),
'token': entity_fields.StringField(),
'registry_url': entity_fields.StringField(),
'seeded': entity_fields.BooleanField(),
}
self._meta = {
'api_path': 'katello/api/flatpak_remotes',
}
super().__init__(server_config=server_config, **kwargs)

def path(self, which=None):
"""Extend ``nailgun.entity_mixins.Entity.path``.
The format of the returned path depends on the value of ``which``:
scan
/katello/api/flatpak_remote/:id/scan
"""
if which == "scan":
return f'{super().path(which="self")}/{which}'
return super().path(which)

def scan(self, synchronous=True, timeout=None, **kwargs):
"""Scan a flatpak remote.
: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()
kwargs.update(self._server_config.get_client_kwargs())
response = client.post(self.path('scan'), **kwargs)
return _handle_response(response, self._server_config, synchronous, timeout)


class ForemanStatus(Entity, EntityReadMixin):
"""A representation of the Foreman Status entity."""

Expand Down
10 changes: 10 additions & 0 deletions tests/test_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ def test_init_succeeds(self):
entities.ErratumContentViewFilter,
entities.File,
entities.Filter,
entities.FlatpakRemoteRepository,
entities.FlatpakRemote,
entities.ForemanStatus,
entities.ForemanTask,
entities.GPGKey,
Expand Down Expand Up @@ -267,6 +269,8 @@ def test_nowhich(self):
(entities.DiscoveryRule, '/discovery_rules'),
(entities.Environment, '/environments'),
(entities.Errata, '/errata'),
(entities.FlatpakRemoteRepository, '/flatpak_remote_repositories'),
(entities.FlatpakRemote, '/flatpak_remotes'),
(entities.Organization, '/organizations'),
(entities.Host, '/hosts'),
(entities.HostGroup, '/hostgroups'),
Expand Down Expand Up @@ -317,6 +321,8 @@ def test_id_and_which(self):
(entities.DiscoveredHost, 'refresh_facts'),
(entities.DiscoveredHost, 'reboot'),
(entities.Environment, 'smart_class_parameters'),
(entities.FlatpakRemoteRepository, 'mirror'),
(entities.FlatpakRemote, 'scan'),
(entities.Host, 'enc'),
(entities.Host, 'errata'),
(entities.Host, 'errata/applicability'),
Expand Down Expand Up @@ -617,6 +623,7 @@ def test_generic(self):
entities.DiscoveryRule(self.cfg),
entities.DiscoveredHost(self.cfg),
entities.Domain(self.cfg),
entities.FlatpakRemote(self.cfg),
entities.Host(self.cfg),
entities.HostCollection(self.cfg),
entities.HostGroup(self.cfg),
Expand Down Expand Up @@ -674,6 +681,7 @@ def test_no_attributes(self):
entities.Domain,
entities.Environment,
entities.Filter,
entities.FlatpakRemote,
entities.Host,
entities.HostCollection,
entities.HostGroup,
Expand Down Expand Up @@ -1772,6 +1780,7 @@ def test_generic(self):
entities.Domain(self.cfg),
entities.Environment(self.cfg),
entities.GPGKey(self.cfg),
entities.FlatpakRemote(self.cfg),
entities.Host(self.cfg),
entities.HostCollection(self.cfg),
entities.HostGroup(self.cfg),
Expand Down Expand Up @@ -2143,6 +2152,7 @@ def setUpClass(cls):
(entities.Environment(**generic).list_scparams, 'get'),
(entities.Errata(**generic).compare, 'get'),
(entities.ExternalUserGroup(**external_usergroup).refresh, 'put'),
(entities.FlatpakRemote(**generic).scan, 'post'),
(entities.ForemanTask(cfg).summary, 'get'),
(entities.Organization(**generic).download_debug_certificate, 'get'),
(entities.Host(**generic).add_puppetclass, 'post'),
Expand Down

0 comments on commit 3449e68

Please sign in to comment.