From 600d7aca5a6554b2856569925df9a01ce9a44463 Mon Sep 17 00:00:00 2001 From: Artem Goncharov Date: Fri, 26 Jul 2024 20:44:14 +0200 Subject: [PATCH] Drop anyhow in cli templates - drop anyhow in favor of eyre crate - fix few things in nova changed in the meanwhile Change-Id: I919cac5bf92e5279a4d840ddf0196e6daa74d869 --- codegenerator/openapi/base.py | 8 +- codegenerator/rust_cli.py | 2 +- codegenerator/templates/rust_cli/impl.rs.j2 | 2 - codegenerator/templates/rust_macros.j2 | 2 +- metadata/identity_metadata.yaml | 92 ++++++++++++++++----- 5 files changed, 80 insertions(+), 26 deletions(-) diff --git a/codegenerator/openapi/base.py b/codegenerator/openapi/base.py index f1cd292..75f8eb1 100644 --- a/codegenerator/openapi/base.py +++ b/codegenerator/openapi/base.py @@ -832,6 +832,9 @@ class OpenStackServerSourceBase: It is expected, that this method is invoked in the raising min_ver order to do proper cleanup of max_ver """ + if "type" not in obj: + # Nova has empty definitions for deprecated methods + return # Yey - we have query_parameters if obj["type"] == "object": params = obj["properties"] @@ -839,7 +842,10 @@ class OpenStackServerSourceBase: param_name = "_".join(path_resource_names) + f"_{prop}" param_attrs: dict[str, TypeSchema | dict] = {} - if spec["type"] == "array": + if spec == {}: + # Nova added empty params since it was never validating them. Skip + param_attrs["schema"] = TypeSchema(type="string") + elif spec["type"] == "array": param_attrs["schema"] = TypeSchema( **copy.deepcopy(spec["items"]) ) diff --git a/codegenerator/rust_cli.py b/codegenerator/rust_cli.py index faad196..2e94ba4 100644 --- a/codegenerator/rust_cli.py +++ b/codegenerator/rust_cli.py @@ -110,7 +110,7 @@ class JsonValue(common_rust.JsonValue): if self.original_data_type and isinstance( self.original_data_type, common_rust.Dictionary ): - imports.update(["std::collections::BTreeMap", "anyhow::Context"]) + imports.update(["std::collections::BTreeMap", "eyre::WrapErr"]) return imports diff --git a/codegenerator/templates/rust_cli/impl.rs.j2 b/codegenerator/templates/rust_cli/impl.rs.j2 index 93e0271..c61979f 100644 --- a/codegenerator/templates/rust_cli/impl.rs.j2 +++ b/codegenerator/templates/rust_cli/impl.rs.j2 @@ -25,8 +25,6 @@ use clap::Args; use serde::{Deserialize, Serialize}; use tracing::info; -use anyhow::Result; - use openstack_sdk::AsyncOpenStack; use crate::output::OutputProcessor; diff --git a/codegenerator/templates/rust_macros.j2 b/codegenerator/templates/rust_macros.j2 index 44976a2..5a9b1d2 100644 --- a/codegenerator/templates/rust_macros.j2 +++ b/codegenerator/templates/rust_macros.j2 @@ -169,7 +169,7 @@ Some({{ val }}) {%- elif original_type and original_type.__class__.__name__ == "DictionaryInput" and original_type.value_type and original_type.value_type.__class__.__name__ == "DictionaryInput" %} {{ dst_var }}.{{ param.remote_name }}( serde_json::from_value::>>({{ val_var | replace("&", "") }}.clone()) - .with_context(|| "Failed to parse `{{ param.local_name }}` as dict of dicts of {{ original_type.value_type.value_type.type_hint }}")? + .wrap_err_with(|| "Failed to parse `{{ param.local_name }}` as dict of dicts of {{ original_type.value_type.value_type.type_hint }}")? .into_iter() .map(|(k, v)| (k, v.into_iter())), ); diff --git a/metadata/identity_metadata.yaml b/metadata/identity_metadata.yaml index 0dde596..da4ea36 100644 --- a/metadata/identity_metadata.yaml +++ b/metadata/identity_metadata.yaml @@ -324,11 +324,31 @@ resources: api_version: v3 operations: check: - operation_id: credentials:head + operation_id: credentials/credential_id:head operation_type: get targets: rust-sdk: module_name: head + list: + operation_id: credentials:get + operation_type: list + targets: + rust-sdk: + module_name: list + rust-cli: + module_name: list + sdk_mod_name: list + cli_full_command: credential list + create: + operation_id: credentials:post + operation_type: create + targets: + rust-sdk: + module_name: create + rust-cli: + module_name: create + sdk_mod_name: create + cli_full_command: credential create show: operation_id: credentials/credential_id:get operation_type: show @@ -359,26 +379,6 @@ resources: module_name: set sdk_mod_name: set cli_full_command: credential set - list: - operation_id: credentials:get - operation_type: list - targets: - rust-sdk: - module_name: list - rust-cli: - module_name: list - sdk_mod_name: list - cli_full_command: credential list - create: - operation_id: credentials:post - operation_type: create - targets: - rust-sdk: - module_name: create - rust-cli: - module_name: create - sdk_mod_name: create - cli_full_command: credential create identity.domain: spec_file: wrk/openapi_specs/identity/v3.yaml api_version: v3 @@ -3110,6 +3110,56 @@ resources: module_name: list sdk_mod_name: list cli_full_command: user projects + identity.user/credential/OS_EC2: + spec_file: wrk/openapi_specs/identity/v3.yaml + api_version: v3 + operations: + check: + operation_id: users/user_id/credentials/OS-EC2/credential_id:head + operation_type: get + targets: + rust-sdk: + module_name: head + list: + operation_id: users/user_id/credentials/OS-EC2:get + operation_type: list + targets: + rust-sdk: + module_name: list + rust-cli: + module_name: list + sdk_mod_name: list + cli_full_command: user credential OS-EC2 list + create: + operation_id: users/user_id/credentials/OS-EC2:post + operation_type: create + targets: + rust-sdk: + module_name: create + rust-cli: + module_name: create + sdk_mod_name: create + cli_full_command: user credential OS-EC2 create + show: + operation_id: users/user_id/credentials/OS-EC2/credential_id:get + operation_type: show + targets: + rust-sdk: + module_name: get + rust-cli: + module_name: show + sdk_mod_name: get + cli_full_command: user credential OS-EC2 show + delete: + operation_id: users/user_id/credentials/OS-EC2/credential_id:delete + operation_type: delete + targets: + rust-sdk: + module_name: delete + rust-cli: + module_name: delete + sdk_mod_name: delete + cli_full_command: user credential OS-EC2 delete identity.user/OS_OAUTH1/access_token: spec_file: wrk/openapi_specs/identity/v3.yaml api_version: v3