Skip to content

Commit 15248bf

Browse files
authored
fix(custom_authorizer): all methods and docs (#570)
fix(custom_authorizer): all methods and docs Reviewed-by: Anton Sidelnikov
1 parent f524079 commit 15248bf

File tree

16 files changed

+624
-4
lines changed

16 files changed

+624
-4
lines changed

doc/source/sdk/guides/apig.rst

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,3 +1035,51 @@ bound to a specific API in the API Gateway.
10351035

10361036
.. literalinclude:: ../examples/apig/list_acl_for_api.py
10371037
:lines: 16-24
1038+
1039+
Custom Authorizer
1040+
_________________
1041+
1042+
Creating a Custom Authorizer
1043+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1044+
1045+
This example demonstrates how to create a custom authorizer in
1046+
the API Gateway.
1047+
1048+
.. literalinclude:: ../examples/apig/create_custom_authorizer.py
1049+
:lines: 16-28
1050+
1051+
Modifying a Custom Authorizer
1052+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1053+
1054+
This example demonstrates how to modify an existing custom
1055+
authorizer in the API Gateway.
1056+
1057+
.. literalinclude:: ../examples/apig/update_custom_authorizer.py
1058+
:lines: 16-35
1059+
1060+
Deleting a Custom Authorizer
1061+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1062+
1063+
This example demonstrates how to delete a custom authorizer
1064+
in the API Gateway.
1065+
1066+
.. literalinclude:: ../examples/apig/delete_custom_authorizer.py
1067+
:lines: 16-21
1068+
1069+
Querying Custom Authorizer Details
1070+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1071+
1072+
This example demonstrates how to retrieve details of a specific
1073+
custom authorizer in the API Gateway.
1074+
1075+
.. literalinclude:: ../examples/apig/get_custom_authorizer.py
1076+
:lines: 16-21
1077+
1078+
Querying Custom Authorizers
1079+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
1080+
1081+
This example demonstrates how to list all custom authorizers
1082+
configured in the API Gateway.
1083+
1084+
.. literalinclude:: ../examples/apig/list_custom_authorizers.py
1085+
:lines: 16-24

doc/source/sdk/proxies/apig.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,11 @@ Access Control Policy Binding Operations
143143
:noindex:
144144
:members: unbind_acls, unbind_acl, bind_acl_to_api, list_apis_for_acl,
145145
list_acl_for_api, list_api_not_bound_to_acl
146+
147+
Custom Authorizer Operations
148+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
149+
150+
.. autoclass:: otcextensions.sdk.apig.v2._proxy.Proxy
151+
:noindex:
152+
:members: custom_authorizers, get_custom_authorizer, create_custom_authorizer,
153+
update_custom_authorizer, delete_custom_authorizer

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ ApiGateway Resources
2424
v2/api_auth
2525
v2/acl_policy
2626
v2/acl_binding
27+
v2/custom_authorizer
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
otcextensions.sdk.apig.v2.custom_authorizer
2+
===========================================
3+
4+
.. automodule:: otcextensions.sdk.apig.v2.custom_authorizer
5+
6+
The IdentitySpec Class
7+
----------------------
8+
9+
The ``IdentitySpec`` class inherits from
10+
:class:`~otcextensions.sdk.sdk_resource.Resource`.
11+
12+
.. autoclass:: otcextensions.sdk.apig.v2.custom_authorizer.IdentitySpec
13+
:members:
14+
15+
The CustomAuthorizer Class
16+
--------------------------
17+
18+
The ``CustomAuthorizer`` class inherits from
19+
:class:`~otcextensions.sdk.sdk_resource.Resource`.
20+
21+
.. autoclass:: otcextensions.sdk.apig.v2.custom_authorizer.CustomAuthorizer
22+
:members:
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
Create custom authorizer
15+
"""
16+
import openstack
17+
18+
openstack.enable_logging(True)
19+
conn = openstack.connect(cloud='otc')
20+
attrs = {
21+
'name': 'custom_auth_test',
22+
'type': 'BACKEND',
23+
'authorizer_type': 'FUNC',
24+
'authorizer_uri': 'urn:fss:eu-de:7ed5f793b8354ea9b27a849f17af4733'
25+
':function:default:test_apig_authorizer:latest',
26+
'authorizer_version': '1'
27+
}
28+
result = conn.apig.create_custom_authorizer(gateway='gateway_id', **attrs)
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+
Delete custom authorizer
15+
"""
16+
import openstack
17+
18+
openstack.enable_logging(True)
19+
conn = openstack.connect(cloud='otc')
20+
conn.apig.delete_custom_authorizer(gateway='gateway_id',
21+
custom_authorizer='authorizer_id')
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+
Get custom authorizer
15+
"""
16+
import openstack
17+
18+
openstack.enable_logging(True)
19+
conn = openstack.connect(cloud='otc')
20+
found = conn.apig.get_custom_authorizer(gateway='gateway_id',
21+
custom_authorizer='authorizer_id')
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 custom authorizers
15+
"""
16+
import openstack
17+
18+
openstack.enable_logging(True)
19+
conn = openstack.connect(cloud='otc')
20+
attrs = {
21+
'limit': 2
22+
}
23+
found = list(conn.apig.custom_authorizers(gateway='gateway_id',
24+
**attrs))
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
Update custom authorizer
15+
"""
16+
import openstack
17+
18+
openstack.enable_logging(True)
19+
conn = openstack.connect(cloud='otc')
20+
attrs = {
21+
'name': 'custom_auth_test',
22+
'type': 'BACKEND',
23+
'authorizer_type': 'FUNC',
24+
'authorizer_uri': 'urn:fss:eu-de:7ed5f793b8354ea9b27a849f17af4733'
25+
':function:default:test_apig_authorizer:latest',
26+
'authorizer_version': '1',
27+
'ttl': 5,
28+
"identities": [{
29+
"name": "header",
30+
"location": "HEADER"
31+
}]
32+
}
33+
updated = conn.apig.update_custom_authorizer(gateway='gateway_id',
34+
custom_authorizer='authorizer_id',
35+
**attrs)

otcextensions/sdk/apig/v2/_proxy.py

Lines changed: 135 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from otcextensions.sdk.apig.v2 import api_auth as _auth
3535
from otcextensions.sdk.apig.v2 import acl_policy as _acl
3636
from otcextensions.sdk.apig.v2 import acl_api_binding as _acl_api_binding
37+
from otcextensions.sdk.apig.v2 import custom_authorizer as _custom_auth
3738

3839

3940
class Proxy(proxy.Proxy):
@@ -2262,7 +2263,7 @@ def unbind_acls(self, gateway, **attrs):
22622263
"""Unbind multiple access control policies from APIs in batch.
22632264
22642265
This method removes bindings between one or more ACL policies
2265-
and APIs within the specified API Gateway instance.
2266+
and APIs within the specified API Gateway instance
22662267
22672268
:param gateway: The ID of the API Gateway instance or an instance of
22682269
:class:`~otcextensions.sdk.apig.v2.instance.Instance`
@@ -2279,3 +2280,136 @@ def unbind_acls(self, gateway, **attrs):
22792280
gateway_id=gateway.id,
22802281
**attrs
22812282
)
2283+
2284+
# ======== Custom Authorizer Methods ========
2285+
2286+
def custom_authorizers(self, gateway, **attrs):
2287+
"""List all custom authorizers in an API Gateway instance
2288+
2289+
This method retrieves a list of custom authorizers configured within
2290+
the specified API Gateway instance. Custom authorizers allow you to
2291+
define your own logic for validating access tokens and identities
2292+
2293+
:param gateway: The ID of the API Gateway instance or an instance of
2294+
:class:`~otcextensions.sdk.apig.v2.instance.Instance`
2295+
:param attrs: Additional filters for listing custom authorizers,
2296+
such as name or type
2297+
2298+
:returns: A list of instances of
2299+
:class:`~otcextensions.sdk.apig.v2.custom_authorizer.
2300+
CustomAuthorizer`
2301+
"""
2302+
gateway = self._get_resource(_gateway.Gateway, gateway)
2303+
return self._list(
2304+
_custom_auth.CustomAuthorizer,
2305+
paginated=False,
2306+
gateway_id=gateway.id,
2307+
**attrs
2308+
)
2309+
2310+
def get_custom_authorizer(self, gateway, custom_authorizer, **attrs):
2311+
"""Retrieve details of a specific custom authorizer
2312+
2313+
This method retrieves detailed information about a custom authorizer
2314+
within the specified API Gateway instance
2315+
2316+
:param gateway: The ID of the API Gateway instance or an instance of
2317+
:class:`~otcextensions.sdk.apig.v2.instance.Instance`
2318+
:param custom_authorizer: The ID or an instance of
2319+
:class:`~otcextensions.sdk.apig.v2.custom_authorizer
2320+
CustomAuthorizer`
2321+
:param attrs: Additional parameters for retrieving
2322+
the custom authorizer
2323+
2324+
:returns: An instance of
2325+
:class:`~otcextensions.sdk.apig.v2.custom_authorizer.
2326+
CustomAuthorizer`
2327+
"""
2328+
gateway = self._get_resource(_gateway.Gateway, gateway)
2329+
custom_authorizer = self._get_resource(_custom_auth.CustomAuthorizer,
2330+
custom_authorizer)
2331+
return self._get(
2332+
_custom_auth.CustomAuthorizer,
2333+
custom_authorizer,
2334+
gateway_id=gateway.id,
2335+
**attrs
2336+
)
2337+
2338+
def create_custom_authorizer(self, gateway, **attrs):
2339+
"""Create a custom authorizer in an API Gateway instance
2340+
2341+
This method creates a new custom authorizer within the specified
2342+
API Gateway instance. Custom authorizers enable custom
2343+
authentication and authorization logic for APIs
2344+
2345+
:param gateway: The ID of the API Gateway or an instance of
2346+
:class:`~otcextensions.sdk.apig.v2.instance.Instance`
2347+
:param attrs: Attributes required to create the custom authorizer
2348+
2349+
:returns: An instance of
2350+
:class:`~otcextensions.sdk.apig.v2.custom_authorizer.
2351+
CustomAuthorizer`
2352+
"""
2353+
gateway = self._get_resource(_gateway.Gateway, gateway)
2354+
return self._create(
2355+
_custom_auth.CustomAuthorizer,
2356+
gateway_id=gateway.id,
2357+
**attrs
2358+
)
2359+
2360+
def update_custom_authorizer(self, gateway, custom_authorizer, **attrs):
2361+
"""Update a custom authorizer
2362+
2363+
This method updates an existing custom authorizer within the specified
2364+
API Gateway instance
2365+
2366+
:param gateway: The ID of the API Gateway instance or an instance of
2367+
:class:`~otcextensions.sdk.apig.v2.instance.Instance`
2368+
:param custom_authorizer: The ID or an instance of
2369+
:class:`~otcextensions.sdk.apig.v2.custom_authorizer.
2370+
CustomAuthorizer`
2371+
:param attrs: Attributes to update
2372+
2373+
:returns: The updated instance of
2374+
:class:`~otcextensions.sdk.apig.v2.custom_authorizer.
2375+
CustomAuthorizer`
2376+
"""
2377+
gateway = self._get_resource(_gateway.Gateway, gateway)
2378+
custom_authorizer = self._get_resource(_custom_auth.CustomAuthorizer,
2379+
custom_authorizer)
2380+
return self._update(
2381+
_custom_auth.CustomAuthorizer,
2382+
custom_authorizer,
2383+
gateway_id=gateway.id,
2384+
**attrs
2385+
)
2386+
2387+
def delete_custom_authorizer(self, gateway, custom_authorizer,
2388+
ignore_missing=False,
2389+
**attrs):
2390+
"""Delete a custom authorizer
2391+
2392+
This method deletes a custom authorizer from the specified
2393+
API Gateway instance
2394+
2395+
:param gateway: The ID of the API Gateway instance or an instance of
2396+
:class:`~otcextensions.sdk.apig.v2.instance.Instance`
2397+
:param custom_authorizer: The ID or an instance of
2398+
:class:`~otcextensions.sdk.apig.v2.custom_authorizer.
2399+
CustomAuthorizer`
2400+
:param ignore_missing: If True, no exception is raised if
2401+
the authorizer does not exist
2402+
:param attrs: Additional parameters for the delete operation
2403+
2404+
:returns: None
2405+
"""
2406+
gateway = self._get_resource(_gateway.Gateway, gateway)
2407+
custom_authorizer = self._get_resource(_custom_auth.CustomAuthorizer,
2408+
custom_authorizer)
2409+
return self._delete(
2410+
_custom_auth.CustomAuthorizer,
2411+
custom_authorizer,
2412+
gateway_id=gateway.id,
2413+
ignore_missing=ignore_missing,
2414+
**attrs
2415+
)

0 commit comments

Comments
 (0)