Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/api/v3/auth/token/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ pub(super) async fn get_authz_info(
return Err(KeystoneApiError::Unauthorized(None));
}
}
Some(Scope::System(_scope)) => {
todo!()
}
Some(Scope::System(_scope)) => AuthzInfo::System,
None => AuthzInfo::Unscoped,
};
authz_info.validate()?;
Expand Down
44 changes: 24 additions & 20 deletions src/api/v3/auth/token/token_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use crate::api::common;
use crate::api::error::KeystoneApiError;
use crate::api::v3::auth::token::types::{Token, TokenBuilder, UserBuilder};
use crate::api::v3::auth::token::types::{System, Token, TokenBuilder, UserBuilder};
use crate::api::v3::role::types::Role;
use crate::identity::IdentityApi;
use crate::keystone::ServiceState;
Expand All @@ -38,6 +38,7 @@ impl Token {
response.audit_ids(token.audit_ids().clone());
response.methods(token.methods().clone());
response.expires_at(*token.expires_at());
response.issued_at(*token.issued_at());

let user = if let Some(user) = token.user() {
user
Expand Down Expand Up @@ -75,15 +76,7 @@ impl Token {
}

match token {
ProviderToken::Unscoped(_token) => {}
ProviderToken::DomainScope(token) => {
if domain.is_none() {
domain = Some(
common::get_domain(state, Some(&token.domain_id), None::<&str>).await?,
);
}
}
ProviderToken::ProjectScope(token) => {
ProviderToken::ApplicationCredential(token) => {
if project.is_none() {
project = Some(
state
Expand All @@ -98,7 +91,22 @@ impl Token {
);
}
}
ProviderToken::ApplicationCredential(token) => {
ProviderToken::DomainScope(token) => {
if domain.is_none() {
domain = Some(
common::get_domain(state, Some(&token.domain_id), None::<&str>).await?,
);
}
}
ProviderToken::FederationUnscoped(_token) => {}
ProviderToken::FederationDomainScope(token) => {
if domain.is_none() {
domain = Some(
common::get_domain(state, Some(&token.domain_id), None::<&str>).await?,
);
}
}
ProviderToken::FederationProjectScope(token) => {
if project.is_none() {
project = Some(
state
Expand All @@ -113,15 +121,7 @@ impl Token {
);
}
}
ProviderToken::FederationUnscoped(_token) => {}
ProviderToken::FederationDomainScope(token) => {
if domain.is_none() {
domain = Some(
common::get_domain(state, Some(&token.domain_id), None::<&str>).await?,
);
}
}
ProviderToken::FederationProjectScope(token) => {
ProviderToken::ProjectScope(token) => {
if project.is_none() {
project = Some(
state
Expand Down Expand Up @@ -151,6 +151,9 @@ impl Token {
);
}
}
ProviderToken::SystemScope(_token) => {
response.system(System { all: true });
}
ProviderToken::Trust(token) => {
if project.is_none() {
project = Some(
Expand Down Expand Up @@ -182,6 +185,7 @@ impl Token {
);
}
}
ProviderToken::Unscoped(_token) => {}
}

if let Some(domain) = domain {
Expand Down
18 changes: 18 additions & 0 deletions src/api/v3/auth/token/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ pub struct Token {
/// The date and time when the token expires.
pub expires_at: DateTime<Utc>,

/// The date and time when the token was issued.
pub issued_at: DateTime<Utc>,

// # Subject
/// A user object.
//#[builder(default)]
Expand Down Expand Up @@ -98,6 +101,12 @@ pub struct Token {
#[validate(nested)]
pub roles: Option<Vec<Role>>,

/// A system object.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default)]
#[validate(nested)]
pub system: Option<System>,

/// A catalog object.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default)]
Expand Down Expand Up @@ -286,3 +295,12 @@ pub struct ValidateTokenParameters {
/// return a 404 exception.
pub allow_expired: Option<bool>,
}

/// System information.
#[derive(Builder, Clone, Debug, Default, Deserialize, PartialEq, Serialize, ToSchema, Validate)]
#[builder(build_fn(error = "BuilderError"))]
#[builder(setter(into, strip_option))]
pub struct System {
/// All
pub all: bool,
}
44 changes: 24 additions & 20 deletions src/api/v4/auth/token/token_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use crate::api::common;
use crate::api::error::KeystoneApiError;
use crate::api::v3::role::types::Role;
use crate::api::v4::auth::token::types::{Token, TokenBuilder, UserBuilder};
use crate::api::v4::auth::token::types::{System, Token, TokenBuilder, UserBuilder};
use crate::identity::IdentityApi;
use crate::keystone::ServiceState;
use crate::resource::{
Expand All @@ -37,6 +37,7 @@ impl Token {
response.audit_ids(token.audit_ids().clone());
response.methods(token.methods().clone());
response.expires_at(*token.expires_at());
response.issued_at(*token.issued_at());

let user = if let Some(user) = token.user() {
user
Expand Down Expand Up @@ -74,15 +75,7 @@ impl Token {
}

match token {
ProviderToken::Unscoped(_token) => {}
ProviderToken::DomainScope(token) => {
if domain.is_none() {
domain = Some(
common::get_domain(state, Some(&token.domain_id), None::<&str>).await?,
);
}
}
ProviderToken::ProjectScope(token) => {
ProviderToken::ApplicationCredential(token) => {
if project.is_none() {
project = Some(
state
Expand All @@ -97,7 +90,22 @@ impl Token {
);
}
}
ProviderToken::ApplicationCredential(token) => {
ProviderToken::DomainScope(token) => {
if domain.is_none() {
domain = Some(
common::get_domain(state, Some(&token.domain_id), None::<&str>).await?,
);
}
}
ProviderToken::FederationUnscoped(_token) => {}
ProviderToken::FederationDomainScope(token) => {
if domain.is_none() {
domain = Some(
common::get_domain(state, Some(&token.domain_id), None::<&str>).await?,
);
}
}
ProviderToken::FederationProjectScope(token) => {
if project.is_none() {
project = Some(
state
Expand All @@ -112,15 +120,7 @@ impl Token {
);
}
}
ProviderToken::FederationUnscoped(_token) => {}
ProviderToken::FederationDomainScope(token) => {
if domain.is_none() {
domain = Some(
common::get_domain(state, Some(&token.domain_id), None::<&str>).await?,
);
}
}
ProviderToken::FederationProjectScope(token) => {
ProviderToken::ProjectScope(token) => {
if project.is_none() {
project = Some(
state
Expand Down Expand Up @@ -150,6 +150,9 @@ impl Token {
);
}
}
ProviderToken::SystemScope(_token) => {
response.system(System { all: true });
}
ProviderToken::Trust(token) => {
if project.is_none() {
project = Some(
Expand All @@ -169,6 +172,7 @@ impl Token {
response.trust(trust);
}
}
ProviderToken::Unscoped(_token) => {}
}

if let Some(domain) = domain {
Expand Down
21 changes: 21 additions & 0 deletions src/api/v4/auth/token/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,16 @@ pub struct Token {
/// The date and time when the token expires.
pub expires_at: DateTime<Utc>,

/// The date and time when the token was issued.
pub issued_at: DateTime<Utc>,

// # Subject
/// A user object.
//#[builder(default)]
#[validate(nested)]
pub user: User,

// # Scope
/// A domain object including the id and name representing the domain the
/// token is scoped to. This is only included in tokens that are scoped
/// to a domain.
Expand All @@ -83,12 +88,19 @@ pub struct Token {
#[validate(nested)]
pub project: Option<Project>,

/// A system object.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default)]
#[validate(nested)]
pub system: Option<System>,

/// A trust object.
#[serde(skip_serializing_if = "Option::is_none", rename = "OS-TRUST:trust")]
#[builder(default)]
#[validate(nested)]
pub trust: Option<TokenTrustRepr>,

// # Roles on the scope.
/// A list of role objects
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default)]
Expand Down Expand Up @@ -275,3 +287,12 @@ pub struct ValidateTokenParameters {
/// return a 404 exception.
pub allow_expired: Option<bool>,
}

/// System information.
#[derive(Builder, Clone, Debug, Default, Deserialize, PartialEq, Serialize, ToSchema, Validate)]
#[builder(build_fn(error = "BuilderError"))]
#[builder(setter(into, strip_option))]
pub struct System {
/// All
pub all: bool,
}
2 changes: 1 addition & 1 deletion src/assignment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl AssignmentApi for AssignmentProvider {
r#type: RoleAssignmentTargetType::Domain,
inherited: Some(false),
});
} else if let Some(val) = &params.system {
} else if let Some(val) = &params.system_id {
targets.push(RoleAssignmentTarget {
id: val.clone(),
r#type: RoleAssignmentTargetType::System,
Expand Down
2 changes: 1 addition & 1 deletion src/assignment/types/assignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ pub struct RoleAssignmentListParameters {
/// Query role assignments on the system.
#[builder(default)]
#[validate(length(max = 64))]
pub system: Option<String>,
pub system_id: Option<String>,

// #[builder(default)]
// pub inherited: Option<bool>,
Expand Down
10 changes: 10 additions & 0 deletions src/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ pub enum AuthzInfo {
Domain(Domain),
/// Project scope.
Project(Project),
/// System scope.
System,
/// Trust scope.
Trust(Trust),
/// Unscoped.
Expand All @@ -180,6 +182,7 @@ impl AuthzInfo {
return Err(AuthenticationError::Unauthorized);
}
}
AuthzInfo::System => {}
AuthzInfo::Trust(_) => {}
AuthzInfo::Unscoped => {}
}
Expand Down Expand Up @@ -295,6 +298,13 @@ mod tests {
}
}

#[test]
#[traced_test]
fn test_authz_validate_system() {
let authz = AuthzInfo::System;
assert!(authz.validate().is_ok());
}

#[test]
#[traced_test]
fn test_authz_validate_unscoped() {
Expand Down
Loading
Loading