Skip to content

Commit

Permalink
Merge pull request #91 from EventStore/brockshelton/clo-852-add-suppo…
Browse files Browse the repository at this point in the history
…rt-for-updating-member-details

add ability to enable and disable members of an org
  • Loading branch information
bshelton authored Apr 10, 2024
2 parents 25b3ab9 + 1ff4af5 commit 5fc034a
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,28 @@ You can display your current refresh token with:
```
esc access tokens display
```


### List members of an organization.

```
esc access members list
```

### Enable a member of an organization

```
esc access members update --id <member-id> --active true
```

### Disable a member of an organization

```
esc access members update --id <member-id> --active false
```

### Deletes a member from an organization

```
esc access members delete --id <member-id>
```
62 changes: 62 additions & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ enum GroupsCommand {
enum MembersCommand {
Get(GetMember),
List(ListMembers),
Update(UpdateMember),
Delete(DeleteMember),
}

#[derive(StructOpt, Debug)]
Expand All @@ -336,6 +338,34 @@ struct ListMembers {
org_id: OrgId,
}

#[derive(StructOpt, Debug)]
#[structopt(about = "Update a member")]
struct UpdateMember {
#[structopt(long, short, parse(try_from_str = parse_member_id), help = "The member id")]
id: MemberId,

#[structopt(long, short, parse(try_from_str = parse_org_id), default_value = "", help = "The organization id the member will relate to")]
org_id: OrgId,

#[structopt(
long,
short,
parse(try_from_str),
help = "Specifies whether the member is active."
)]
active: bool,
}

#[derive(StructOpt, Debug)]
#[structopt(about = "Deletes a Member")]
struct DeleteMember {
#[structopt(long, short, parse(try_from_str = parse_member_id))]
id: MemberId,

#[structopt(long, short, parse(try_from_str = parse_org_id), default_value = "")]
org_id: OrgId,
}

#[derive(StructOpt, Debug)]
enum UserCommand {
List,
Expand Down Expand Up @@ -749,6 +779,7 @@ enum OrganizationsCommand {
Get(GetOrganization),
Delete(DeleteOrganization),
List(ListOrganizations),
GetMfaStatus(GetOrganizationMfaStatus),
}

#[derive(Debug, StructOpt)]
Expand All @@ -775,6 +806,13 @@ struct GetOrganization {
id: OrgId,
}

#[derive(Debug, StructOpt)]
#[structopt(about = "read an organization's MFA status")]
struct GetOrganizationMfaStatus {
#[structopt(short, long, parse(try_from_str = parse_org_id), default_value = "", help = "The id of the organization you want to read MFA status of")]
id: OrgId,
}

#[derive(Debug, StructOpt)]
#[structopt(about = "Delete an organization")]
struct DeleteOrganization {
Expand Down Expand Up @@ -1953,6 +1991,24 @@ async fn call_api<'a, 'b>(
esc_api::access::get_member(&client, params.org_id, params.id).await?;
printer.print(resp)?;
}

MembersCommand::Update(params) => {
let client = client_builder.create().await?;
esc_api::access::update_member(
&client,
params.org_id,
params.id,
esc_api::access::UpdateMemberRequest {
active: params.active,
},
)
.await?;
}

MembersCommand::Delete(params) => {
let client = client_builder.create().await?;
esc_api::access::delete_member(&client, params.org_id, params.id).await?;
}
},
},

Expand Down Expand Up @@ -2339,6 +2395,12 @@ async fn call_api<'a, 'b>(
let resp = esc_api::resources::list_organizations(&client).await?;
printer.print(resp)?;
}

OrganizationsCommand::GetMfaStatus(params) => {
let client = client_builder.create().await?;
let resp = esc_api::resources::get_mfa_status(&client, params.id).await?;
printer.print(resp)?;
}
},

ResourcesCommand::Projects(projs) => match projs.projects_command {
Expand Down
10 changes: 10 additions & 0 deletions cli/src/v1/resources.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use chrono::{DateTime, Utc};
use esc_api::resources::MfaStatus;
use std::fmt::Formatter;

use super::common::{List, ToV1};
Expand Down Expand Up @@ -59,6 +60,15 @@ impl ToV1 for esc_api::resources::ListOrganizationsResponse {
}
}

impl ToV1 for esc_api::resources::MfaStatus {
type V1Type = MfaStatus;
fn to_v1(self) -> Self::V1Type {
MfaStatus {
mfa_enabled: self.mfa_enabled,
}
}
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Project {
Expand Down
35 changes: 35 additions & 0 deletions generated/src/resources/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ pub async fn delete_project(
.await
}

/// Gets the mfa status of an organization
///
/// # Arguments
///
/// * `organization_id` - The id of the organization
pub async fn get_mfa_status(client: &Client, organization_id: OrganizationId) -> Result<MfaStatus> {
let url = format!(
"/resources/v1/organizations/{organizationId}/mfa",
organizationId = urlencode(organization_id),
);
client
.send_request::<(), MfaStatus>(Method::GET, url, None, None)
.await
}

/// Gets a single organization by ID.
///
/// # Arguments
Expand Down Expand Up @@ -158,6 +173,26 @@ pub async fn list_projects(
.await
}

/// Changes the status of MFA for an organization
/// # Arguments
///
/// * `organization_id` - The id of the organization
/// * `mfa_status`
pub async fn update_mfa(
client: &Client,
organization_id: OrganizationId,
// The desired status of MFA
mfa_status: MfaStatus,
) -> Result<UpdateMfaResponse> {
let url = format!(
"/resources/v1/organizations/{organizationId}/mfa",
organizationId = urlencode(organization_id),
);
client
.send_request::<MfaStatus, UpdateMfaResponse>(Method::POST, url, Some(&mfa_status), None)
.await
}

/// Deletes an organization by ID.
///
/// # Arguments
Expand Down
12 changes: 12 additions & 0 deletions generated/src/resources/schemas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ pub struct ListProjectsResponse {
pub projects: Vec<Project>,
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MfaStatus {
pub mfa_enabled: bool,
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Organization {
Expand All @@ -71,6 +77,12 @@ pub struct Project {
pub organization_id: OrganizationId,
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct UpdateMfaResponse {
pub mfa_enabled: bool,
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct UpdateOrganizationRequest {
Expand Down

0 comments on commit 5fc034a

Please sign in to comment.