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
12 changes: 8 additions & 4 deletions crates/core-types/src/assignment/assignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ pub struct RoleAssignmentListParameters {
#[validate(length(max = 64))]
pub role_id: Option<String>,

// Actors
/// Get role assignments for the user.
#[builder(default)]
#[validate(length(max = 64))]
Expand All @@ -235,14 +236,17 @@ pub struct RoleAssignmentListParameters {
#[validate(length(max = 64))]
pub group_id: Option<String>,

/// Query role assignments on the project.
#[builder(default)]
#[validate(length(max = 64))]
pub project_id: Option<String>,
// Targets
/// Query role assignments on the domain.
#[builder(default)]
#[validate(length(max = 64))]
pub domain_id: Option<String>,

/// Query role assignments on the project.
#[builder(default)]
#[validate(length(max = 64))]
pub project_id: Option<String>,

/// Query role assignments on the system.
#[builder(default)]
#[validate(length(max = 64))]
Expand Down
47 changes: 28 additions & 19 deletions crates/core-types/src/role/role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,28 @@ use crate::error::BuilderError;
#[builder(build_fn(error = "BuilderError"))]
#[builder(setter(strip_option, into))]
pub struct Role {
/// The role ID.
#[validate(length(min = 1, max = 64))]
pub id: String,
/// The role name.
/// The role description.
#[builder(default)]
#[validate(length(min = 1, max = 255))]
pub name: String,
pub description: Option<String>,

/// The role domain_id.
#[builder(default)]
#[validate(length(min = 1, max = 64))]
pub domain_id: Option<String>,
/// The role description.
#[builder(default)]
#[validate(length(min = 1, max = 255))]
pub description: Option<String>,

/// Additional role properties.
#[builder(default)]
#[serde(flatten)]
pub extra: HashMap<String, Value>,

/// The role ID.
#[validate(length(min = 1, max = 64))]
pub id: String,

/// The role name.
#[validate(length(min = 1, max = 255))]
pub name: String,
}

/// Short role representation (reference).
Expand Down Expand Up @@ -95,6 +99,7 @@ pub struct RoleListParameters {
#[builder(default)]
#[validate(length(min = 1, max = 64))]
pub domain_id: Option<Option<String>>,

/// Filter roles by the name attribute.
#[builder(default)]
#[validate(length(min = 1, max = 255))]
Expand All @@ -106,22 +111,26 @@ pub struct RoleListParameters {
#[builder(build_fn(error = "BuilderError"))]
#[builder(setter(strip_option, into))]
pub struct RoleCreate {
/// The role ID.
/// The role description.
#[builder(default)]
#[validate(length(min = 1, max = 64))]
pub id: Option<String>,
/// The role name.
#[validate(length(min = 1, max = 255))]
pub name: String,
#[validate(length(max = 255))]
pub description: Option<String>,

/// The role domain_id.
#[builder(default)]
#[validate(length(min = 1, max = 64))]
pub domain_id: Option<String>,
/// The role description.
#[builder(default)]
#[validate(length(max = 255))]
pub description: Option<String>,

/// Additional role properties.
#[builder(default)]
pub extra: HashMap<String, Value>,

/// The role ID.
#[builder(default)]
#[validate(length(min = 1, max = 64))]
pub id: Option<String>,

/// The role name.
#[validate(length(min = 1, max = 255))]
pub name: String,
}
22 changes: 11 additions & 11 deletions crates/core/src/role/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ pub trait RoleBackend: Send + Sync {
id: &'a str,
) -> Result<(), RoleProviderError>;

/// Expand implied roles.
///
/// # Arguments
/// * `state` - The current service state.
/// * `roles` - The list of roles to expand.
async fn expand_implied_roles(
&self,
state: &ServiceState,
roles: &mut Vec<RoleRef>,
) -> Result<(), RoleProviderError>;

/// Get single role by ID.
///
/// * `state` - The current service state.
Expand All @@ -58,17 +69,6 @@ pub trait RoleBackend: Send + Sync {
id: &'a str,
) -> Result<Option<Role>, RoleProviderError>;

/// Expand implied roles.
///
/// # Arguments
/// * `state` - The current service state.
/// * `roles` - The list of roles to expand.
async fn expand_implied_roles(
&self,
state: &ServiceState,
roles: &mut Vec<RoleRef>,
) -> Result<(), RoleProviderError>;

/// List role imply rules.
///
/// # Arguments
Expand Down
22 changes: 11 additions & 11 deletions crates/core/src/role/provider_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ pub trait RoleApi: Send + Sync {
id: &'a str,
) -> Result<(), RoleProviderError>;

/// Expand implied roles.
///
/// # Arguments
/// * `state` - The current service state.
/// * `roles` - The list of roles to expand.
async fn expand_implied_roles(
&self,
state: &ServiceState,
roles: &mut Vec<RoleRef>,
) -> Result<(), RoleProviderError>;

/// Get a single role.
///
/// * `state` - The current service state.
Expand All @@ -61,17 +72,6 @@ pub trait RoleApi: Send + Sync {
role_id: &'a str,
) -> Result<Option<Role>, RoleProviderError>;

/// Expand implied roles.
///
/// # Arguments
/// * `state` - The current service state.
/// * `roles` - The list of roles to expand.
async fn expand_implied_roles(
&self,
state: &ServiceState,
roles: &mut Vec<RoleRef>,
) -> Result<(), RoleProviderError>;

/// List role imply rules.
///
/// # Arguments
Expand Down
32 changes: 16 additions & 16 deletions crates/role-sql/src/implied_role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub async fn list_rules(
}

#[cfg(test)]
mod tests {
pub(crate) mod tests {
use sea_orm::{DatabaseBackend, MockDatabase, Transaction};

use crate::entity::implied_role;
Expand Down Expand Up @@ -144,31 +144,31 @@ mod tests {
);
}

fn get_implied_role_mock(id: String, implied_id: String) -> implied_role::Model {
pub fn get_implied_role_mock<S: Into<String>>(id: S, implied_id: S) -> implied_role::Model {
implied_role::Model {
prior_role_id: id.clone(),
implied_role_id: implied_id.clone(),
prior_role_id: id.into(),
implied_role_id: implied_id.into(),
}
}

#[tokio::test]
async fn test_list_rules() {
let db = MockDatabase::new(DatabaseBackend::Postgres)
.append_query_results([vec![
get_implied_role_mock("1".into(), "2".into()),
get_implied_role_mock("1".into(), "3".into()),
get_implied_role_mock("2".into(), "4".into()),
get_implied_role_mock("4".into(), "7".into()),
get_implied_role_mock("4".into(), "8".into()),
get_implied_role_mock("5".into(), "6".into()),
get_implied_role_mock("1", "2"),
get_implied_role_mock("1", "3"),
get_implied_role_mock("2", "4"),
get_implied_role_mock("4", "7"),
get_implied_role_mock("4", "8"),
get_implied_role_mock("5", "6"),
]])
.append_query_results([vec![
get_implied_role_mock("1".into(), "2".into()),
get_implied_role_mock("1".into(), "3".into()),
get_implied_role_mock("2".into(), "4".into()),
get_implied_role_mock("4".into(), "7".into()),
get_implied_role_mock("4".into(), "8".into()),
get_implied_role_mock("5".into(), "6".into()),
get_implied_role_mock("1", "2"),
get_implied_role_mock("1", "3"),
get_implied_role_mock("2", "4"),
get_implied_role_mock("4", "7"),
get_implied_role_mock("4", "8"),
get_implied_role_mock("5", "6"),
]])
.into_connection();
assert_eq!(
Expand Down
Loading
Loading