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 #26 from gtema/dev
Browse files Browse the repository at this point in the history
feat: extend identity.role coverage
  • Loading branch information
gtema authored Feb 29, 2024
2 parents 71dd5af + d34201a commit 3db1e5e
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 28 deletions.
8 changes: 8 additions & 0 deletions codegenerator/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,14 @@ def post_process_compute_operation(
def post_process_identity_operation(
resource_name: str, operation_name: str, operation
):
if resource_name == "role/imply":
if operation_name == "list":
operation.targets["rust-cli"].response_key = "role_inference"
operation.targets["rust-sdk"].response_key = "role_inference"
if resource_name == "role_inference":
if operation_name == "list":
operation.targets["rust-cli"].response_key = "role_inferences"
operation.targets["rust-sdk"].response_key = "role_inferences"
return operation


Expand Down
2 changes: 1 addition & 1 deletion codegenerator/openapi/cinder_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"type": "object",
"description": "Links to the resources in question. See [API Guide / Links and References](https://docs.openstack.org/api-guide/compute/links_and_references.html) for more info.",
"properties": {
"href": {"type": "string", "format": "url"},
"href": {"type": "string", "format": "uri"},
"rel": {"type": "string"},
},
}
Expand Down
2 changes: 1 addition & 1 deletion codegenerator/openapi/keystone_schemas/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@
},
"url": {
"type": "string",
"format": "url",
"format": "uri",
"description": "The endpoint url",
},
},
Expand Down
2 changes: 1 addition & 1 deletion codegenerator/openapi/keystone_schemas/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"type": "object",
"description": "Links to the resources in question. See [API Guide / Links and References](https://docs.openstack.org/api-guide/compute/links_and_references.html) for more info.",
"properties": {
"href": {"type": "string", "format": "url"},
"href": {"type": "string", "format": "uri"},
"rel": {"type": "string"},
},
}
Expand Down
2 changes: 1 addition & 1 deletion codegenerator/openapi/keystone_schemas/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"properties": {
"url": {
"type": "string",
"format": "url",
"format": "uri",
"description": "The LDAP URL.",
},
"user_tree_dn": {
Expand Down
4 changes: 2 additions & 2 deletions codegenerator/openapi/keystone_schemas/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
"region": {
"type": "string",
"description": "The geographic location of the service ",
"description": "The geographic location of the service endpoint.",
"x-openstack": {"max-ver": "3.2"},
},
"region_id": {
Expand All @@ -52,7 +52,7 @@
},
"url": {
"type": "string",
"format": "url",
"format": "uri",
"description": "The endpoint URL.",
},
},
Expand Down
4 changes: 2 additions & 2 deletions codegenerator/openapi/keystone_schemas/region.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
"id": {
"type": "string",
"format": "uuid",
"description": "The ID for the ",
"description": "The ID for the region.",
},
"parent_id": {
"type": "string",
"format": "uuid",
"description": "To make this region a child of another region, set this parameter to the ID of the parent ",
"description": "To make this region a child of another region, set this parameter to the ID of the parent region.",
},
},
}
Expand Down
89 changes: 76 additions & 13 deletions codegenerator/openapi/keystone_schemas/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"id": {
"type": "string",
"format": "uuid",
"description": "The role ID",
"description": "The role ID.",
},
"links": {"type": "object"},
**assignment_schema._role_properties,
Expand All @@ -37,11 +37,25 @@
"id": {
"type": "string",
"format": "uuid",
"description": "The role ID",
"description": "The role ID.",
},
"name": {
"type": "string",
"description": "The role name",
"description": "The role name.",
},
"description": {
"type": "string",
"description": "The role description.",
},
"links": {
"type": "object",
"properties": {
"self": {
"type": "string",
"format": "uri",
"description": "The link to the resource in question.",
}
},
},
},
}
Expand All @@ -55,15 +69,26 @@
},
}

# Role list specific query parameters
ROLE_LIST_PARAMETERS: dict[str, Any] = {
"role_domain_id": {
"in": "query",
"name": "domain_id",
"description": "Filters the response by a domain ID.",
"schema": {"type": "string", "format": "uuid"},
},
}


