Skip to content

Commit 5fc034a

Browse files
authored
Merge pull request #91 from EventStore/brockshelton/clo-852-add-support-for-updating-member-details
add ability to enable and disable members of an org
2 parents 25b3ab9 + 1ff4af5 commit 5fc034a

5 files changed

Lines changed: 144 additions & 0 deletions

File tree

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,28 @@ You can display your current refresh token with:
146146
```
147147
esc access tokens display
148148
```
149+
150+
151+
### List members of an organization.
152+
153+
```
154+
esc access members list
155+
```
156+
157+
### Enable a member of an organization
158+
159+
```
160+
esc access members update --id <member-id> --active true
161+
```
162+
163+
### Disable a member of an organization
164+
165+
```
166+
esc access members update --id <member-id> --active false
167+
```
168+
169+
### Deletes a member from an organization
170+
171+
```
172+
esc access members delete --id <member-id>
173+
```

cli/src/main.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,8 @@ enum GroupsCommand {
317317
enum MembersCommand {
318318
Get(GetMember),
319319
List(ListMembers),
320+
Update(UpdateMember),
321+
Delete(DeleteMember),
320322
}
321323

322324
#[derive(StructOpt, Debug)]
@@ -336,6 +338,34 @@ struct ListMembers {
336338
org_id: OrgId,
337339
}
338340

341+
#[derive(StructOpt, Debug)]
342+
#[structopt(about = "Update a member")]
343+
struct UpdateMember {
344+
#[structopt(long, short, parse(try_from_str = parse_member_id), help = "The member id")]
345+
id: MemberId,
346+
347+
#[structopt(long, short, parse(try_from_str = parse_org_id), default_value = "", help = "The organization id the member will relate to")]
348+
org_id: OrgId,
349+
350+
#[structopt(
351+
long,
352+
short,
353+
parse(try_from_str),
354+
help = "Specifies whether the member is active."
355+
)]
356+
active: bool,
357+
}
358+
359+
#[derive(StructOpt, Debug)]
360+
#[structopt(about = "Deletes a Member")]
361+
struct DeleteMember {
362+
#[structopt(long, short, parse(try_from_str = parse_member_id))]
363+
id: MemberId,
364+
365+
#[structopt(long, short, parse(try_from_str = parse_org_id), default_value = "")]
366+
org_id: OrgId,
367+
}
368+
339369
#[derive(StructOpt, Debug)]
340370
enum UserCommand {
341371
List,
@@ -749,6 +779,7 @@ enum OrganizationsCommand {
749779
Get(GetOrganization),
750780
Delete(DeleteOrganization),
751781
List(ListOrganizations),
782+
GetMfaStatus(GetOrganizationMfaStatus),
752783
}
753784

754785
#[derive(Debug, StructOpt)]
@@ -775,6 +806,13 @@ struct GetOrganization {
775806
id: OrgId,
776807
}
777808

809+
#[derive(Debug, StructOpt)]
810+
#[structopt(about = "read an organization's MFA status")]
811+
struct GetOrganizationMfaStatus {
812+
#[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")]
813+
id: OrgId,
814+
}
815+
778816
#[derive(Debug, StructOpt)]
779817
#[structopt(about = "Delete an organization")]
780818
struct DeleteOrganization {
@@ -1953,6 +1991,24 @@ async fn call_api<'a, 'b>(
19531991
esc_api::access::get_member(&client, params.org_id, params.id).await?;
19541992
printer.print(resp)?;
19551993
}
1994+
1995+
MembersCommand::Update(params) => {
1996+
let client = client_builder.create().await?;
1997+
esc_api::access::update_member(
1998+
&client,
1999+
params.org_id,
2000+
params.id,
2001+
esc_api::access::UpdateMemberRequest {
2002+
active: params.active,
2003+
},
2004+
)
2005+
.await?;
2006+
}
2007+
2008+
MembersCommand::Delete(params) => {
2009+
let client = client_builder.create().await?;
2010+
esc_api::access::delete_member(&client, params.org_id, params.id).await?;
2011+
}
19562012
},
19572013
},
19582014

