Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #25 from gtema/dev
Browse files Browse the repository at this point in the history
chore: further modularize identity schemas
  • Loading branch information
gtema authored Feb 28, 2024
2 parents 8d11ec0 + 8be8096 commit 71dd5af
Show file tree
Hide file tree
Showing 12 changed files with 942 additions and 758 deletions.
772 changes: 30 additions & 742 deletions codegenerator/openapi/keystone.py

Large diffs are not rendered by default.

77 changes: 76 additions & 1 deletion codegenerator/openapi/keystone_schemas/application_credential.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
schema as application_credential_schema,
)

from . import common
from codegenerator.common.schema import TypeSchema
from codegenerator.common.schema import ParameterSchema
from codegenerator.openapi.keystone_schemas import common

# Application Credentials
APPLICATION_CREDENTIAL_ACCESS_RULES_SCHEMA: dict[str, Any] = {
Expand Down Expand Up @@ -106,3 +108,76 @@
"schema": {"type": "string"},
},
}


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 == "users/user_id/application_credentials:get":
for (
key,
val,
) in APPLICATION_CREDENTIALS_LIST_PARAMETERS.items():
openapi_spec.components.parameters.setdefault(
key, ParameterSchema(**val)
)
ref = f"#/components/parameters/{key}"
if ref not in [x.ref for x in operation_spec.parameters]:
operation_spec.parameters.append(ParameterSchema(ref=ref))


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
# ### Application Credentials
if name == "UsersAccess_RuleGetResponse":
openapi_spec.components.schemas.setdefault(
name,
TypeSchema(**APPLICATION_CREDENTIAL_ACCESS_RULE_SCHEMA),
)
ref = f"#/components/schemas/{name}"
elif name == "UsersAccess_RulesGetResponse":
openapi_spec.components.schemas.setdefault(
name,
TypeSchema(**APPLICATION_CREDENTIAL_ACCESS_RULES_SCHEMA),
)
ref = f"#/components/schemas/{name}"
elif name == "UsersApplication_CredentialsGetResponse":
openapi_spec.components.schemas.setdefault(
name,
TypeSchema(**APPLICATION_CREDENTIALS_SCHEMA),
)
ref = f"#/components/schemas/{name}"
elif name in [
"UsersApplication_CredentialGetResponse",
]:
openapi_spec.components.schemas.setdefault(
name,
TypeSchema(**APPLICATION_CREDENTIAL_CONTAINER_SCHEMA),
)
ref = f"#/components/schemas/{name}"
elif name == "UsersApplication_CredentialsPostRequest":
openapi_spec.components.schemas.setdefault(
name,
TypeSchema(**APPLICATION_CREDENTIAL_CREATE_SCHEMA),
)
ref = f"#/components/schemas/{name}"
elif name in "UsersApplication_CredentialsPostResponse":
openapi_spec.components.schemas.setdefault(
name,
TypeSchema(**APPLICATION_CREDENTIAL_CREATE_RESPONSE_SCHEMA),
)
ref = f"#/components/schemas/{name}"

else:
return (None, None, False)

return (ref, mime_type, True)
85 changes: 84 additions & 1 deletion codegenerator/openapi/keystone_schemas/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

from typing import Any

from . import common
from codegenerator.common.schema import TypeSchema
from codegenerator.openapi.keystone_schemas import common


SCOPE_SCHEMA: dict[str, Any] = {
Expand Down Expand Up @@ -549,3 +550,85 @@
},
},
}


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 == "auth/tokens:post":
(receipt_schema_ref, receipt_mime_type, matched) = _get_schema_ref(
openapi_spec, "AuthReceiptSchema"
)
operation_spec.responses["401"] = {
"description": "Unauthorized",
"headers": {
"Openstack-Auth-Receipt": {
"$ref": "#/components/headers/Openstack-Auth-Receipt"
}
},
"content": {
receipt_mime_type: {"schema": {"$ref": receipt_schema_ref}}
},
}


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

# Auth
if name == "AuthTokensPostRequest":
openapi_spec.components.schemas.setdefault(
name,
TypeSchema(**AUTH_TOKEN_ISSUE_SCHEMA),
)
ref = f"#/components/schemas/{name}"
elif name in ["AuthTokensGetResponse", "AuthTokensPostResponse"]:
openapi_spec.components.schemas.setdefault(
name,
TypeSchema(**AUTH_SCOPED_TOKEN_SCHEMA),
)
ref = f"#/components/schemas/{name}"
elif name == "AuthReceiptSchema":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**AUTH_RECEIPT_SCHEMA)
)
ref = f"#/components/schemas/{name}"
elif name in [
"AuthProjectsGetResponse",
]:
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**AUTH_PROJECTS_SCHEMA)
)
ref = f"#/components/schemas/{name}"
elif name in [
"AuthDomainsGetResponse",
]:
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**AUTH_DOMAINS_SCHEMA)
)
ref = f"#/components/schemas/{name}"
elif name == "AuthSystemGetResponse":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**AUTH_SYSTEMS_SCHEMA)
)
ref = f"#/components/schemas/{name}"
elif name == "AuthCatalogGetResponse":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**AUTH_CATALOG_SCHEMA)
)
ref = f"#/components/schemas/{name}"

else:
return (None, None, False)

return (ref, mime_type, True)
84 changes: 84 additions & 0 deletions codegenerator/openapi/keystone_schemas/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

