Skip to content

Commit

Permalink
Merge pull request #37 from semtisem/feature/roles
Browse files Browse the repository at this point in the history
feature/roles
  • Loading branch information
unbekanntes-pferd authored Aug 30, 2024
2 parents b9bd7f1 + 013245b commit 68c3351
Show file tree
Hide file tree
Showing 13 changed files with 795 additions and 25 deletions.
5 changes: 5 additions & 0 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ pub const PROVISIONING_CUSTOMER_ATTRIBUTES: &str = "customerAttributes";
pub const PROVISIONING_CUSTOMER_USERS: &str = "users";
pub const PROVISIONING_TOKEN_HEADER: &str = "X-Sds-Service-Token";

// ROLES
pub const ROLES_BASE: &str = "roles";
pub const ROLES_GROUPS: &str = "groups";
pub const ROLES_USERS: &str = "users";

// SETTINGS
pub const SETTINGS_BASE: &str = "settings";
pub const SETTINGS_KEYPAIR: &str = "keypair";
Expand Down
2 changes: 1 addition & 1 deletion src/groups/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
auth::{DracoonClient, DracoonErrorResponse},
models::{FilterOperator, FilterQuery, ObjectExpiration, RangedItems, SortOrder, SortQuery},
nodes::models::UserInfo,
user::models::RoleList,
roles::RoleList,
utils::{parse_body, FromResponse},
DracoonClientError,
};
Expand Down
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
//! * [Public] - for public information
//! * [PublicDownload] - for public download via share
//! * [PublicUpload] - for public upload via file request
//! * [Roles] - for role operations
//!
//! ### Example
//! ```no_run
Expand Down Expand Up @@ -434,6 +435,7 @@ use nodes::NodesEndpoint;
use provisioning::ProvisioningEndpoint;
use public::{PublicEndpoint, SystemInfo};
use reqwest::Url;
use roles::RolesEndpoint;
use settings::SettingsEndpoint;
use shares::SharesEndpoint;
use system::SystemEndpoint;
Expand All @@ -457,6 +459,7 @@ pub use self::{
nodes::{Download, Folders, MissingFileKeys, Nodes, Rooms, Upload},
provisioning::CustomerProvisioning,
public::{Public, PublicDownload, PublicUpload},
roles::Roles,
settings::RescueKeyPair,
shares::{DownloadShares, UploadShares},
system::AuthenticationMethods,
Expand All @@ -473,6 +476,7 @@ pub mod models;
pub mod nodes;
pub mod provisioning;
pub mod public;
pub mod roles;
pub mod settings;
pub mod shares;
pub mod system;
Expand Down Expand Up @@ -501,6 +505,7 @@ pub struct Dracoon<State = Disconnected> {
pub users: UsersEndpoint<State>,
pub public: PublicEndpoint<State>,
pub provisioning: ProvisioningEndpoint<State>,
pub roles: RolesEndpoint<State>,
}

impl<S: Send + Sync> GetClient<S> for Dracoon<S> {
Expand Down Expand Up @@ -616,6 +621,7 @@ impl DracoonBuilder {
let system_endpoint = SystemEndpoint::new(Arc::clone(&dracoon));
let nodes_endpoint = NodesEndpoint::new(Arc::clone(&dracoon));
let eventlog_endpoint = EventlogEndpoint::new(Arc::clone(&dracoon));
let roles_endpoint = RolesEndpoint::new(Arc::clone(&dracoon));

Ok(Dracoon {
client: dracoon,
Expand All @@ -635,6 +641,7 @@ impl DracoonBuilder {
system: system_endpoint,
users: users_endpoint,
groups: groups_endpoint,
roles: roles_endpoint,
})
}

Expand All @@ -653,6 +660,7 @@ impl DracoonBuilder {
let system_endpoint = SystemEndpoint::new(Arc::clone(&dracoon));
let nodes_endpoint = NodesEndpoint::new(Arc::clone(&dracoon));
let eventlog_endpoint = EventlogEndpoint::new(Arc::clone(&dracoon));
let roles_endpoint = RolesEndpoint::new(Arc::clone(&dracoon));

Ok(Dracoon {
client: dracoon,
Expand All @@ -672,6 +680,7 @@ impl DracoonBuilder {
system: system_endpoint,
users: users_endpoint,
groups: groups_endpoint,
roles: roles_endpoint,
})
}
}
Expand Down Expand Up @@ -699,6 +708,7 @@ impl Dracoon<Disconnected> {
let system_endpoint = SystemEndpoint::new(Arc::clone(&connected_client));
let nodes_endpoint = NodesEndpoint::new(Arc::clone(&connected_client));
let eventlog_endpoint = EventlogEndpoint::new(Arc::clone(&connected_client));
let roles_endpoint = RolesEndpoint::new(Arc::clone(&connected_client));

let mut dracoon = Dracoon {
client: connected_client,
Expand All @@ -712,6 +722,7 @@ impl Dracoon<Disconnected> {
user: user_endpoint,
public: public_endpoint,
provisioning: provisioning_endpoint,
roles: roles_endpoint,
nodes: nodes_endpoint,
shares: shares_endpoint,
settings: settings_endpoint,
Expand Down
173 changes: 173 additions & 0 deletions src/roles/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
use async_trait::async_trait;

mod models;
#[allow(clippy::module_inception)]
mod roles;

pub use models::*;

use crate::{models::ListAllParams, DracoonClientError};

#[async_trait]
pub trait Roles {
/// Get a list of all roles.
/// ```no_run
/// # use dco3::{Dracoon, auth::OAuth2Flow, Roles};
/// # #[tokio::main]
/// # async fn main() {
/// # let dracoon = Dracoon::builder()
/// # .with_base_url("https://dracoon.team")
/// # .with_client_id("client_id")
/// # .with_client_secret("client_secret")
/// # .build()
/// # .unwrap()
/// # .connect(OAuth2Flow::PasswordFlow("username".into(), "password".into()))
/// # .await
/// # .unwrap();
/// let roles = dracoon.roles.get_roles().await.unwrap();
/// # }
/// ```
async fn get_roles(&self) -> Result<RoleList, DracoonClientError>;
/// Get a list of all groups with a specific role.
/// ```no_run
/// # use dco3::{Dracoon, auth::OAuth2Flow, Roles, ListAllParams};
/// # #[tokio::main]
/// # async fn main() {
/// # let dracoon = Dracoon::builder()
/// # .with_base_url("https://dracoon.team")
/// # .with_client_id("client_id")
/// # .with_client_secret("client_secret")
/// # .build()
/// # .unwrap()
/// # .connect(OAuth2Flow::PasswordFlow("username".into(), "password".into()))
/// # .await
/// # .unwrap();
/// // Params are optional
/// let params = ListAllParams::builder()
/// .with_offset(0)
/// .with_limit(100)
/// .build();
/// let groups = dracoon.roles.get_all_groups_with_role(1, Some(params)).await.unwrap();
/// # }
/// ```
async fn get_all_groups_with_role(
&self,
role_id: u64,
params: Option<ListAllParams>,
) -> Result<RoleGroupList, DracoonClientError>;
/// Assign a role to a list of groups.
/// ```no_run
/// # use dco3::{Dracoon, auth::OAuth2Flow, Roles};
/// # #[tokio::main]
/// # async fn main() {
/// # let dracoon = Dracoon::builder()
/// # .with_base_url("https://dracoon.team")
/// # .with_client_id("client_id")
/// # .with_client_secret("client_secret")
/// # .build()
/// # .unwrap()
/// # .connect(OAuth2Flow::PasswordFlow("username".into(), "password".into()))
/// # .await
/// # .unwrap();
/// let groups = dracoon.roles.assign_role_to_groups(1, vec![1, 2, 3].into()).await.unwrap();
/// # }
/// ```
async fn assign_role_to_groups(
&self,
role_id: u64,
group_ids: AssignRoleBatchRequest,
) -> Result<RoleGroupList, DracoonClientError>;
/// Revoke a role from a list of groups.
/// ```no_run
/// # use dco3::{Dracoon, auth::OAuth2Flow, Roles};
/// # #[tokio::main]
/// # async fn main() {
/// # let dracoon = Dracoon::builder()
/// # .with_base_url("https://dracoon.team")
/// # .with_client_id("client_id")
/// # .with_client_secret("client_secret")
/// # .build()
/// # .unwrap()
/// # .connect(OAuth2Flow::PasswordFlow("username".into(), "password".into()))
/// # .await
/// # .unwrap();
/// let groups = dracoon.roles.revoke_role_from_groups(1, vec![1, 2, 3].into()).await.unwrap();
/// # }
/// ```
async fn revoke_role_from_groups(
&self,
role_id: u64,
group_ids: RevokeRoleBatchRequest,
) -> Result<RoleGroupList, DracoonClientError>;
/// Get a list of all users with a specific role.
/// ```no_run
/// # use dco3::{Dracoon, auth::OAuth2Flow, Roles, ListAllParams};
/// # #[tokio::main]
/// # async fn main() {
/// # let dracoon = Dracoon::builder()
/// # .with_base_url("https://dracoon.team")
/// # .with_client_id("client_id")
/// # .with_client_secret("client_secret")
/// # .build()
/// # .unwrap()
/// # .connect(OAuth2Flow::PasswordFlow("username".into(), "password".into()))
/// # .await
/// # .unwrap();
/// // Params are optional
/// let params = ListAllParams::builder()
/// .with_offset(0)
/// .with_limit(100)
/// .build();
/// let users = dracoon.roles.get_all_users_with_role(1, Some(params)).await.unwrap();
/// # }
/// ```
async fn get_all_users_with_role(
&self,
role_id: u64,
params: Option<ListAllParams>,
) -> Result<RoleUserList, DracoonClientError>;
/// Assign a role to a list of users.
/// ```no_run
/// # use dco3::{Dracoon, auth::OAuth2Flow, Roles};
/// # #[tokio::main]
/// # async fn main() {
/// # let dracoon = Dracoon::builder()
/// # .with_base_url("https://dracoon.team")
/// # .with_client_id("client_id")
/// # .with_client_secret("client_secret")
/// # .build()
/// # .unwrap()
/// # .connect(OAuth2Flow::PasswordFlow("username".into(), "password".into()))
/// # .await
/// # .unwrap();
/// let users = dracoon.roles.assign_role_to_users(1, vec![1, 2, 3].into()).await.unwrap();
/// # }
/// ```
async fn assign_role_to_users(
&self,
role_id: u64,
user_ids: AssignRoleBatchRequest,
) -> Result<RoleUserList, DracoonClientError>;
/// Revoke a role from a list of users.
/// ```no_run
/// # use dco3::{Dracoon, auth::OAuth2Flow, Roles};
/// # #[tokio::main]
/// # async fn main() {
/// # let dracoon = Dracoon::builder()
/// # .with_base_url("https://dracoon.team")
/// # .with_client_id("client_id")
/// # .with_client_secret("client_secret")
/// # .build()
/// # .unwrap()
/// # .connect(OAuth2Flow::PasswordFlow("username".into(), "password".into()))
/// # .await
/// # .unwrap();
/// let users = dracoon.roles.revoke_role_from_users(1, vec![1, 2, 3].into()).await.unwrap();
/// # }
/// ```
async fn revoke_role_from_users(
&self,
role_id: u64,
user_ids: RevokeRoleBatchRequest,
) -> Result<RoleUserList, DracoonClientError>;
}
Loading

0 comments on commit 68c3351

Please sign in to comment.