Extend user path param with --current-user
Recently support of `--user-id|--user-name` has been added when user_id is a path parameter of the resource. To make it even more smoother extend it with `--user-id <ID>|--user-name <NAME>|--current-user` to allow using current authenticated user while being very explicit (ensure user precisely decides what is desired. Change-Id: I0261140572e76799ea54dc0c9544cf5d094c1120
This commit is contained in:
parent
89c07638cf
commit
ca4120cddd
codegenerator
@ -1037,6 +1037,7 @@ class RustCliGenerator(BaseGenerator):
|
|||||||
global_additional_imports.add(
|
global_additional_imports.add(
|
||||||
f"openstack_sdk::api::{'::'.join(link_res_name.split('/'))}::find as find_{link_res_name.split('/')[-1]}"
|
f"openstack_sdk::api::{'::'.join(link_res_name.split('/'))}::find as find_{link_res_name.split('/')[-1]}"
|
||||||
)
|
)
|
||||||
|
global_additional_imports.add("eyre::OptionExt")
|
||||||
|
|
||||||
# List of operation variants (based on the body)
|
# List of operation variants (based on the body)
|
||||||
operation_variants = common.get_operation_variants(spec, args.operation_name)
|
operation_variants = common.get_operation_variants(spec, args.operation_name)
|
||||||
|
@ -31,6 +31,11 @@ struct {{ res_name | title }}Input {
|
|||||||
/// {{ res_name | title }} ID.
|
/// {{ res_name | title }} ID.
|
||||||
#[arg(long, help_heading = "Path parameters", value_name = "{{ res_name | upper }}_ID")]
|
#[arg(long, help_heading = "Path parameters", value_name = "{{ res_name | upper }}_ID")]
|
||||||
{{ res_name }}_id: Option<String>,
|
{{ res_name }}_id: Option<String>,
|
||||||
|
{%- if res_name == "user" %}
|
||||||
|
/// Current authenticated user.
|
||||||
|
#[arg(long, help_heading = "Path parameters", action = clap::ArgAction::SetTrue)]
|
||||||
|
current_user: bool,
|
||||||
|
{%- endif %}
|
||||||
}
|
}
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
@ -418,6 +418,18 @@ Some({{ val }})
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
{%- if res_name == "user" and v.remote_name == "user_id" %}
|
||||||
|
else if self.path.{{ res_name }}.current_{{ res_name }} {
|
||||||
|
{{ builder }}.{{ v.remote_name }}(
|
||||||
|
client
|
||||||
|
.get_auth_info()
|
||||||
|
.ok_or_eyre("Cannot determine current authentication information")?
|
||||||
|
.token
|
||||||
|
.user
|
||||||
|
.id,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
{%- endif %}
|
||||||
{%- else %}
|
{%- else %}
|
||||||
{%- if not v.is_required %}
|
{%- if not v.is_required %}
|
||||||
{%- if k != "project_id" %}
|
{%- if k != "project_id" %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user