diff --git a/src/api/error.rs b/src/api/error.rs index 60713d0e..01a1b0f5 100644 --- a/src/api/error.rs +++ b/src/api/error.rs @@ -189,11 +189,6 @@ pub enum TokenError { #[from] source: crate::api::v3::auth::token::types::ProjectBuilderError, }, - #[error("error building token data: {}", source)] - TokenBuilder { - #[from] - source: crate::api::v3::types::TokenBuilderError, - }, } #[derive(Error, Debug)] diff --git a/src/api/v3/auth/token/types.rs b/src/api/v3/auth/token/types.rs index 17cc2031..0f542223 100644 --- a/src/api/v3/auth/token/types.rs +++ b/src/api/v3/auth/token/types.rs @@ -22,8 +22,10 @@ use derive_builder::Builder; use serde::{Deserialize, Serialize}; use utoipa::ToSchema; +use crate::api::error::TokenError; use crate::api::v3::role::types::Role; use crate::resource::types as resource_provider_types; +use crate::token::Token as BackendToken; /// Authorization token #[derive(Builder, Clone, Debug, Default, Deserialize, PartialEq, Serialize, ToSchema)] @@ -130,3 +132,16 @@ impl From for Domain { } } } + +impl TryFrom<&BackendToken> for Token { + type Error = TokenError; + + fn try_from(value: &BackendToken) -> Result { + let mut token = TokenBuilder::default(); + token.user(UserBuilder::default().id(value.user_id()).build()?); + token.methods(value.methods().clone()); + token.audit_ids(value.audit_ids().clone()); + token.expires_at(*value.expires_at()); + Ok(token.build()?) + } +} diff --git a/src/api/v3/mod.rs b/src/api/v3/mod.rs index 073d0e72..ea65b54e 100644 --- a/src/api/v3/mod.rs +++ b/src/api/v3/mod.rs @@ -20,7 +20,6 @@ pub mod auth; pub mod group; pub mod role; pub mod role_assignment; -pub mod types; pub mod user; pub(super) fn openapi_router() -> OpenApiRouter { diff --git a/src/api/v3/types.rs b/src/api/v3/types.rs deleted file mode 100644 index a7683589..00000000 --- a/src/api/v3/types.rs +++ /dev/null @@ -1,42 +0,0 @@ -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// SPDX-License-Identifier: Apache-2.0 - -use chrono::{DateTime, Utc}; -use derive_builder::Builder; -use serde::Serialize; - -use crate::api::error::TokenError; -use crate::token::Token as BackendToken; - -#[derive(Builder, Clone, Debug, Default, PartialEq, Serialize)] -pub struct Token { - pub user_id: String, - pub methods: Vec, - pub audit_ids: Vec, - pub expires_at: DateTime, -} - -impl TryFrom<&BackendToken> for Token { - type Error = TokenError; - fn try_from(value: &BackendToken) -> Result { - let mut token = TokenBuilder::default(); - if let BackendToken::Unscoped(data) = value { - token.user_id(data.user_id.clone()); - token.methods(data.methods.clone()); - token.audit_ids(data.audit_ids.clone()); - token.expires_at(data.expires_at); - } - Ok(token.build()?) - } -} diff --git a/src/api/v3/user/passkey/mod.rs b/src/api/v3/user/passkey/mod.rs index c75dfaec..71a7e3ef 100644 --- a/src/api/v3/user/passkey/mod.rs +++ b/src/api/v3/user/passkey/mod.rs @@ -25,7 +25,7 @@ use webauthn_rs::prelude::*; use crate::api::{ error::{KeystoneApiError, WebauthnError}, - v3::types::Token as ApiToken, + v3::auth::token::types::Token as ApiToken, }; use crate::identity::IdentityApi; use crate::keystone::ServiceState;