from keystone.resource import schema as ks_schema

from codegenerator.common.schema import TypeSchema


DOMAIN_SCHEMA: dict[str, Any] = {
"type": "object",
"properties": {
Expand Down Expand Up @@ -79,3 +82,84 @@
DOMAIN_CONFIG_GROUP_LDAP,
]
}


def _post_process_operation_hook(
openapi_spec, operation_spec, path: str | None = None
):
"""Hook to allow service specific generator to modify details"""
pass


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
# Domains
if name == "DomainsPostRequest":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**ks_schema.domain_create)
)
ref = f"#/components/schemas/{name}"
elif name == "DomainsPostResponse":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**DOMAIN_SCHEMA)
)
ref = f"#/components/schemas/{name}"
elif name == "DomainPatchRequest":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**ks_schema.domain_update)
)
ref = f"#/components/schemas/{name}"
elif name == "DomainPatchResponse":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**DOMAIN_SCHEMA)
)
ref = f"#/components/schemas/{name}"
elif name == "DomainsGetResponse":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**DOMAINS_SCHEMA)
)
ref = f"#/components/schemas/{name}"
elif name == "DomainGetResponse":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**DOMAIN_SCHEMA)
)
ref = f"#/components/schemas/{name}"
# Domain Config
elif name in [
"DomainsConfigDefaultGetResponse",
"DomainsConfigPutRequest",
"DomainsConfigPutResponse",
"DomainsConfigPatchResponse",
"DomainsConfigPatchResponse",
"DomainsConfigDefaultGetResponse",
]:
openapi_spec.components.schemas.setdefault(
name,
TypeSchema(**DOMAIN_CONFIGS_SCHEMA),
)
ref = f"#/components/schemas/{name}"
elif name in [
"DomainsConfigGroupGetResponse",
"DomainsConfigGroupPatchRequest",
"DomainsConfigGroupPatchResponse",
"DomainsConfigGroupPatchResponse",
"DomainsConfigGroupPatchResponse",
"DomainsConfigDefaultGroupGetResponse",
]:
openapi_spec.components.schemas.setdefault(
name,
TypeSchema(**DOMAIN_CONFIG_SCHEMA),
)
ref = f"#/components/schemas/{name}"

else:
return (None, None, False)

return (ref, mime_type, True)
72 changes: 69 additions & 3 deletions codegenerator/openapi/keystone_schemas/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

from typing import Any

from codegenerator.common.schema import TypeSchema
from codegenerator.common.schema import ParameterSchema

ENDPOINT_SCHEMA: dict[str, Any] = {
"type": "object",
"properties": {
Expand All @@ -29,17 +32,17 @@
"interface": {
"type": "string",
"enum": ["internal", "admin", "public"],
"description": "The interface type, which describes the visibility of the endpoint. Value is: - public. Visible by end users on a publicly available network interface. - internal. Visible by end users on an unmetered internal network interface. - admin. Visible by administrative users on a secure network interface.",
"description": "The interface type, which describes the visibility of the Value is: - public. Visible by end users on a publicly available network interface. - internal. Visible by end users on an unmetered internal network interface. - admin. Visible by administrative users on a secure network interface.",
},
"region": {
"type": "string",
"description": "The geographic location of the service endpoint.",
"description": "The geographic location of the service ",
"x-openstack": {"max-ver": "3.2"},
},
"region_id": {
"type": "string",
"format": "uuid",
"description": "The geographic location of the service endpoint.",
"description": "The geographic location of the service ",
"x-openstack": {"min-ver": "3.2"},
},
"service_id": {
Expand Down Expand Up @@ -99,3 +102,66 @@
ENDPOINT_CONTAINER_SCHEMA
)
ENDPOINT_UPDATE_SCHEMA["properties"]["endpoint"]["properties"].pop("id")


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 == "endpoints:get":
for (
key,
val,
) in ENDPOINTS_LIST_PARAMETERS.items():
openapi_spec.components.parameters.setdefault(
key, ParameterSchema(**val)
)
ref = f"#/components/parameters/{key}"
if ref not in [x.ref for x in operation_spec.parameters]:
operation_spec.parameters.append(ParameterSchema(ref=ref))


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
# ### Endpoints
if name == "EndpointsGetResponse":
openapi_spec.components.schemas.setdefault(
name,
TypeSchema(**ENDPOINTS_SCHEMA),
)
ref = f"#/components/schemas/{name}"
elif name in [
"EndpointGetResponse",
"EndpointsPostResponse",
"EndpointPatchResponse",
]:
openapi_spec.components.schemas.setdefault(
name,
TypeSchema(**ENDPOINT_CONTAINER_SCHEMA),
)
ref = f"#/components/schemas/{name}"
elif name == "EndpointsPostRequest":
openapi_spec.components.schemas.setdefault(
name,
TypeSchema(**ENDPOINT_CREATE_SCHEMA),
)
ref = f"#/components/schemas/{name}"
elif name == "EndpointsPostRequest":
openapi_spec.components.schemas.setdefault(
name,
TypeSchema(**ENDPOINT_UPDATE_SCHEMA),
)
ref = f"#/components/schemas/{name}"

else:
return (None, None, False)

return (ref, mime_type, True)
Loading

0 comments on commit 71dd5af

Please sign in to comment.