From 3f748f6867ba0125ea222a1364546101c8dfcc67 Mon Sep 17 00:00:00 2001 From: Brock Shelton Date: Fri, 5 Apr 2024 12:07:11 -0400 Subject: [PATCH 1/3] add ability to enable and disable members of an org --- README.md | 19 +++++++++++++++++++ cli/src/main.rs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/README.md b/README.md index c1fae86..fbf4bc2 100644 --- a/README.md +++ b/README.md @@ -146,3 +146,22 @@ 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 --active true +``` + +### Disable a member of an organization + +``` +esc access members update --id --active false +``` \ No newline at end of file diff --git a/cli/src/main.rs b/cli/src/main.rs index 1d57d38..ba6503b 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -317,6 +317,7 @@ enum GroupsCommand { enum MembersCommand { Get(GetMember), List(ListMembers), + Update(UpdateMember), } #[derive(StructOpt, Debug)] @@ -336,6 +337,24 @@ 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)] enum UserCommand { List, @@ -1953,6 +1972,19 @@ 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?; + } }, }, From 62d070dfd66145bb56a77251b7d02c67ce51213d Mon Sep 17 00:00:00 2001 From: Brock Shelton Date: Fri, 5 Apr 2024 12:39:01 -0400 Subject: [PATCH 2/3] add delete support --- README.md | 6 ++++++ cli/src/main.rs | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/README.md b/README.md index fbf4bc2..5559c09 100644 --- a/README.md +++ b/README.md @@ -164,4 +164,10 @@ esc access members update --id --active true ``` esc access members update --id --active false +``` + +### Deletes a member from an organization + +``` +esc access members delete --id ``` \ No newline at end of file diff --git a/cli/src/main.rs b/cli/src/main.rs index ba6503b..4738ece 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -318,6 +318,7 @@ enum MembersCommand { Get(GetMember), List(ListMembers), Update(UpdateMember), + Delete(DeleteMember), } #[derive(StructOpt, Debug)] @@ -355,6 +356,16 @@ struct UpdateMember { 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, @@ -1985,6 +1996,11 @@ async fn call_api<'a, 'b>( ) .await?; } + + MembersCommand::Delete(params) => { + let client = client_builder.create().await?; + esc_api::access::delete_member(&client, params.org_id, params.id).await?; + } }, }, From 1ff4af597a616c11ca63f1d18c9b82e52c2bfc19 Mon Sep 17 00:00:00 2001 From: Brock Shelton Date: Wed, 10 Apr 2024 15:34:29 -0400 Subject: [PATCH 3/3] add mfa status command --- cli/src/main.rs | 14 +++++++++++ cli/src/v1/resources.rs | 10 ++++++++ generated/src/resources/operations.rs | 35 +++++++++++++++++++++++++++ generated/src/resources/schemas.rs | 12 +++++++++ 4 files changed, 71 insertions(+) diff --git a/cli/src/main.rs b/cli/src/main.rs index 4738ece..6c5f1fa 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -779,6 +779,7 @@ enum OrganizationsCommand { Get(GetOrganization), Delete(DeleteOrganization), List(ListOrganizations), + GetMfaStatus(GetOrganizationMfaStatus), } #[derive(Debug, StructOpt)] @@ -805,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 { @@ -2387,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 { diff --git a/cli/src/v1/resources.rs b/cli/src/v1/resources.rs index 9436866..900b083 100644 --- a/cli/src/v1/resources.rs +++ b/cli/src/v1/resources.rs @@ -1,4 +1,5 @@ use chrono::{DateTime, Utc}; +use esc_api::resources::MfaStatus; use std::fmt::Formatter; use super::common::{List, ToV1}; @@ -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 { diff --git a/generated/src/resources/operations.rs b/generated/src/resources/operations.rs index 615fb30..c90e5b2 100644 --- a/generated/src/resources/operations.rs +++ b/generated/src/resources/operations.rs @@ -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 { + 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 @@ -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 { + let url = format!( + "/resources/v1/organizations/{organizationId}/mfa", + organizationId = urlencode(organization_id), + ); + client + .send_request::(Method::POST, url, Some(&mfa_status), None) + .await +} + /// Deletes an organization by ID. /// /// # Arguments diff --git a/generated/src/resources/schemas.rs b/generated/src/resources/schemas.rs index 6261afe..9556634 100644 --- a/generated/src/resources/schemas.rs +++ b/generated/src/resources/schemas.rs @@ -53,6 +53,12 @@ pub struct ListProjectsResponse { pub projects: Vec, } +#[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 { @@ -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 {