Skip to content

Commit 959b05b

Browse files
committed
Add support for Registration Tokens
1 parent fce8adb commit 959b05b

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
@@ -6901,7 +6901,7 @@ def path(self, which=None):
69016901

69026902

69036903
class RegistrationCommand(Entity, EntityCreateMixin, EntityReadMixin):
6904-
"""A representation of a Role entity."""
6904+
"""A representation of a Registration Command entity."""
69056905

69066906
def __init__(self, server_config=None, **kwargs):
69076907
self._fields = {
@@ -6954,6 +6954,35 @@ def read(self, entity=None, attrs=None, ignore=None, params=None):
69546954
return attrs['registration_command']
69556955

69566956

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

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)