Skip to content

Commit 20db3a2

Browse files
authored
feat(apig-tag): implemented (#600)
feat(apig-tag): implemented Reviewed-by: Anton Sidelnikov
1 parent e2c3727 commit 20db3a2

File tree

12 files changed

+233
-0
lines changed

12 files changed

+233
-0
lines changed

doc/source/sdk/guides/apig.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,3 +1358,15 @@ in the API Gateway.
13581358

13591359
.. literalinclude:: ../examples/apig/list_group_responses.py
13601360
:lines: 16-23
1361+
1362+
Tag
1363+
---
1364+
1365+
Listing Tags
1366+
^^^^^^^^^^^^
1367+
1368+
This example demonstrates how to list all tags associated with a specific
1369+
API Gateway.
1370+
1371+
.. literalinclude:: ../examples/apig/list_tags.py
1372+
:lines: 16-21

doc/source/sdk/proxies/apig.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,9 @@ Group Response Operations
186186
:members: create_group_response, update_group_response,
187187
delete_group_response, group_responses, get_group_response,
188188
get_error_response, update_error_response, delete_error_response
189+
190+
Tag Operations
191+
^^^^^^^^^^^^^^
192+
.. autoclass:: otcextensions.sdk.apig.v2._proxy.Proxy
193+
:noindex:
194+
:members: tags

doc/source/sdk/resources/apig/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ ApiGateway Resources
3333
v2/metric_data
3434
v2/group_response
3535
v2/error_response
36+
v2/tag
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
otcextensions.sdk.apig.v2.tag
2+
=============================
3+
4+
.. automodule:: otcextensions.sdk.apig.v2.tag
5+
6+
The Tag Class
7+
-------------
8+
9+
The ``Tag`` class inherits from
10+
:class:`~otcextensions.sdk.sdk_resource.Resource`.
11+
12+
.. autoclass:: otcextensions.sdk.apig.v2.tag.Tag
13+
:members:

examples/apig/list_tags.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python3
2+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
3+
# not use this file except in compliance with the License. You may obtain
4+
# a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11+
# License for the specific language governing permissions and limitations
12+
# under the License.
13+
"""
14+
List tags for API gateway
15+
"""
16+
import openstack
17+
18+
openstack.enable_logging(True)
19+
conn = openstack.connect(cloud='otc')
20+
tags = list(conn.apig.tags(gateway="gateway_id"))
21+
print("Tags:", tags)

otcextensions/sdk/apig/v2/_proxy.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
from otcextensions.sdk.apig.v2 import metric_data as _metric_data
4444
from otcextensions.sdk.apig.v2 import group_response as _group_response
4545
from otcextensions.sdk.apig.v2 import error_response as _error_response
46+
from otcextensions.sdk.apig.v2 import tag as _tag
4647

4748

4849
class Proxy(proxy.Proxy):
@@ -3105,6 +3106,23 @@ def delete_group_response(self, gateway, group, response,
31053106
)
31063107

31073108
def get_error_response(self, gateway, group, response, response_type):
3109+
"""
3110+
Retrieve a specific error response for an API group
3111+
This method fetches details of a specific error response for an API
3112+
group within the specified API Gateway instance.
3113+
3114+
:param gateway: The ID of the API Gateway instance or an instance of
3115+
:class:`~otcextensions.sdk.apig.v2.gateway.Gateway`
3116+
:param group: The ID of the API group or an instance of
3117+
:class:`~otcextensions.sdk.apig.v2.group.Group`
3118+
:param response: The ID of the group response or an instance of
3119+
:class:`~otcextensions.sdk.apig.v2.group_response.GroupResponse`
3120+
:param response_type: The type of the error response (e.g., 'default',
3121+
'unauthorized', 'not_found', etc.)
3122+
3123+
:returns: An instance of
3124+
:class:`~otcextensions.sdk.apig.v2.error_response.ErrorResponse`
3125+
"""
31083126
gateway = self._get_resource(_gateway.Gateway, gateway)
31093127
group = self._get_resource(_api_group.ApiGroup, group)
31103128
response = self._get_resource(_group_response.GroupResponse, response)
@@ -3119,6 +3137,23 @@ def get_error_response(self, gateway, group, response, response_type):
31193137

31203138
def update_error_response(self, gateway, group, response, response_type,
31213139
**attrs):
3140+
"""Update a custom error response for an API group
3141+
This method updates an existing custom error response for a specific
3142+
API group within the specified API Gateway instance.
3143+
3144+
:param gateway: The ID of the API Gateway instance or an instance of
3145+
:class:`~otcextensions.sdk.apig.v2.gateway.Gateway`
3146+
:param group: The ID of the API group or an instance of
3147+
:class:`~otcextensions.sdk.apig.v2.group.Group`
3148+
:param response: The ID of the group response or an instance of
3149+
:class:`~otcextensions.sdk.apig.v2.group_response.GroupResponse`
3150+
:param response_type: The type of the error response (e.g., 'default',
3151+
'unauthorized', 'not_found', etc.)
3152+
:param attrs: Attributes to update in the error response
3153+
3154+
:returns: The updated instance of
3155+
:class:`~otcextensions.sdk.apig.v2.error_response.ErrorResponse`
3156+
"""
31223157
gateway = self._get_resource(_gateway.Gateway, gateway)
31233158
response = self._get_resource(_group_response.GroupResponse, response)
31243159
group = self._get_resource(_api_group.ApiGroup, group)
@@ -3133,6 +3168,22 @@ def update_error_response(self, gateway, group, response, response_type,
31333168
)
31343169

31353170
def delete_error_response(self, gateway, group, response, response_type):
3171+
"""
3172+
Delete a custom error response for an API group
3173+
This method deletes a specific custom error response for an API group
3174+
within the specified API Gateway instance.
3175+
3176+
:param gateway: The ID of the API Gateway instance or an instance of
3177+
:class:`~otcextensions.sdk.apig.v2.gateway.Gateway`
3178+
:param group: The ID of the API group or an instance of
3179+
:class:`~otcextensions.sdk.apig.v2.group.Group`
3180+
:param response: The ID of the group response or an instance of
3181+
:class:`~otcextensions.sdk.apig.v2.group_response.GroupResponse`
3182+
:param response_type: The type of the error response (e.g., 'default',
3183+
'unauthorized', 'not_found', etc.)
3184+
3185+
:returns: None
3186+
"""
31363187
gateway = self._get_resource(_gateway.Gateway, gateway)
31373188
group = self._get_resource(_api_group.ApiGroup, group)
31383189
response = self._get_resource(_group_response.GroupResponse, response)
@@ -3144,3 +3195,22 @@ def delete_error_response(self, gateway, group, response, response_type):
31443195
response_id=response.id,
31453196
response_type=response_type,
31463197
)
3198+
3199+
# ======== Tag Management Methods ========
3200+
def tags(self, gateway):
3201+
"""List all tags for an API Gateway instance
3202+
3203+
This method retrieves all tags associated with the specified API
3204+
Gateway instance.
3205+
3206+
:param gateway: The ID of the API Gateway instance or an instance of
3207+
:class:`~otcextensions.sdk.apig.v2.gateway.Gateway`
3208+
3209+
:returns: A generator of
3210+
:class:`~otcextensions.sdk.apig.v2.tag.Tag` instances
3211+
"""
3212+
gateway = self._get_resource(_gateway.Gateway, gateway)
3213+
return self._list(
3214+
_tag.Tag,
3215+
gateway_id=gateway.id
3216+
)

