Skip to main content

openstack_keystone_core/api/v3/
group.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::group::*;
22
23use crate::identity::types;
24
25impl From<types::Group> for Group {
26    fn from(value: types::Group) -> 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<GroupCreateRequest> for types::GroupCreate {
38    fn from(value: GroupCreateRequest) -> Self {
39        let group = value.group;
40        Self {
41            id: None,
42            name: group.name,
43            domain_id: group.domain_id,
44            extra: group.extra,
45            description: group.description,
46        }
47    }
48}
49
50impl IntoResponse for types::Group {
51    fn into_response(self) -> Response {
52        (
53            StatusCode::OK,
54            Json(GroupResponse {
55                group: Group::from(self),
56            }),
57        )
58            .into_response()
59    }
60}
61
62impl From<GroupListParameters> for types::GroupListParameters {
63    fn from(value: GroupListParameters) -> Self {
64        Self {
65            domain_id: value.domain_id,
66            name: value.name,
67        }
68    }
69}