From 345e6bdaf0e2b03615d49722fda395bdcb5cb2d8 Mon Sep 17 00:00:00 2001 From: Artem Goncharov Date: Wed, 30 Oct 2024 18:28:57 +0100 Subject: [PATCH] Fix identity resource link code - fix project_id resource link in openapi - fix --current-domain --current-project filling Change-Id: Ide2a2ae7eed04f51317346370c50431bf9282550 --- codegenerator/openapi/keystone.py | 8 ++++++ codegenerator/rust_cli.py | 1 + codegenerator/templates/rust_macros.j2 | 34 ++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/codegenerator/openapi/keystone.py b/codegenerator/openapi/keystone.py index cbb77eb..64745f7 100644 --- a/codegenerator/openapi/keystone.py +++ b/codegenerator/openapi/keystone.py @@ -240,6 +240,14 @@ class KeystoneGenerator(OpenStackServerSourceBase): path_param.openstack["resource_link"] = ( "identity/v3/domain.id" ) + if path_param.name == "project_id" and path_resource_names != [ + "projects" + ]: + if not path_param.openstack: + path_param.openstack = {} + path_param.openstack["resource_link"] = ( + "identity/v3/project.id" + ) openapi_spec.components.parameters[global_param_name] = ( path_param ) diff --git a/codegenerator/rust_cli.py b/codegenerator/rust_cli.py index 12d2b74..c967df8 100644 --- a/codegenerator/rust_cli.py +++ b/codegenerator/rust_cli.py @@ -1079,6 +1079,7 @@ class RustCliGenerator(BaseGenerator): f"openstack_sdk::api::{'::'.join(link_res_name.split('/'))}::find as find_{link_res_name.split('/')[-1]}" ) global_additional_imports.add("eyre::OptionExt") + global_additional_imports.add("eyre::eyre") # List of operation variants (based on the body) operation_variants = common.get_operation_variants( diff --git a/codegenerator/templates/rust_macros.j2 b/codegenerator/templates/rust_macros.j2 index f184da4..e1fa861 100644 --- a/codegenerator/templates/rust_macros.j2 +++ b/codegenerator/templates/rust_macros.j2 @@ -420,6 +420,39 @@ Some({{ val }}) } {%- if v.remote_name in ["user_id", "project_id", "domain_id"] %} else if self.path.{{ res_name }}.current_{{ res_name }} { + {%- if v.remote_name == "domain_id" %} + let token = client + .get_auth_info() + .ok_or_eyre("Cannot determine current authentication information")? + .token; + if let Some(domain) = token.domain { + ep_builder.domain_id(domain.id.ok_or_eyre("Domain ID is missing in the auth")?); + } else if let Some(project) = token.project { + ep_builder.{{ v.remote_name }}( + project + .domain + .ok_or_eyre("Domain information is missing in the project auth info")? + .id + .ok_or_eyre("Domain ID is missing in the project.domain auth info")?, + ); + } else { + return Err(eyre!("Current domain information can not be identified").into()); + } + {%- elif v.remote_name == "project_id" %} + let token = client + .get_auth_info() + .ok_or_eyre("Cannot determine current authentication information")? + .token; + if let Some(project) = token.project { + ep_builder.{{ v.remote_name }}( + project + .id + .ok_or_eyre("Project ID is missing in the project auth info")?, + ); + } else { + return Err(eyre!("Current project information can not be identified").into()); + } + {%- elif v.remote_name == "user_id" %} {{ builder }}.{{ v.remote_name }}( client .get_auth_info() @@ -428,6 +461,7 @@ Some({{ val }}) .user .id, ); + {%- endif %} } {%- endif %} {%- else %}