Merge "Hardcode barbican secret_store schemas"
This commit is contained in:
commit
f1e54465b9
@ -21,6 +21,7 @@ from codegenerator.common.schema import SpecSchema
|
||||
from codegenerator.openapi.base import OpenStackServerSourceBase
|
||||
from codegenerator.openapi.utils import merge_api_ref_doc
|
||||
from codegenerator.openapi.barbican_schemas import secret
|
||||
from codegenerator.openapi.barbican_schemas import secret_store
|
||||
|
||||
from ruamel.yaml.scalarstring import LiteralScalarString
|
||||
|
||||
@ -28,7 +29,7 @@ from ruamel.yaml.scalarstring import LiteralScalarString
|
||||
class BarbicanGenerator(OpenStackServerSourceBase):
|
||||
URL_TAG_MAP = {}
|
||||
|
||||
RESOURCE_MODULES = [secret]
|
||||
RESOURCE_MODULES = [secret, secret_store]
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
@ -324,13 +325,6 @@ class BarbicanGenerator(OpenStackServerSourceBase):
|
||||
conditions={"method": ["DELETE"]},
|
||||
)
|
||||
# Secret stores
|
||||
mapper.connect(
|
||||
None,
|
||||
"/v1/secret-stores/{secret_store_id}",
|
||||
controller=secretstores.SecretStoreController.on_get,
|
||||
action="get",
|
||||
conditions={"method": ["GET"]},
|
||||
)
|
||||
mapper.connect(
|
||||
None,
|
||||
"/v1/secret-stores/{secret_store_id}/preferred",
|
||||
@ -342,8 +336,8 @@ class BarbicanGenerator(OpenStackServerSourceBase):
|
||||
None,
|
||||
"/v1/secret-stores/{secret_store_id}/preferred",
|
||||
controller=secretstores.PreferredSecretStoreController.on_post,
|
||||
action="get",
|
||||
conditions={"method": ["GET"]},
|
||||
action="set",
|
||||
conditions={"method": ["POST"]},
|
||||
)
|
||||
|
||||
# Containers
|
||||
|
101
codegenerator/openapi/barbican_schemas/secret_store.py
Normal file
101
codegenerator/openapi/barbican_schemas/secret_store.py
Normal file
@ -0,0 +1,101 @@
|
||||
# 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 typing import Any
|
||||
|
||||
from codegenerator.common.schema import ParameterSchema
|
||||
from codegenerator.common.schema import TypeSchema
|
||||
|
||||
SECRET_STORE_SCHEMA: dict[str, Any] = {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"created": {
|
||||
"type": "string",
|
||||
"format": "date-time",
|
||||
"description": "Date and time secret store was created",
|
||||
},
|
||||
"crypto_plugin": {"type": ["string", "null"]},
|
||||
"global_default": {
|
||||
"type": "boolean",
|
||||
"description": "flag indicating if this secret store is global default or not",
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "store and crypto plugin name delimited by ‘+’ (plus) sign",
|
||||
},
|
||||
"secret_store_ref": {
|
||||
"type": "string",
|
||||
"description": "URL for referencing a specific secret store",
|
||||
},
|
||||
"updated": {
|
||||
"type": ["string", "null"],
|
||||
"format": "date-time",
|
||||
"description": "Date and time secret store was last updated",
|
||||
},
|
||||
},
|
||||
"required": ["name", "secret_store_ref"],
|
||||
"additionalProperties": False,
|
||||
}
|
||||
|
||||
SECRET_STORE_LIST_SCHEMA: dict[str, Any] = {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"secret_stores": {
|
||||
"type": "array",
|
||||
"items": SECRET_STORE_SCHEMA,
|
||||
"description": "A list of secret store references",
|
||||
}
|
||||
},
|
||||
"required": ["secret_stores"],
|
||||
"additionalProperties": False,
|
||||
}
|
||||
|
||||
|
||||
def _post_process_operation_hook(
|
||||
openapi_spec, operation_spec, path: str | None = None
|
||||
):
|
||||
"""Hook to allow service specific generator to modify details"""
|
||||
|
||||
operationId = operation_spec.operationId
|
||||
if operationId == "secret-stores/secret_store_id/preferred:post":
|
||||
operation_spec.requestBody = None
|
||||
operation_spec.responses = {"204": {"description": "ok"}}
|
||||
|
||||
|
||||
def _get_schema_ref(
|
||||
openapi_spec, name, description=None, schema_def=None, action_name=None
|
||||
) -> tuple[str | None, str | None, bool]:
|
||||
mime_type: str = "application/json"
|
||||
ref: str
|
||||
if name == "Secret_StoresListResponse":
|
||||
openapi_spec.components.schemas.setdefault(
|
||||
name, TypeSchema(**SECRET_STORE_LIST_SCHEMA)
|
||||
)
|
||||
ref = f"#/components/schemas/{name}"
|
||||
elif name in [
|
||||
"Secret_StoreShowResponse",
|
||||
"Secret_StoresPreferredResponse",
|
||||
"Secret_StoresGlobal_DefaultResponse",
|
||||
]:
|
||||
openapi_spec.components.schemas.setdefault(
|
||||
name, TypeSchema(**SECRET_STORE_SCHEMA)
|
||||
)
|
||||
ref = f"#/components/schemas/{name}"
|
||||
elif name in [
|
||||
"Secret_StoresPreferredSetRequest",
|
||||
"Secret_StoresPreferredSetResponse",
|
||||
]:
|
||||
return (None, None, True)
|
||||
else:
|
||||
return (None, None, False)
|
||||
|
||||
return (ref, mime_type, True)
|
Loading…
x
Reference in New Issue
Block a user