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 #29 from gtema/dev
Browse files Browse the repository at this point in the history
feat: extend identity schemas
  • Loading branch information
gtema authored Feb 29, 2024
2 parents ac72dbe + c9f37cc commit c36ff28
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 25 deletions.
4 changes: 2 additions & 2 deletions codegenerator/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ def find_resource_schema(
try:
if "type" not in schema:
# Response of server create is a server or reservation_id
if "allOf" in schema:
if "oneOf" in schema:
kinds = {}
for kind in schema["allOf"]:
for kind in schema["oneOf"]:
kinds.update(kind)
schema["type"] = kinds["type"]
elif schema == {}:
Expand Down
89 changes: 70 additions & 19 deletions codegenerator/openapi/keystone_schemas/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,72 @@

from keystone.identity import schema as identity_schema

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


GROUP_SCHEMA: dict[str, Any] = {
"type": "object",
"properties": {
"id": {"type": "string", "format": "uuid"},
"id": {"type": "string", "format": "uuid", "readOnly": True},
**identity_schema._group_properties,
},
}

GROUP_CONTAINER_SCHEMA: dict[str, Any] = {
"type": "object",
"properties": {"group": GROUP_SCHEMA},
}

GROUPS_SCHEMA: dict[str, Any] = {
"type": "object",
"properties": {"groups": {"type": "array", "items": GROUP_SCHEMA}},
}

GROUPS_LIST_PARAMETERS: dict[str, Any] = {
"group_domain_id": {
"in": "query",
"name": "domain_id",
"description": "Filters the response by a domain ID.",
"schema": {"type": "string", "format": "uuid"},
},
}

GROUP_USERS_LIST_PARAMETERS: dict[str, Any] = {
"group_user_password_expires_at": {
"in": "query",
"name": "password_expires_at",
"description": "Filter results based on which user passwords have expired. The query should include an operator and a timestamp with a colon (:) separating the two, for example: `password_expires_at={operator}:{timestamp}`.\nValid operators are: `lt`, `lte`, `gt`, `gte`, `eq`, and `neq`.\nValid timestamps are of the form: YYYY-MM-DDTHH:mm:ssZ.",
"schema": {"type": "string", "format": "date-time"},
},
}


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 == "groups:get":
for key, val in GROUPS_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))

elif operationId == "groups/group_id/users:get":
for key, val in GROUP_USERS_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,
Expand All @@ -41,32 +91,33 @@ def _get_schema_ref(
mime_type: str = "application/json"
ref: str
# Groups
if name == "GroupPatchRequest":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**identity_schema.user_update)
)
ref = f"#/components/schemas/{name}"
elif name == "GroupsPostRequest":
if name == "GroupsGetResponse":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**identity_schema.user_create)
)
ref = f"#/components/schemas/{name}"
elif name == "GroupPatchResponse":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**GROUP_SCHEMA)
name, TypeSchema(**GROUPS_SCHEMA)
)
ref = f"#/components/schemas/{name}"
elif name == "GroupsGetResponse":
elif name in [
"GroupsPostRequest",
"GroupsPostResponse",
"GroupGetResponse",
"GroupPatchRequest",
"GroupPatchResponse",
]:
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**GROUPS_SCHEMA)
"Group", TypeSchema(**GROUP_CONTAINER_SCHEMA)
)
ref = f"#/components/schemas/{name}"
elif name == "GroupGetResponse":
ref = "#/components/schemas/Group"
elif name == "GroupsUsersGetResponse":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**GROUP_SCHEMA)
name, TypeSchema(**user.USERS_SCHEMA)
)
ref = f"#/components/schemas/{name}"

elif name in [
"GroupsUserGetResponse",
"GroupsUserPutRequest",
"GroupsUserPutResponse",
]:
return (None, None, True)
else:
return (None, None, False)

Expand Down
2 changes: 1 addition & 1 deletion codegenerator/openapi/keystone_schemas/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
USER_SCHEMA: dict[str, Any] = {
"type": "object",
"properties": {
"id": {"type": "string", "format": "uuid"},
"id": {"type": "string", "format": "uuid", "readOnly": True},
**identity_schema._user_properties,
},
}
Expand Down
7 changes: 4 additions & 3 deletions tools/generate_rust_identity.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ WRK_DIR=wrk
METADATA=metadata
DST=~/workspace/github/gtema/openstack
NET_RESOURCES=(
"project"
"auth"
"user"
"group"
"os_federation"
"service"
"endpoint"
"region"
"role_assignment"
"role_inference"
"role"
"service"
"project"
"user"
)

openstack-codegenerator --work-dir ${WRK_DIR} --target rust-sdk --metadata ${METADATA}/identity_metadata.yaml --service identity
Expand Down

0 comments on commit c36ff28

Please sign in to comment.