openstack_keystone_core/api/v4/
token_restriction.rs1use axum::{
16 Json,
17 http::StatusCode,
18 response::{IntoResponse, Response},
19};
20
21pub use openstack_keystone_api_types::v4::token_restriction::*;
22
23use crate::token::types::{
24 self as types, TokenRestriction as ProviderTokenRestriction,
25 TokenRestrictionCreate as ProviderTokenRestrictionCreate,
26 TokenRestrictionUpdate as ProviderTokenRestrictionUpdate,
27};
28
29impl From<TokenRestrictionListParameters> for types::TokenRestrictionListParameters {
30 fn from(value: TokenRestrictionListParameters) -> Self {
31 Self {
32 domain_id: value.domain_id,
33 user_id: value.user_id,
34 project_id: value.project_id,
35 }
36 }
37}
38
39impl From<ProviderTokenRestriction> for TokenRestriction {
40 fn from(value: ProviderTokenRestriction) -> Self {
41 Self {
42 allow_rescope: value.allow_rescope,
43 allow_renew: value.allow_renew,
44 id: value.id,
45 domain_id: value.domain_id,
46 project_id: value.project_id,
47 user_id: value.user_id,
48 roles: value
49 .roles
50 .map(|roles| roles.into_iter().map(Into::into).collect())
51 .unwrap_or_default(),
52 }
53 }
54}
55
56impl From<TokenRestrictionCreateRequest> for ProviderTokenRestrictionCreate {
57 fn from(value: TokenRestrictionCreateRequest) -> Self {
58 Self {
59 allow_rescope: value.restriction.allow_rescope,
60 allow_renew: value.restriction.allow_renew,
61 id: String::new(),
62 domain_id: value.restriction.domain_id,
63 project_id: value.restriction.project_id,
64 user_id: value.restriction.user_id,
65 role_ids: value
66 .restriction
67 .roles
68 .into_iter()
69 .map(|role| role.id)
70 .collect(),
71 }
72 }
73}
74
75impl From<TokenRestrictionUpdateRequest> for ProviderTokenRestrictionUpdate {
76 fn from(value: TokenRestrictionUpdateRequest) -> Self {
77 Self {
78 allow_rescope: value.restriction.allow_rescope,
79 allow_renew: value.restriction.allow_renew,
80 project_id: value.restriction.project_id,
81 user_id: value.restriction.user_id,
82 role_ids: value
83 .restriction
84 .roles
85 .map(|roles| roles.into_iter().map(|role| role.id).collect()),
86 }
87 }
88}
89
90impl IntoResponse for ProviderTokenRestriction {
101 fn into_response(self) -> Response {
102 (
103 StatusCode::OK,
104 Json(TokenRestrictionResponse {
105 restriction: TokenRestriction::from(self),
106 }),
107 )
108 .into_response()
109 }
110}