ROLE_INFERENCE_SCHEMA: dict[str, Any] = {
"type": "object",
"properties": {
"role_inference": {
"type": "object",
"properties": {
"prior_role": ROLE_SCHEMA,
"implies": ROLE_SCHEMA,
}
"prior_role": ROLE_INFO_SCHEMA,
"implies": ROLE_INFO_SCHEMA,
},
}
},
}
Expand All @@ -72,13 +97,33 @@
"type": "object",
"properties": {
"role_inference": {
"type": "object",
"properties": {
"prior_role": ROLE_SCHEMA,
"prior_role": ROLE_INFO_SCHEMA,
"implies": {
"type": "array",
"items": ROLE_SCHEMA,
"items": ROLE_INFO_SCHEMA,
},
}
},
}
},
}

ROLES_INFERENCES_SCHEMA: dict[str, Any] = {
"type": "object",
"properties": {
"role_inferences": {
"type": "array",
"items": {
"type": "object",
"properties": {
"prior_role": ROLE_INFO_SCHEMA,
"implies": {
"type": "array",
"items": ROLE_INFO_SCHEMA,
},
},
},
}
},
}
Expand Down Expand Up @@ -130,12 +175,12 @@
"properties": {
"assignment": {
"type": "string",
"format": "url",
"format": "uri",
"description": "a link to the assignment that gave rise to this entity",
},
"membership": {
"type": "string",
"format": "url",
"format": "uri",
},
},
},
Expand Down Expand Up @@ -224,7 +269,19 @@ def _post_process_operation_hook(
"""Hook to allow service specific generator to modify details"""
operationId = operation_spec.operationId

if operationId == "role_assignments:get":
if operationId == "roles:get":
for (
key,
val,
) in ROLE_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 == "role_assignments:get":
for map in [
ROLE_ASSIGNMENTS_QUERY_PARAMETERS,
ROLE_ASSIGNMENT_LIST_PARAMETERS,
Expand All @@ -240,7 +297,7 @@ def _post_process_operation_hook(

if ref not in [x.ref for x in operation_spec.parameters]:
operation_spec.parameters.append(ParameterSchema(ref=ref))
if operationId == "role_assignments:head":
elif operationId == "role_assignments:head":
for (
key,
val,
Expand Down Expand Up @@ -318,6 +375,12 @@ def _get_schema_ref(
name, TypeSchema(**ROLE_ASSIGNMENTS_SCHEMA)
)
ref = f"#/components/schemas/{name}"
# Role Inferences
elif name == "Role_InferencesGetResponse":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**ROLES_INFERENCES_SCHEMA)
)
ref = f"#/components/schemas/{name}"

# Project/Domain Roles
elif name == "ProjectsUsersRolesGetResponse":
Expand Down
4 changes: 2 additions & 2 deletions codegenerator/openapi/nova_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"type": "object",
"description": "Links to the resources in question. See [API Guide / Links and References](https://docs.openstack.org/api-guide/compute/links_and_references.html) for more info.",
"properties": {
"href": {"type": "string", "format": "url"},
"href": {"type": "string", "format": "uri"},
"rel": {"type": "string"},
},
}
Expand Down Expand Up @@ -477,7 +477,7 @@
},
"url": {
"type": "string",
"format": "url",
"format": "uri",
"description": "The URL is used to connect the console.",
},
},
Expand Down
14 changes: 9 additions & 5 deletions metadata/identity_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2294,15 +2294,17 @@ resources:
targets:
rust-sdk:
module_name: head
get:
list:
operation_id: role_inferences:get
operation_type: get
operation_type: list
targets:
rust-sdk:
module_name: get
module_name: list
response_key: role_inferences
rust-cli:
module_name: get
sdk_mod_name: get
module_name: list
sdk_mod_name: list
response_key: role_inferences
identity.role:
spec_file: wrk/openapi_specs/identity/v3.yaml
api_version: v3
Expand Down Expand Up @@ -2387,9 +2389,11 @@ resources:
targets:
rust-sdk:
module_name: list
response_key: role_inference
rust-cli:
module_name: list
sdk_mod_name: list
response_key: role_inference
show:
operation_id: roles/prior_role_id/implies/implied_role_id:get
operation_type: show
Expand Down
2 changes: 2 additions & 0 deletions tools/generate_rust_identity.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ NET_RESOURCES=(
"endpoint"
"region"
"role_assignment"
"role_inference"
"role"
)

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

0 comments on commit 3db1e5e

Please sign in to comment.