Skip to main content

openstack_keystone_core/api/v4/
auth.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
15pub use openstack_keystone_api_types::v4::auth::token::*;
16
17use crate::error::BuilderError;
18use crate::identity::types as identity_types;
19use crate::token::Token as BackendToken;
20
21impl TryFrom<UserPassword> for identity_types::UserPasswordAuthRequest {
22    type Error = BuilderError;
23
24    fn try_from(value: UserPassword) -> Result<Self, Self::Error> {
25        let mut upa = identity_types::UserPasswordAuthRequestBuilder::default();
26        if let Some(id) = &value.id {
27            upa.id(id);
28        }
29        if let Some(name) = &value.name {
30            upa.name(name);
31        }
32        if let Some(domain) = &value.domain {
33            let mut domain_builder = identity_types::DomainBuilder::default();
34            if let Some(id) = &domain.id {
35                domain_builder.id(id);
36            }
37            if let Some(name) = &domain.name {
38                domain_builder.name(name);
39            }
40            upa.domain(domain_builder.build()?);
41        }
42        upa.password(value.password.clone());
43        upa.build()
44    }
45}
46
47impl TryFrom<&BackendToken> for Token {
48    type Error = openstack_keystone_api_types::error::BuilderError;
49
50    fn try_from(value: &BackendToken) -> Result<Self, Self::Error> {
51        let mut token = TokenBuilder::default();
52        token.user(UserBuilder::default().id(value.user_id()).build()?);
53        token.methods(value.methods().clone());
54        token.audit_ids(value.audit_ids().clone());
55        token.expires_at(*value.expires_at());
56        token.build()
57    }
58}