@@ -2339,6 +2395,12 @@ async fn call_api<'a, 'b>(
23392395
let resp = esc_api::resources::list_organizations(&client).await?;
23402396
printer.print(resp)?;
23412397
}
2398+
2399+
OrganizationsCommand::GetMfaStatus(params) => {
2400+
let client = client_builder.create().await?;
2401+
let resp = esc_api::resources::get_mfa_status(&client, params.id).await?;
2402+
printer.print(resp)?;
2403+
}
23422404
},
23432405

23442406
ResourcesCommand::Projects(projs) => match projs.projects_command {

cli/src/v1/resources.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use chrono::{DateTime, Utc};
2+
use esc_api::resources::MfaStatus;
23
use std::fmt::Formatter;
34

45
use super::common::{List, ToV1};
@@ -59,6 +60,15 @@ impl ToV1 for esc_api::resources::ListOrganizationsResponse {
5960
}
6061
}
6162

63+
impl ToV1 for esc_api::resources::MfaStatus {
64+
type V1Type = MfaStatus;
65+
fn to_v1(self) -> Self::V1Type {
66+
MfaStatus {
67+
mfa_enabled: self.mfa_enabled,
68+
}
69+
}
70+
}
71+
6272
#[derive(Debug, Serialize, Deserialize)]
6373
#[serde(rename_all = "camelCase")]
6474
pub struct Project {

generated/src/resources/operations.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,21 @@ pub async fn delete_project(
8686
.await
8787
}
8888

89+
/// Gets the mfa status of an organization
90+
///
91+
/// # Arguments
92+
///
93+
/// * `organization_id` - The id of the organization
94+
pub async fn get_mfa_status(client: &Client, organization_id: OrganizationId) -> Result<MfaStatus> {
95+
let url = format!(
96+
"/resources/v1/organizations/{organizationId}/mfa",
97+
organizationId = urlencode(organization_id),
98+
);
99+
client
100+
.send_request::<(), MfaStatus>(Method::GET, url, None, None)
101+
.await
102+
}
103+
89104
/// Gets a single organization by ID.
90105
///
91106
/// # Arguments
@@ -158,6 +173,26 @@ pub async fn list_projects(
158173
.await
159174
}
160175

176+
/// Changes the status of MFA for an organization
177+
/// # Arguments
178+
///
179+
/// * `organization_id` - The id of the organization
180+
/// * `mfa_status`
181+
pub async fn update_mfa(
182+
client: &Client,
183+
organization_id: OrganizationId,
184+
// The desired status of MFA
185+
mfa_status: MfaStatus,
186+
) -> Result<UpdateMfaResponse> {
187+
let url = format!(
188+
"/resources/v1/organizations/{organizationId}/mfa",
189+
organizationId = urlencode(organization_id),
190+
);
191+
client
192+
.send_request::<MfaStatus, UpdateMfaResponse>(Method::POST, url, Some(&mfa_status), None)
193+
.await
194+
}
195+
161196
/// Deletes an organization by ID.
162197
///
163198
/// # Arguments

generated/src/resources/schemas.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ pub struct ListProjectsResponse {
5353
pub projects: Vec<Project>,
5454
}
5555

56+
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
57+
#[serde(rename_all = "camelCase")]
58+
pub struct MfaStatus {
59+
pub mfa_enabled: bool,
60+
}
61+
5662
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
5763
#[serde(rename_all = "camelCase")]
5864
pub struct Organization {
@@ -71,6 +77,12 @@ pub struct Project {
7177
pub organization_id: OrganizationId,
7278
}
7379

80+
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
81+
#[serde(rename_all = "camelCase")]
82+
pub struct UpdateMfaResponse {
83+
pub mfa_enabled: bool,
84+
}
85+
7486
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
7587
#[serde(rename_all = "camelCase")]
7688
pub struct UpdateOrganizationRequest {

0 commit comments

Comments
 (0)