Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add console auth token resource #10

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion esi/lease/v1/_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# under the License.

from esi.lease.v1 import _common
from esi.lease.v1 import console_auth_token as _console_auth_token
from esi.lease.v1 import event as _event
from esi.lease.v1 import lease as _lease
from esi.lease.v1 import node as _node
Expand All @@ -25,7 +26,8 @@ class Proxy(proxy.Proxy):
"offer": _offer.Offer,
"lease": _lease.Lease,
"node": _node.Node,
"event": _event.Event
"event": _event.Event,
"console_auth_token": _console_auth_token.ConsoleAuthToken,
}
skip_discovery = True

Expand Down Expand Up @@ -245,3 +247,31 @@ def events(self, **query):
:returns: A generator of event instances.
"""
return _event.Event.list(self, **query)

def create_console_auth_token(self, **attrs):
"""Create a new console auth token from attributes.

:param string node_uuid_or_name: node uuid or name

:returns: The results of token creation.
:rtype: :class:`~esi_leap.v1.console_auth_token.ConsoleAuthToken`.
"""
return self._create(_console_auth_token.ConsoleAuthToken, **attrs)

def delete_console_auth_token(self, node_uuid_or_name, ignore_missing=True):
"""Delete a console auth token for a node.

:param string node_uuid_or_name: node uuid or name
:param bool ignore_missing: When set to ``False``, an exception
:class:`~openstack.exceptions.ResourceNotFound` will be raised
when the node could not be found. When set to ``True``, no
exception will be raised when attempting to delete a non-existent
offer.

:returns: The result of delete.
:rtype: :class:`~esi_leap.v1.console_auth_token.ConsoleAuthToken`.
"""
return self._delete(
_console_auth_token.ConsoleAuthToken,
node_uuid_or_name,
ignore_missing=ignore_missing)
35 changes: 35 additions & 0 deletions esi/lease/v1/console_auth_token.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from openstack import resource


class ConsoleAuthToken(resource.Resource):
resources_key = 'console_auth_tokens'
base_path = '/console_auth_tokens'

# capabilities
allow_create = True
allow_fetch = False
allow_commit = True
allow_delete = True
allow_list = False
commit_method = 'PATCH'
commit_jsonpatch = True

#: The transaction date and time.
timestamp = resource.Header("x-timestamp")
#: The value of the resource. Also available in headers.
node_uuid = resource.Body("node_uuid", alternate_id=True)
node_uuid_or_name = resource.Body("node_uuid_or_name")
token = resource.Body("token")
access_url = resource.Body("access_url")
40 changes: 40 additions & 0 deletions esi/tests/unit/lease/v1/test_console_auth_token.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from esi.lease.v1 import console_auth_token
from openstack.tests.unit import base


FAKE = {'node_uuid': 'node_001',
'token': 'fake_token',
'access_url': 'ws://0.0.0.0:7777?token=fake_token',
}


class TestConsoleAuthToken(base.TestCase):
def test_basic(self):
c = console_auth_token.ConsoleAuthToken()
self.assertIsNone(c.resource_key)
self.assertEqual('console_auth_tokens', c.resources_key)
self.assertEqual('/console_auth_tokens', c.base_path)
self.assertTrue(c.allow_create)
self.assertFalse(c.allow_fetch)
self.assertTrue(c.allow_commit)
self.assertTrue(c.allow_delete)
self.assertFalse(c.allow_list)
self.assertEqual('PATCH', c.commit_method)

def test_instantiate(self):
c = console_auth_token.ConsoleAuthToken(**FAKE)
self.assertEqual(FAKE['node_uuid'], c.node_uuid)
self.assertEqual(FAKE['token'], c.token)
self.assertEqual(FAKE['access_url'], c.access_url)
11 changes: 11 additions & 0 deletions esi/tests/unit/lease/v1/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from unittest import mock

from esi.lease.v1 import _proxy
from esi.lease.v1 import console_auth_token
from esi.lease.v1 import event
from esi.lease.v1 import lease
from esi.lease.v1 import node
Expand Down Expand Up @@ -93,3 +94,13 @@ def test_events(self, mock_list):
result = self.proxy.events(query=1)
self.assertIs(result, mock_list.return_value)
mock_list.assert_called_once_with(self.proxy, query=1)


class TestConsoleAuthToken(TestESILEAPProxy):
def test_create_console_auth_token(self):
self.verify_create(self.proxy.create_console_auth_token,
console_auth_token.ConsoleAuthToken)

def test_delete_console_auth_token(self):
self.verify_delete(self.proxy.delete_console_auth_token,
console_auth_token.ConsoleAuthToken, False)
Loading