Skip to content

Commit 5fff171

Browse files
[Feat.] APIG Signature key bind (#544)
[Feat.] APIG Signature key bind Implements: https://docs.otc.t-systems.com/api-gateway/api-ref/dedicated_gateway_apis_v2/binding_unbinding_signature_keys/index.html Closes #540 Reviewed-by: Muneeb H. Jan <muneebhafeezjan@gmail.com>
1 parent a637f86 commit 5fff171

15 files changed

Lines changed: 896 additions & 3 deletions

File tree

doc/source/sdk/guides/apig.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,3 +503,46 @@ This example demonstrates how to fetch all signature keys.
503503

504504
.. literalinclude:: ../examples/apig/list_signatures.py
505505
:lines: 16-20
506+
507+
Binding a Signature Key
508+
^^^^^^^^^^^^^^^^^^^^^^^
509+
510+
This example demonstrates how to bind a signature key.
511+
512+
.. literalinclude:: ../examples/apig/bind_signature.py
513+
:lines: 16-28
514+
515+
Unbinding a Signature Key
516+
^^^^^^^^^^^^^^^^^^^^^^^^^
517+
518+
This example demonstrates how to unbind a signature key.
519+
520+
.. literalinclude:: ../examples/apig/unbind_signature.py
521+
:lines: 16-24
522+
523+
Querying Signature Keys Bound to an API
524+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
525+
526+
This example demonstrates how to list the signature keys that
527+
have been bound to a specified API.
528+
529+
.. literalinclude:: ../examples/apig/list_bound_signatures.py
530+
:lines: 16-24
531+
532+
Querying APIs Not Bound with a Signature Key
533+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
534+
535+
This example demonstrates how to list the APIs to which a signature key
536+
has not been bound.
537+
538+
.. literalinclude:: ../examples/apig/list_not_bound_apis.py
539+
:lines: 16-23
540+
541+
Querying APIs Bound with a Signature Key
542+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
543+
544+
This example demonstrates how to list the APIs to which a signature key
545+
has been bound.
546+
547+
.. literalinclude:: ../examples/apig/list_bound_apis.py
548+
:lines: 16-24

doc/source/sdk/proxies/apig.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,5 @@ Signature Key Operations
6666
.. autoclass:: otcextensions.sdk.apig.v2._proxy.Proxy
6767
:noindex:
6868
:members: create_signature, update_signature, delete_signature,
69-
signatures
69+
signatures, bind_signature, unbind_signature, bound_signatures,
70+
not_bound_apis, bound_apis

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ ApiGateway Resources
1313
v2/api
1414
v2/api_supplements
1515
v2/signature
16+
v2/signature_bind
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
otcextensions.sdk.apig.v2.signature_binding
2+
===========================================
3+
4+
.. automodule:: otcextensions.sdk.apig.v2.signature_binding
5+
6+
The SignatureBind Class
7+
-----------------------
8+
9+
The ``SignatureBind`` class inherits from
10+
:class:`~otcextensions.sdk.sdk_resource.Resource`.
11+
12+
.. autoclass:: otcextensions.sdk.apig.v2.signature_binding.SignatureBind
13+
:members:
14+
15+
The NotBoundApi Class
16+
-----------------------
17+
18+
The ``NotBoundApi`` class inherits from
19+
:class:`~otcextensions.sdk.sdk_resource.Resource`.
20+
21+
.. autoclass:: otcextensions.sdk.apig.v2.signature_binding.NotBoundApi
22+
:members:
23+
24+
The BoundApi Class
25+
-----------------------
26+
27+
The ``BoundApi`` class inherits from
28+
:class:`~otcextensions.sdk.sdk_resource.Resource`.
29+
30+
.. autoclass:: otcextensions.sdk.apig.v2.signature_binding.BoundApi
31+
:members:

examples/apig/bind_signature.py

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+
Bind Signature to API
15+
"""
16+
import openstack
17+
18+
openstack.enable_logging(True)
19+
conn = openstack.connect(cloud='otc')
20+
21+
attrs = {
22+
"sign_id": "sign_id",
23+
"publish_ids": ["publish_id"]
24+
}
25+
bind = conn.apig.bind_signature(
26+
gateway="gateway_id",
27+
**attrs
28+
)

examples/apig/list_bound_apis.py

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 APIs Bound with a Signature Key
15+
"""
16+
import openstack
17+
18+
openstack.enable_logging(True)
19+
conn = openstack.connect(cloud='otc')
20+
21+
apis = list(conn.apig.bound_apis(
22+
gateway="gateway_id",
23+
sign_id="sign_id"
24+
))
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 Signature Keys Bound to an API
15+
"""
16+
import openstack
17+
18+
openstack.enable_logging(True)
19+
conn = openstack.connect(cloud='otc')
20+
21+
signs = list(conn.apig.bound_signatures(
22+
gateway="gateway_id",
23+
api_id="api_id"
24+
))
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 APIs Not Bound with a Signature Key
15+
"""
16+
import openstack
17+
18+
openstack.enable_logging(True)
19+
conn = openstack.connect(cloud='otc')
20+
apis = list(conn.apig.not_bound_apis(
21+
gateway="gateway_id",
22+
sign_id="sign_id"
23+
))

examples/apig/unbind_signature.py

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+
Unbind Signature from API
15+
"""
16+
import openstack
17+
18+
openstack.enable_logging(True)
19+
conn = openstack.connect(cloud='otc')
20+
21+
conn.apig.unbind_signature(
22+
gateway="gateway_id",
23+
bind="binding_id"
24+
)

otcextensions/sdk/apig/v2/_proxy.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from otcextensions.sdk.apig.v2 import api as _api
2323
from otcextensions.sdk.apig.v2 import api_supplements as _supp
2424
from otcextensions.sdk.apig.v2 import signature as _sign
25+
from otcextensions.sdk.apig.v2 import signature_binding as _sign_bind
2526

2627

2728
class Proxy(proxy.Proxy):
@@ -981,3 +982,92 @@ def signatures(self, gateway, **attrs):
981982
gateway_id=gateway.id,
982983
**attrs
983984
)
985+
986+
# ======== Signature Binding Methods ========
987+
988+
def bind_signature(self, gateway, **attrs):
989+
"""Bind a Signature for a specific API.
990+
991+
:param gateway: The ID of the gateway or an instance of
992+
:class:`~otcextensions.sdk.apig.v2.gateway.Gateway`
993+
:param attrs: Additional attributes for the Signature bind.
994+
995+
:returns: An instance of SignatureBind
996+
"""
997+
gateway = self._get_resource(_gateway.Gateway, gateway)
998+
return self._create(
999+
_sign_bind.SignatureBind,
1000+
gateway_id=gateway.id,
1001+
**attrs)
1002+
1003+
def unbind_signature(self, gateway, bind, ignore_missing=False):
1004+
"""Unbind a bound Signature from a specific API.
1005+
1006+
:param gateway: The ID of the gateway or an instance of
1007+
:class:`~otcextensions.sdk.apig.v2.gateway.Gateway`
1008+
:param bind: The ID of the SignatureBind or an instance
1009+
of SignatureBind
1010+
1011+
:returns: None
1012+
"""
1013+
gateway = self._get_resource(_gateway.Gateway, gateway)
1014+
bind = self._get_resource(_sign_bind.SignatureBind, bind)
1015+
return self._delete(
1016+
_sign_bind.SignatureBind,
1017+
bind,
1018+
gateway_id=gateway.id,
1019+
ignore_missing=ignore_missing
1020+
)
1021+
1022+
def bound_signatures(self, gateway, **query):
1023+
"""List all Signatures bound a specific API.
1024+
1025+
:param gateway: The ID of the gateway or an instance of
1026+
:class:`~otcextensions.sdk.apig.v2.gateway.Gateway`
1027+
:param query: Additional filters for listing SignatureBind.
1028+
1029+
:returns: A list of instances of SignatureBind
1030+
"""
1031+
gateway = self._get_resource(_gateway.Gateway, gateway)
1032+
bp = '/apigw/instances/%(gateway_id)s/sign-bindings/binded-signs'
1033+
return self._list(
1034+
_sign_bind.SignatureBind,
1035+
paginated=False,
1036+
gateway_id=gateway.id,
1037+
base_path=bp,
1038+
**query
1039+
)
1040+
1041+
def not_bound_apis(self, gateway, **query):
1042+
"""List all APIs to which a signature key has not been bound.
1043+
1044+
:param gateway: The ID of the gateway or an instance of
1045+
:class:`~otcextensions.sdk.apig.v2.gateway.Gateway`
1046+
:param query: Additional filters for listing NotBoundApi.
1047+
1048+
:returns: A list of instances of NotBoundApi
1049+
"""
1050+
gateway = self._get_resource(_gateway.Gateway, gateway)
1051+
return self._list(
1052+
_sign_bind.NotBoundApi,
1053+
paginated=False,
1054+
gateway_id=gateway.id,
1055+
**query
1056+
)
1057+
1058+
def bound_apis(self, gateway, **query):
1059+
"""List all APIs to which a signature key has been bound.
1060+
1061+
:param gateway: The ID of the gateway or an instance of
1062+
:class:`~otcextensions.sdk.apig.v2.gateway.Gateway`
1063+
:param query: Additional filters for listing BoundApi.
1064+
1065+
:returns: A list of instances of BoundApi
1066+
"""
1067+
gateway = self._get_resource(_gateway.Gateway, gateway)
1068+
return self._list(
1069+
_sign_bind.BoundApi,
1070+
paginated=False,
1071+
gateway_id=gateway.id,
1072+
**query
1073+
)

0 commit comments

Comments
 (0)