Skip to content

Commit

Permalink
[Feat.] APIG Signature key bind (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-sidelnikov authored Feb 27, 2025
1 parent a637f86 commit 5fff171
Show file tree
Hide file tree
Showing 15 changed files with 896 additions and 3 deletions.
43 changes: 43 additions & 0 deletions doc/source/sdk/guides/apig.rst
Original file line number Diff line number Diff line change
Expand Up @@ -503,3 +503,46 @@ This example demonstrates how to fetch all signature keys.

.. literalinclude:: ../examples/apig/list_signatures.py
:lines: 16-20

Binding a Signature Key
^^^^^^^^^^^^^^^^^^^^^^^

This example demonstrates how to bind a signature key.

.. literalinclude:: ../examples/apig/bind_signature.py
:lines: 16-28

Unbinding a Signature Key
^^^^^^^^^^^^^^^^^^^^^^^^^

This example demonstrates how to unbind a signature key.

.. literalinclude:: ../examples/apig/unbind_signature.py
:lines: 16-24

Querying Signature Keys Bound to an API
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This example demonstrates how to list the signature keys that
have been bound to a specified API.

.. literalinclude:: ../examples/apig/list_bound_signatures.py
:lines: 16-24

Querying APIs Not Bound with a Signature Key
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This example demonstrates how to list the APIs to which a signature key
has not been bound.

.. literalinclude:: ../examples/apig/list_not_bound_apis.py
:lines: 16-23

Querying APIs Bound with a Signature Key
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This example demonstrates how to list the APIs to which a signature key
has been bound.

.. literalinclude:: ../examples/apig/list_bound_apis.py
:lines: 16-24
3 changes: 2 additions & 1 deletion doc/source/sdk/proxies/apig.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ Signature Key Operations
.. autoclass:: otcextensions.sdk.apig.v2._proxy.Proxy
:noindex:
:members: create_signature, update_signature, delete_signature,
signatures
signatures, bind_signature, unbind_signature, bound_signatures,
not_bound_apis, bound_apis
1 change: 1 addition & 0 deletions doc/source/sdk/resources/apig/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ ApiGateway Resources
v2/api
v2/api_supplements
v2/signature
v2/signature_bind
31 changes: 31 additions & 0 deletions doc/source/sdk/resources/apig/v2/signature_bind.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
otcextensions.sdk.apig.v2.signature_binding
===========================================

.. automodule:: otcextensions.sdk.apig.v2.signature_binding

The SignatureBind Class
-----------------------

The ``SignatureBind`` class inherits from
:class:`~otcextensions.sdk.sdk_resource.Resource`.

.. autoclass:: otcextensions.sdk.apig.v2.signature_binding.SignatureBind
:members:

The NotBoundApi Class
-----------------------

The ``NotBoundApi`` class inherits from
:class:`~otcextensions.sdk.sdk_resource.Resource`.

.. autoclass:: otcextensions.sdk.apig.v2.signature_binding.NotBoundApi
:members:

The BoundApi Class
-----------------------

The ``BoundApi`` class inherits from
:class:`~otcextensions.sdk.sdk_resource.Resource`.

.. autoclass:: otcextensions.sdk.apig.v2.signature_binding.BoundApi
:members:
28 changes: 28 additions & 0 deletions examples/apig/bind_signature.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env python3
# 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.
"""
Bind Signature to API
"""
import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')

attrs = {
"sign_id": "sign_id",
"publish_ids": ["publish_id"]
}
bind = conn.apig.bind_signature(
gateway="gateway_id",
**attrs
)
24 changes: 24 additions & 0 deletions examples/apig/list_bound_apis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env python3
# 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.
"""
List APIs Bound with a Signature Key
"""
import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')

apis = list(conn.apig.bound_apis(
gateway="gateway_id",
sign_id="sign_id"
))
24 changes: 24 additions & 0 deletions examples/apig/list_bound_signatures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env python3
# 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.
"""
List Signature Keys Bound to an API
"""
import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')

signs = list(conn.apig.bound_signatures(
gateway="gateway_id",
api_id="api_id"
))
23 changes: 23 additions & 0 deletions examples/apig/list_not_bound_apis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python3
# 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.
"""
List APIs Not Bound with a Signature Key
"""
import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
apis = list(conn.apig.not_bound_apis(
gateway="gateway_id",
sign_id="sign_id"
))
24 changes: 24 additions & 0 deletions examples/apig/unbind_signature.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env python3
# 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.
"""
Unbind Signature from API
"""
import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')

conn.apig.unbind_signature(
gateway="gateway_id",
bind="binding_id"
)
90 changes: 90 additions & 0 deletions otcextensions/sdk/apig/v2/_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from otcextensions.sdk.apig.v2 import api as _api
from otcextensions.sdk.apig.v2 import api_supplements as _supp
from otcextensions.sdk.apig.v2 import signature as _sign
from otcextensions.sdk.apig.v2 import signature_binding as _sign_bind


class Proxy(proxy.Proxy):
Expand Down Expand Up @@ -981,3 +982,92 @@ def signatures(self, gateway, **attrs):
gateway_id=gateway.id,
**attrs
)

