Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ mod tests {
use crate::identity::{MockIdentityProvider, types::*};
use crate::provider::Provider;
use crate::resource::{MockResourceProvider, types::Project};

#[tokio::test]
#[traced_test]
async fn test_revoke_success() {
Expand Down
2 changes: 1 addition & 1 deletion crates/keystone/src/assignment/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ pub trait AssignmentBackend: Send + Sync {
async fn revoke_grant(
&self,
state: &ServiceState,
params: Assignment,
params: &Assignment,
) -> Result<(), AssignmentProviderError>;
}
2 changes: 1 addition & 1 deletion crates/keystone/src/assignment/backend/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl AssignmentBackend for SqlBackend {
async fn revoke_grant(
&self,
state: &ServiceState,
grant: Assignment,
grant: &Assignment,
) -> Result<(), AssignmentProviderError> {
Ok(assignment::delete(&state.db, grant).await?)
}
Expand Down
16 changes: 8 additions & 8 deletions crates/keystone/src/assignment/backend/sql/assignment/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::error::DbContextExt;
/// Delete assignment grant.
pub async fn delete(
db: &DatabaseConnection,
grant: Assignment,
grant: &Assignment,
) -> Result<(), AssignmentDatabaseError> {
let rows_affected = match &grant.r#type {
AssignmentType::GroupDomain
Expand Down Expand Up @@ -96,7 +96,7 @@ mod tests {
implied_via: None,
};

delete(&db, grant).await.unwrap();
delete(&db, &grant).await.unwrap();

// Update expected SQL to match delete_by_id order
assert_eq!(
Expand Down Expand Up @@ -134,7 +134,7 @@ mod tests {
implied_via: None,
};

delete(&db, grant).await.unwrap();
delete(&db, &grant).await.unwrap();

assert_eq!(
db.into_transaction_log(),
Expand Down Expand Up @@ -171,7 +171,7 @@ mod tests {
implied_via: None,
};

delete(&db, grant).await.unwrap();
delete(&db, &grant).await.unwrap();

assert_eq!(
db.into_transaction_log(),
Expand Down Expand Up @@ -208,7 +208,7 @@ mod tests {
implied_via: None,
};

delete(&db, grant).await.unwrap();
delete(&db, &grant).await.unwrap();

assert_eq!(
db.into_transaction_log(),
Expand Down Expand Up @@ -245,7 +245,7 @@ mod tests {
implied_via: None,
};

delete(&db, grant).await.unwrap();
delete(&db, &grant).await.unwrap();

assert_eq!(
db.into_transaction_log(),
Expand Down Expand Up @@ -282,7 +282,7 @@ mod tests {
implied_via: None,
};

delete(&db, grant).await.unwrap();
delete(&db, &grant).await.unwrap();

assert_eq!(
db.into_transaction_log(),
Expand Down Expand Up @@ -319,7 +319,7 @@ mod tests {
implied_via: None,
};

let result = delete(&db, grant).await;
let result = delete(&db, &grant).await;

assert!(result.is_err());

Expand Down
8 changes: 8 additions & 0 deletions crates/keystone/src/assignment/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use thiserror::Error;
use crate::assignment::backend::error::*;
use crate::identity::error::IdentityProviderError;
use crate::resource::error::ResourceProviderError;
use crate::revoke::error::RevokeProviderError;

/// Assignment provider error.
#[derive(Error, Debug)]
Expand Down Expand Up @@ -47,6 +48,13 @@ pub enum AssignmentProviderError {
source: ResourceProviderError,
},

/// Revoke provider error.
#[error(transparent)]
RevokeProvider {
#[from]
source: RevokeProviderError,
},

/// Role not found.
#[error("role {0} not found")]
RoleNotFound(String),
Expand Down
49 changes: 48 additions & 1 deletion crates/keystone/src/assignment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ use crate::identity::IdentityApi;
use crate::keystone::ServiceState;
use crate::plugin_manager::PluginManager;
use crate::resource::ResourceApi;
use crate::revoke::{RevokeApi, types::RevocationEventCreate};

#[cfg(test)]
pub use mock::MockAssignmentProvider;
Expand Down Expand Up @@ -238,6 +239,52 @@ impl AssignmentApi for AssignmentProvider {
state: &ServiceState,
grant: Assignment,
) -> Result<(), AssignmentProviderError> {
self.backend_driver.revoke_grant(state, grant).await
// Call backend with reference (no move)
self.backend_driver.revoke_grant(state, &grant).await?;

// Determine user_id or group_id
let user_id = match &grant.r#type {
AssignmentType::UserDomain
| AssignmentType::UserProject
| AssignmentType::UserSystem => Some(grant.actor_id.clone()),

AssignmentType::GroupDomain
| AssignmentType::GroupProject
| AssignmentType::GroupSystem => None,
};

// Determine project_id or domain_id
let (project_id, domain_id) = match &grant.r#type {
AssignmentType::UserProject | AssignmentType::GroupProject => {
(Some(grant.target_id.clone()), None)
}
AssignmentType::UserDomain | AssignmentType::GroupDomain => {
(None, Some(grant.target_id.clone()))
}
AssignmentType::UserSystem | AssignmentType::GroupSystem => (None, None),
};

let revocation_event = RevocationEventCreate {
domain_id,
project_id,
user_id,
role_id: Some(grant.role_id.clone()),
trust_id: None,
consumer_id: None,
access_token_id: None,
issued_before: chrono::Utc::now(),
expires_at: None,
audit_id: None,
audit_chain_id: None,
revoked_at: chrono::Utc::now(),
};

state
.provider
.get_revoke_provider()
.create_revocation_event(state, revocation_event)
.await?;

Ok(())
}
}