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
2 changes: 1 addition & 1 deletion src/api/v3/auth/token/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ mod tests {
});
let mut assignment_mock = MockAssignmentProvider::default();
assignment_mock.expect_list_role_assignments().returning(
|_, _, q: &RoleAssignmentListParameters| {
|_, q: &RoleAssignmentListParameters| {
Ok(vec![Assignment {
role_id: "rid".into(),
role_name: Some("role_name".into()),
Expand Down
10 changes: 5 additions & 5 deletions src/api/v3/auth/token/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ mod tests {
let mut catalog_mock = MockCatalogProvider::default();
assignment_mock
.expect_list_role_assignments()
.returning(|_, _, _| Ok(Vec::new()));
.returning(|_, _| Ok(Vec::new()));

let mut identity_mock = MockIdentityProvider::default();
identity_mock
Expand All @@ -844,15 +844,15 @@ mod tests {
let mut resource_mock = MockResourceProvider::default();
resource_mock
.expect_get_project()
.withf(|_: &DatabaseConnection, id: &'_ str| id == "pid")
.withf(|_, id: &'_ str| id == "pid")
.returning(move |_, _| Ok(Some(project.clone())));
resource_mock
.expect_get_domain()
.withf(|_: &DatabaseConnection, id: &'_ str| id == "user_domain_id")
.withf(|_, id: &'_ str| id == "user_domain_id")
.returning(move |_, _| Ok(Some(user_domain.clone())));
resource_mock
.expect_get_domain()
.withf(|_: &DatabaseConnection, id: &'_ str| id == "pdid")
.withf(|_, id: &'_ str| id == "pdid")
.returning(move |_, _| Ok(Some(project_domain.clone())));
let mut token_mock = MockTokenProvider::default();
token_mock.expect_issue_token().returning(|_, _, _| {
Expand Down Expand Up @@ -995,7 +995,7 @@ mod tests {
let mut resource_mock = MockResourceProvider::default();
resource_mock
.expect_get_project()
.withf(|_: &DatabaseConnection, id: &'_ str| id == "pid")
.withf(|_, id: &'_ str| id == "pid")
.returning(move |_, _| {
Ok(Some(Project {
id: "pid".into(),
Expand Down
12 changes: 6 additions & 6 deletions src/api/v3/role/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async fn list(
let roles: Vec<Role> = state
.provider
.get_assignment_provider()
.list_roles(&state.db, &query.into())
.list_roles(&state, &query.into())
.await
.map_err(KeystoneApiError::assignment)?
.into_iter()
Expand Down Expand Up @@ -83,7 +83,7 @@ async fn show(
state
.provider
.get_assignment_provider()
.get_role(&state.db, &role_id)
.get_role(&state, &role_id)
.await
.map(|x| {
x.ok_or_else(|| KeystoneApiError::NotFound {
Expand Down Expand Up @@ -166,7 +166,7 @@ mod tests {
let mut assignment_mock = MockAssignmentProvider::default();
assignment_mock
.expect_list_roles()
.withf(|_: &DatabaseConnection, _: &RoleListParameters| true)
.withf(|_, _: &RoleListParameters| true)
.returning(|_, _| {
Ok(vec![Role {
id: "1".into(),
Expand Down Expand Up @@ -215,7 +215,7 @@ mod tests {
let mut assignment_mock = MockAssignmentProvider::default();
assignment_mock
.expect_list_roles()
.withf(|_: &DatabaseConnection, qp: &RoleListParameters| {
.withf(|_, qp: &RoleListParameters| {
RoleListParameters {
domain_id: Some("domain".into()),
name: Some("name".into()),
Expand Down Expand Up @@ -269,12 +269,12 @@ mod tests {
let mut assignment_mock = MockAssignmentProvider::default();
assignment_mock
.expect_get_role()
.withf(|_: &DatabaseConnection, id: &'_ str| id == "foo")
.withf(|_, id: &'_ str| id == "foo")
.returning(|_, _| Ok(None));

assignment_mock
.expect_get_role()
.withf(|_: &DatabaseConnection, id: &'_ str| id == "bar")
.withf(|_, id: &'_ str| id == "bar")
.returning(|_, _| {
Ok(Some(Role {
id: "bar".into(),
Expand Down
18 changes: 9 additions & 9 deletions src/api/v3/role_assignment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async fn list(
let assignments: Result<Vec<Assignment>, _> = state
.provider
.get_assignment_provider()
.list_role_assignments(&state.db, &state.provider, &query.try_into()?)
.list_role_assignments(&state, &query.try_into()?)
.await
.map_err(KeystoneApiError::assignment)?
.into_iter()
Expand Down Expand Up @@ -136,8 +136,8 @@ mod tests {
let mut assignment_mock = MockAssignmentProvider::default();
assignment_mock
.expect_list_role_assignments()
.withf(|_, _, _s| true)
.returning(|_, _, _| {
.withf(|_, _s| true)
.returning(|_, _| {
Ok(vec![Assignment {
role_id: "role".into(),
role_name: Some("rn".into()),
Expand Down Expand Up @@ -191,15 +191,15 @@ mod tests {
let mut assignment_mock = MockAssignmentProvider::default();
assignment_mock
.expect_list_role_assignments()
.withf(|_, _, qp: &RoleAssignmentListParameters| {
.withf(|_, qp: &RoleAssignmentListParameters| {
RoleAssignmentListParameters {
role_id: Some("role".into()),
user_id: Some("user1".into()),
project_id: Some("project1".into()),
..Default::default()
} == *qp
})
.returning(|_, _, _| {
.returning(|_, _| {
Ok(vec![Assignment {
role_id: "role".into(),
role_name: None,
Expand All @@ -212,15 +212,15 @@ mod tests {

assignment_mock
.expect_list_role_assignments()
.withf(|_, _, qp: &RoleAssignmentListParameters| {
.withf(|_, qp: &RoleAssignmentListParameters| {
RoleAssignmentListParameters {
role_id: Some("role".into()),
user_id: Some("user2".into()),
domain_id: Some("domain2".into()),
..Default::default()
} == *qp
})
.returning(|_, _, _| {
.returning(|_, _| {
Ok(vec![Assignment {
role_id: "role".into(),
role_name: None,
Expand All @@ -233,14 +233,14 @@ mod tests {

assignment_mock
.expect_list_role_assignments()
.withf(|_, _, qp: &RoleAssignmentListParameters| {
.withf(|_, qp: &RoleAssignmentListParameters| {
RoleAssignmentListParameters {
group_id: Some("group3".into()),
project_id: Some("project3".into()),
..Default::default()
} == *qp
})
.returning(|_, _, _| {
.returning(|_, _| {
Ok(vec![Assignment {
role_id: "role".into(),
role_name: None,
Expand Down
10 changes: 5 additions & 5 deletions src/api/v4/auth/token/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ mod tests {
let mut identity_mock = MockIdentityProvider::default();
identity_mock
.expect_get_user()
.withf(|_: &DatabaseConnection, id: &'_ str| id == "bar")
.withf(|_, id: &'_ str| id == "bar")
.returning(|_, _| {
Ok(Some(UserResponse {
id: "bar".into(),
Expand All @@ -229,7 +229,7 @@ mod tests {
let mut resource_mock = MockResourceProvider::default();
resource_mock
.expect_get_domain()
.withf(|_: &DatabaseConnection, id: &'_ str| id == "user_domain_id")
.withf(|_, id: &'_ str| id == "user_domain_id")
.returning(|_, _| {
Ok(Some(Domain {
id: "user_domain_id".into(),
Expand Down Expand Up @@ -272,7 +272,7 @@ mod tests {
let mut identity_mock = MockIdentityProvider::default();
identity_mock
.expect_get_user()
.withf(|_: &DatabaseConnection, id: &'_ str| id == "bar")
.withf(|_, id: &'_ str| id == "bar")
.returning(|_, _| {
Ok(Some(UserResponse {
id: "bar".into(),
Expand Down Expand Up @@ -331,7 +331,7 @@ mod tests {
let mut identity_mock = MockIdentityProvider::default();
identity_mock
.expect_get_user()
.withf(|_: &DatabaseConnection, id: &'_ str| id == "bar")
.withf(|_, id: &'_ str| id == "bar")
.returning(|_, _| {
Ok(Some(UserResponse {
id: "bar".into(),
Expand Down Expand Up @@ -360,7 +360,7 @@ mod tests {
});
let mut assignment_mock = MockAssignmentProvider::default();
assignment_mock.expect_list_role_assignments().returning(
|_, _, q: &RoleAssignmentListParameters| {
|_, q: &RoleAssignmentListParameters| {
Ok(vec![Assignment {
role_id: "rid".into(),
role_name: Some("role_name".into()),
Expand Down
2 changes: 1 addition & 1 deletion src/api/v4/auth/token/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ mod tests {
let mut catalog_mock = MockCatalogProvider::default();
assignment_mock
.expect_list_role_assignments()
.returning(|_, _, _| Ok(Vec::new()));
.returning(|_, _| Ok(Vec::new()));

let mut identity_mock = MockIdentityProvider::default();
identity_mock
Expand Down
62 changes: 28 additions & 34 deletions src/api/v4/role_assignment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ mod tests {
let mut assignment_mock = MockAssignmentProvider::default();
assignment_mock
.expect_list_role_assignments()
.withf(|_: &DatabaseConnection, _: &Provider, _: &RoleAssignmentListParameters| true)
.returning(|_, _, _| {
.withf(|_, _: &RoleAssignmentListParameters| true)
.returning(|_, _| {
Ok(vec![Assignment {
role_id: "role".into(),
role_name: Some("rn".into()),
Expand Down Expand Up @@ -146,17 +146,15 @@ mod tests {
let mut assignment_mock = MockAssignmentProvider::default();
assignment_mock
.expect_list_role_assignments()
.withf(
|_: &DatabaseConnection, _: &Provider, qp: &RoleAssignmentListParameters| {
RoleAssignmentListParameters {
role_id: Some("role".into()),
user_id: Some("user1".into()),
project_id: Some("project1".into()),
..Default::default()
} == *qp
},
)
.returning(|_, _, _| {
.withf(|_, qp: &RoleAssignmentListParameters| {
RoleAssignmentListParameters {
role_id: Some("role".into()),
user_id: Some("user1".into()),
project_id: Some("project1".into()),
..Default::default()
} == *qp
})
.returning(|_, _| {
Ok(vec![Assignment {
role_id: "role".into(),
role_name: None,
Expand All @@ -169,17 +167,15 @@ mod tests {

assignment_mock
.expect_list_role_assignments()
.withf(
|_: &DatabaseConnection, _: &Provider, qp: &RoleAssignmentListParameters| {
RoleAssignmentListParameters {
role_id: Some("role".into()),
user_id: Some("user2".into()),
domain_id: Some("domain2".into()),
..Default::default()
} == *qp
},
)
.returning(|_, _, _| {
.withf(|_, qp: &RoleAssignmentListParameters| {
RoleAssignmentListParameters {
role_id: Some("role".into()),
user_id: Some("user2".into()),
domain_id: Some("domain2".into()),
..Default::default()
} == *qp
})
.returning(|_, _| {
Ok(vec![Assignment {
role_id: "role".into(),
role_name: None,
Expand All @@ -192,16 +188,14 @@ mod tests {

assignment_mock
.expect_list_role_assignments()
.withf(
|_: &DatabaseConnection, _: &Provider, qp: &RoleAssignmentListParameters| {
RoleAssignmentListParameters {
group_id: Some("group3".into()),
project_id: Some("project3".into()),
..Default::default()
} == *qp
},
)
.returning(|_, _, _| {
.withf(|_, qp: &RoleAssignmentListParameters| {
RoleAssignmentListParameters {
group_id: Some("group3".into()),
project_id: Some("project3".into()),
..Default::default()
} == *qp
})
.returning(|_, _| {
Ok(vec![Assignment {
role_id: "role".into(),
role_name: None,
Expand Down
29 changes: 16 additions & 13 deletions src/assignment/backends/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
// SPDX-License-Identifier: Apache-2.0

use async_trait::async_trait;
use sea_orm::DatabaseConnection;

use super::super::types::*;
use crate::assignment::AssignmentProviderError;
use crate::config::Config;
use crate::keystone::ServiceState;

mod assignment;
mod implied_role;
Expand All @@ -38,42 +38,45 @@ impl AssignmentBackend for SqlBackend {
}

/// List roles
#[tracing::instrument(level = "debug", skip(self, db))]
#[tracing::instrument(level = "debug", skip(self, state))]
async fn list_roles(
&self,
db: &DatabaseConnection,
state: &ServiceState,
params: &RoleListParameters,
) -> Result<Vec<Role>, AssignmentProviderError> {
Ok(role::list(&self.config, db, params).await?)
Ok(role::list(&self.config, &state.db, params).await?)
}

/// Get single role by ID
#[tracing::instrument(level = "debug", skip(self, db))]
#[tracing::instrument(level = "debug", skip(self, state))]
async fn get_role<'a>(
&self,
db: &DatabaseConnection,
state: &ServiceState,
id: &'a str,
) -> Result<Option<Role>, AssignmentProviderError> {
Ok(role::get(&self.config, db, id).await?)
Ok(role::get(&self.config, &state.db, id).await?)
}

/// List role assignments
#[tracing::instrument(level = "info", skip(self, db))]
#[tracing::instrument(level = "info", skip(self, state))]
async fn list_assignments(
&self,
db: &DatabaseConnection,
state: &ServiceState,
params: &RoleAssignmentListParameters,
) -> Result<Vec<Assignment>, AssignmentProviderError> {
Ok(assignment::list(&self.config, db, params).await?)
Ok(assignment::list(&self.config, &state.db, params).await?)
}

/// List role assignments for multiple actors/targets
#[tracing::instrument(level = "info", skip(self, db))]
#[tracing::instrument(level = "info", skip(self, state))]
async fn list_assignments_for_multiple_actors_and_targets(
&self,
db: &DatabaseConnection,
state: &ServiceState,
params: &RoleAssignmentListForMultipleActorTargetParameters,
) -> Result<Vec<Assignment>, AssignmentProviderError> {
Ok(assignment::list_for_multiple_actors_and_targets(&self.config, db, params).await?)
Ok(
assignment::list_for_multiple_actors_and_targets(&self.config, &state.db, params)
.await?,
)
}
}
Loading
Loading