otcextensions/sdk/apig/v2/tag.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
from openstack import resource
13+
14+
15+
class Tag(resource.Resource):
16+
base_path = 'apigw/instances/%(gateway_id)s/tags'
17+
18+
_query_mapping = resource.QueryParameters('limit', 'offset')
19+
20+
allow_list = True
21+
22+
gateway_id = resource.URI('gateway_id')
23+
tags = resource.Body('tags', type=list)
24+
size = resource.Body('size', type=int)
25+
total = resource.Body('total', type=int)

otcextensions/tests/functional/sdk/apig/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,20 @@ def get_attrs(self):
3030
security_group = security_groups[0]
3131
available_zone_ids = ["eu-de-01"]
3232
nmb = uuid.uuid4().hex[:8]
33+
tags = [
34+
{
35+
"key": "check_this",
36+
"value": "mate"
37+
}
38+
]
3339
return {
3440
'instance_name': 'test_gateway_{}'.format(nmb),
3541
'spec_id': 'BASIC',
3642
'vpc_id': vpc.id,
3743
'subnet_id': subnet.id,
3844
'security_group_id': security_group.id,
3945
'available_zone_ids': available_zone_ids,
46+
'tags': tags
4047
}
4148

4249
def create_gateway(self):
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
from otcextensions.tests.functional.sdk.apig import TestApiG
13+
14+
15+
class TestTags(TestApiG):
16+
17+
def setUp(self):
18+
super(TestTags, self).setUp()
19+
self.create_gateway()
20+
21+
def tearDown(self):
22+
super(TestTags, self).tearDown()
23+
self.delete_gateway()
24+
25+
def test_list_tags(self):
26+
tags = list(self.client.tags(gateway=TestTags.gateway))
27+
print("Tags:", tags)
28+
self.assertGreater(len(tags), 0, "No tags found")

otcextensions/tests/unit/sdk/apig/v2/test_proxy.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from otcextensions.sdk.apig.v2 import backend_server_group as _vpc_sg
3737
from otcextensions.sdk.apig.v2 import backend_server as _vpc_s
3838
from otcextensions.sdk.apig.v2 import group_response as _group_response
39+
from otcextensions.sdk.apig.v2 import tag as _tag
3940
from openstack.tests.unit import test_proxy_base
4041
from unittest import mock
4142

@@ -1986,3 +1987,15 @@ def test_delete_error_response(self):
19861987
'group_id': None, 'response_id': None,
19871988
'response_type': None}
19881989
)
1990+
1991+
1992+
class TestTag(TestApiGatewayProxy):
1993+
def test_list_tags(self):
1994+
gateway = _gateway.Gateway()
1995+
self.verify_list(self.proxy.tags,
1996+
_tag.Tag,
1997+
method_args=[gateway],
1998+
expected_args=[],
1999+
method_kwargs={},
2000+
expected_kwargs={'gateway_id': None}
2001+
)

0 commit comments

Comments
 (0)