Skip to main content

openstack_keystone_core/api/v3/
role.rs

1// Licensed under the Apache License, Version 2.0 (the "License");
2// you may not use this file except in compliance with the License.
3// You may obtain a copy of the License at
4//
5//     http://www.apache.org/licenses/LICENSE-2.0
6//
7// Unless required by applicable law or agreed to in writing, software
8// distributed under the License is distributed on an "AS IS" BASIS,
9// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10// See the License for the specific language governing permissions and
11// limitations under the License.
12//
13// SPDX-License-Identifier: Apache-2.0
14
15use axum::{
16    Json,
17    http::StatusCode,
18    response::{IntoResponse, Response},
19};
20
21pub use openstack_keystone_api_types::v3::role::*;
22
23use crate::role::types;
24
25impl From<types::Role> for Role {
26    fn from(value: types::Role) -> Self {
27        Self {
28            id: value.id,
29            domain_id: value.domain_id,
30            name: value.name,
31            description: value.description,
32            extra: value.extra,
33        }
34    }
35}
36
37impl From<types::RoleRef> for RoleRef {
38    fn from(value: types::RoleRef) -> Self {
39        Self {
40            id: value.id,
41            domain_id: value.domain_id,
42            name: value.name.unwrap_or_default(),
43        }
44    }
45}
46
47impl IntoResponse for types::Role {
48    fn into_response(self) -> Response {
49        (
50            StatusCode::OK,
51            Json(RoleResponse {
52                role: Role::from(self),
53            }),
54        )
55            .into_response()
56    }
57}
58
59impl From<RoleListParameters> for types::RoleListParameters {
60    fn from(value: RoleListParameters) -> Self {
61        Self {
62            domain_id: Some(value.domain_id),
63            name: value.name,
64        }
65    }
66}
67
68impl From<RoleCreate> for types::RoleCreate {
69    fn from(value: RoleCreate) -> Self {
70        Self {
71            description: value.description,
72            domain_id: value.domain_id,
73            extra: value.extra,
74            id: None,
75            name: value.name,
76        }
77    }
78}