Skip to content

Commit b7f072d

Browse files
committed
Add support for Registration Tokens
1 parent bcf600d commit b7f072d

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

nailgun/entities.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6904,7 +6904,7 @@ def path(self, which=None):
69046904

69056905

69066906
class RegistrationCommand(Entity, EntityCreateMixin, EntityReadMixin):
6907-
"""A representation of a Role entity."""
6907+
"""A representation of a Registration Command entity."""
69086908

69096909
def __init__(self, server_config=None, **kwargs):
69106910
self._fields = {
@@ -6957,6 +6957,35 @@ def read(self, entity=None, attrs=None, ignore=None, params=None):
69576957
return attrs['registration_command']
69586958

69596959

6960+
class RegistrationTokens(Entity, EntityDeleteMixin):
6961+
"""A representation of Registration Token entity."""
6962+
6963+
def __init__(self, server_config=None, user=None, **kwargs):
6964+
self._fields = {
6965+
'location': entity_fields.OneToManyField(Location),
6966+
'organization': entity_fields.OneToManyField(Organization),
6967+
}
6968+
api_path = f'api/users/{user}/registration_tokens' if user else 'api/registration_tokens'
6969+
self._meta = {'api_path': api_path}
6970+
super().__init__(server_config=server_config, **kwargs)
6971+
6972+
def invalidate(self, synchronous=True, timeout=None, **kwargs):
6973+
"""Invalidate tokens for a single user."""
6974+
kwargs = kwargs.copy()
6975+
kwargs.update(self._server_config.get_client_kwargs())
6976+
response = client.delete(self.path(), **kwargs)
6977+
return _handle_response(response, self._server_config, synchronous, timeout)
6978+
6979+
def invalidate_multiple(self, synchronous=True, timeout=None, search=None, **kwargs):
6980+
"""Invalidate tokens for multiple users."""
6981+
kwargs = kwargs.copy()
6982+
if search:
6983+
kwargs['params'] = {'search': search}
6984+
kwargs.update(self._server_config.get_client_kwargs())
6985+
response = client.delete(self.path(), **kwargs)
6986+
return _handle_response(response, self._server_config, synchronous, timeout)
6987+
6988+
69606989
class Report(Entity):
69616990
"""A representation of a Report entity."""
69626991

tests/test_entities.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ def test_init_succeeds(self):
160160
entities.Realm,
161161
entities.RecurringLogic,
162162
entities.RegistrationCommand,
163+
entities.RegistrationTokens,
163164
entities.Report,
164165
entities.Repository,
165166
entities.RepositorySet,
@@ -280,6 +281,7 @@ def test_nowhich(self):
280281
(entities.PuppetClass, '/puppetclasses'),
281282
(entities.RHCIDeployment, '/deployments'),
282283
(entities.RegistrationCommand, '/registration_commands'),
284+
(entities.RegistrationTokens, '/registration_tokens'),
283285
(entities.Repository, '/repositories'),
284286
(entities.Setting, '/settings'),
285287
(entities.SmartProxy, '/smart_proxies'),

0 commit comments

Comments
 (0)