Skip to content

Commit

Permalink
SM-784: Enable Project Create/Edit/Delete CLI Commands (#67)
Browse files Browse the repository at this point in the history
* SM-417: Add project create, update, and delete commands

* SM-417: Run cargo fmt on branch

* SM-417: Update string guid's to be type Uuid, based on recently merged changes from master

* SM-417: Add project create, update, and delete commands to Client

* SM-417: Remove unneeded line in client_projects.rs

* SM-417: add the create, update, and delete commands to client, and run schemas

* SM-784: Add projects functionality

* SM-784: Typo fix, from secret to project

* SM-784: Finish enabling create/edit/delete commands for projects

* SM-784: Switch to Uuid per PR comment

* SM-784: Ran cargo fmt
  • Loading branch information
coltonhurst authored Jun 15, 2023
1 parent 4adfc04 commit 6758707
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion crates/bws/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use bitwarden::{
auth::request::AccessTokenLoginRequest,
request::{
client_settings::ClientSettings,
projects_request::{ProjectGetRequest, ProjectsListRequest},
projects_request::{
ProjectCreateRequest, ProjectGetRequest, ProjectPutRequest, ProjectsDeleteRequest,
ProjectsListRequest,
},
secrets_request::{
SecretCreateRequest, SecretGetRequest, SecretIdentifiersByProjectRequest,
SecretIdentifiersRequest, SecretPutRequest, SecretsDeleteRequest,
Expand Down Expand Up @@ -118,6 +121,9 @@ enum CreateCommand {
#[arg(long, help = "The ID of the project this secret will be added to")]
project_id: Option<Uuid>,
},
Project {
name: String,
},
}

#[derive(Subcommand, Debug)]
Expand All @@ -132,11 +138,18 @@ enum EditCommand {
#[arg(long, group = "edit_field")]
note: Option<String>,
},
#[clap(group = ArgGroup::new("edit_field").required(true).multiple(true))]
Project {
project_id: Uuid,
#[arg(long, group = "edit_field")]
name: String,
},
}

#[derive(Subcommand, Debug)]
enum DeleteCommand {
Secret { secret_ids: Vec<Uuid> },
Project { project_ids: Vec<Uuid> },
}

#[tokio::main(flavor = "current_thread")]
Expand Down Expand Up @@ -296,6 +309,50 @@ async fn process_commands() -> Result<()> {
serialize_response(project, cli.output, color);
}

Commands::Create {
cmd: CreateCommand::Project { name },
} => {
let project = client
.projects()
.create(&ProjectCreateRequest {
organization_id,
name,
})
.await?;
serialize_response(project, cli.output, color);
}

Commands::Edit {
cmd: EditCommand::Project { project_id, name },
} => {
let project = client
.projects()
.update(&ProjectPutRequest {
id: project_id,
organization_id,
name,
})
.await?;
serialize_response(project, cli.output, color);
}

Commands::Delete {
cmd: DeleteCommand::Project { project_ids },
} => {
let project_count = project_ids.len();

client
.projects()
.delete(ProjectsDeleteRequest { ids: project_ids })
.await?;

if project_count > 1 {
println!("Projects deleted successfully.");
} else {
println!("Project deleted successfully.");
}
}

Commands::Get {
cmd: GetCommand::Secret { secret_id },
} => {
Expand Down

0 comments on commit 6758707

Please sign in to comment.