Unvendor identity user schema

User schema in keystone is now good enough. Drop the hardcode.
Change-Id: I718906b0c9c12fd4c7936bdb5047725fa3267b39
Signed-off-by: Artem Goncharov <artem.goncharov@gmail.com>
This commit is contained in:
Artem Goncharov
2025年05月28日 10:24:32 +02:00
parent eb390639ab
commit 52bfb4e619

View File

@@ -105,7 +105,7 @@ def _get_schema_ref(
ref = "#/components/schemas/Group"
elif name == "GroupsUsersGetResponse":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**user.USERS_SCHEMA)
name, TypeSchema(**identity_schema.user_index_response_body)
)
ref = f"#/components/schemas/{name}"
elif name in [

View File

@@ -14,109 +14,9 @@ from typing import Any
from keystone.identity import schema as identity_schema
from codegenerator.common.schema import ParameterSchema
from codegenerator.common.schema import TypeSchema
USER_LIST_PARAMETERS: dict[str, Any] = {
"users_domain_id": {
"in": "query",
"name": "domain_id",
"description": "Filters the response by a domain ID.",
"schema": {"type": "string", "format": "uuid"},
},
"users_enabled": {
"in": "query",
"name": "enabled",
"description": "If set to true, then only enabled projects will be returned. Any value other than 0 (including no value) will be interpreted as true.",
"schema": {"type": "boolean"},
},
"users_idp_id": {
"in": "query",
"name": "idp_id",
"description": "Filters the response by IDP ID.",
"schema": {"type": "string", "format": "uuid"},
},
"users_name": {
"in": "query",
"name": "name",
"description": "Filters the response by a resource name.",
"schema": {"type": "string"},
},
"users_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"},
},
"users_protocol_id": {
"in": "query",
"name": "protocol_id",
"description": "Filters the response by a protocol ID.",
"schema": {"type": "string", "format": "uuid"},
},
"users_unique_id": {
"in": "query",
"name": "unique_id",
"description": "Filters the response by a unique ID.",
"schema": {"type": "string", "format": "uuid"},
},
}
USER_SCHEMA: dict[str, Any] = {
"type": "object",
"properties": {
"id": {"type": "string", "format": "uuid", "readOnly": True},
**identity_schema._user_properties,
},
}
USER_CREATE_SCHEMA: dict[str, Any] = {
"type": "object",
"properties": {
"user": {
"type": "object",
"properties": {
"password": {"type": ["string", "null"]},
**identity_schema._user_properties,
},
"required": ["name"],
"additionalProperties": True,
}
},
"required": ["user"],
"additionalProperties": False,
}
USER_PATCH_SCHEMA: dict[str, Any] = {
"type": "object",
"properties": {
"user": {
"type": "object",
"properties": {
"password": {"type": ["string", "null"]},
**identity_schema._user_properties,
},
"minProperties": 1,
"additionalProperties": True,
}
},
"required": ["user"],
"additionalProperties": False,
}
USER_CONTAINER_SCHEMA: dict[str, Any] = {
"type": "object",
"properties": {"user": USER_SCHEMA},
}
USERS_SCHEMA: dict[str, Any] = {
"type": "object",
"properties": {"users": {"type": "array", "items": USER_SCHEMA}},
}
USER_PWD_CHANGE_SCHEMA: dict[str, Any] = {
"type": "object",
"properties": {"user": identity_schema.password_change},
@@ -206,49 +106,13 @@ USER_PROJECTS_SCHEMA: dict[str, Any] = {
}
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:get":
for key, val in USER_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
# Users
if name == "UserPatchRequest":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**USER_PATCH_SCHEMA)
)
ref = f"#/components/schemas/{name}"
elif name == "UsersPostRequest":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**USER_CREATE_SCHEMA)
)
ref = f"#/components/schemas/{name}"
elif name == "UsersGetResponse":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**USERS_SCHEMA)
)
ref = f"#/components/schemas/{name}"
elif name in ["UserGetResponse", "UserPostResponse", "UserPatchResponse"]:
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**USER_CONTAINER_SCHEMA)
)
ref = f"#/components/schemas/{name}"
elif name == "UsersPasswordPostRequest":
if name == "UsersPasswordPostRequest":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**USER_PWD_CHANGE_SCHEMA)
)
Reference in New Issue
openstack/codegenerator
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.

The note is not visible to the blocked user.