# ======== Signature Binding Methods ========

def bind_signature(self, gateway, **attrs):
"""Bind a Signature for a specific API.
:param gateway: The ID of the gateway or an instance of
:class:`~otcextensions.sdk.apig.v2.gateway.Gateway`
:param attrs: Additional attributes for the Signature bind.
:returns: An instance of SignatureBind
"""
gateway = self._get_resource(_gateway.Gateway, gateway)
return self._create(
_sign_bind.SignatureBind,
gateway_id=gateway.id,
**attrs)

def unbind_signature(self, gateway, bind, ignore_missing=False):
"""Unbind a bound Signature from a specific API.
:param gateway: The ID of the gateway or an instance of
:class:`~otcextensions.sdk.apig.v2.gateway.Gateway`
:param bind: The ID of the SignatureBind or an instance
of SignatureBind
:returns: None
"""
gateway = self._get_resource(_gateway.Gateway, gateway)
bind = self._get_resource(_sign_bind.SignatureBind, bind)
return self._delete(
_sign_bind.SignatureBind,
bind,
gateway_id=gateway.id,
ignore_missing=ignore_missing
)

def bound_signatures(self, gateway, **query):
"""List all Signatures bound a specific API.
:param gateway: The ID of the gateway or an instance of
:class:`~otcextensions.sdk.apig.v2.gateway.Gateway`
:param query: Additional filters for listing SignatureBind.
:returns: A list of instances of SignatureBind
"""
gateway = self._get_resource(_gateway.Gateway, gateway)
bp = '/apigw/instances/%(gateway_id)s/sign-bindings/binded-signs'
return self._list(
_sign_bind.SignatureBind,
paginated=False,
gateway_id=gateway.id,
base_path=bp,
**query
)

def not_bound_apis(self, gateway, **query):
"""List all APIs to which a signature key has not been bound.
:param gateway: The ID of the gateway or an instance of
:class:`~otcextensions.sdk.apig.v2.gateway.Gateway`
:param query: Additional filters for listing NotBoundApi.
:returns: A list of instances of NotBoundApi
"""
gateway = self._get_resource(_gateway.Gateway, gateway)
return self._list(
_sign_bind.NotBoundApi,
paginated=False,
gateway_id=gateway.id,
**query
)

def bound_apis(self, gateway, **query):
"""List all APIs to which a signature key has been bound.
:param gateway: The ID of the gateway or an instance of
:class:`~otcextensions.sdk.apig.v2.gateway.Gateway`
:param query: Additional filters for listing BoundApi.
:returns: A list of instances of BoundApi
"""
gateway = self._get_resource(_gateway.Gateway, gateway)
return self._list(
_sign_bind.BoundApi,
paginated=False,
gateway_id=gateway.id,
**query
)
Loading

0 comments on commit 5fff171

Please sign in to comment.