Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SM-807: BWS CLI & SDK Updates #77

Merged
merged 18 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
93f2ca6
SM-807: Fix edit secret, allow updating the project a secret is in, a…
coltonhurst Jun 26, 2023
b117e20
SM-807: Update schemas
coltonhurst Jun 26, 2023
cae2129
SM-807: Add proper error messaging when secrets or projects are deleted.
coltonhurst Jun 26, 2023
10e985d
SM-807: Make project_id a parameter rather than an argument on secret…
coltonhurst Jun 26, 2023
25b90fe
SM-807: Merge master into branch
coltonhurst Jun 27, 2023
45fe743
SM-807: Add back project_ids that were lost in the merge conflict res…
coltonhurst Jun 27, 2023
30bb03c
SM-807: Add additional secrets / projects deletion error message when…
coltonhurst Jun 27, 2023
28242ec
SM-807: Make failed messaging on projects or secrets delete optional,…
coltonhurst Jun 27, 2023
032f4e0
SM-807: Add back the project_id help text on secret create
coltonhurst Jun 27, 2023
b8074ff
SM-807: Update secret/project delete to use a filter_map and not prin…
coltonhurst Jun 28, 2023
8c6543e
Merge branch 'master' into sm/SM-807
coltonhurst Jun 28, 2023
daf7921
SM-807: Remove mut refactor
coltonhurst Jun 29, 2023
30f4da1
SM-807: Merge branch 'master' into sm/SM-807 and fix merge conflict i…
coltonhurst Jul 10, 2023
348ef19
Merge branch 'master' into sm/SM-807
coltonhurst Jul 11, 2023
ef38c8a
Merge branch 'master' into sm/SM-807
coltonhurst Jul 12, 2023
ecf34e0
Merge branch 'master' into sm/SM-807
coltonhurst Jul 14, 2023
d174d22
Merge branch 'master' into sm/SM-807
coltonhurst Jul 20, 2023
1077d74
Merge branch 'master' into sm/SM-807
coltonhurst Jul 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/bitwarden-napi/src-ts/bitwarden_client/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ export interface SecretPutRequest {
* Organization ID of the secret to modify
*/
organizationId: string;
projectIds?: string[] | null;
value: string;
}

Expand Down Expand Up @@ -923,6 +924,7 @@ const typeMap: any = {
{ json: "key", js: "key", typ: "" },
{ json: "note", js: "note", typ: "" },
{ json: "organizationId", js: "organizationId", typ: "" },
{ json: "projectIds", js: "projectIds", typ: u(undefined, u(a(""), null)) },
{ json: "value", js: "value", typ: "" },
], false),
"SyncRequest": o([
Expand Down
3 changes: 2 additions & 1 deletion crates/bitwarden/src/secrets_manager/secrets/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct SecretPutRequest {
pub key: String,
pub value: String,
pub note: String,
pub project_ids: Option<Vec<Uuid>>,
}

pub(crate) async fn update_secret(
Expand All @@ -37,7 +38,7 @@ pub(crate) async fn update_secret(
key: enc.encrypt(input.key.as_bytes(), org_id)?.to_string(),
value: enc.encrypt(input.value.as_bytes(), org_id)?.to_string(),
note: enc.encrypt(input.note.as_bytes(), org_id)?.to_string(),
project_ids: None,
project_ids: input.project_ids.clone(),
});

let config = client.get_api_configurations().await;
Expand Down
84 changes: 71 additions & 13 deletions crates/bws/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,15 @@ enum SecretCommand {
Create {
key: String,
value: String,
project_id: Uuid,

#[arg(long, help = "An optional note to add to the secret")]
note: Option<String>,

#[arg(long, help = "The ID of the project this secret will be added to")]
Hinton marked this conversation as resolved.
Show resolved Hide resolved
project_id: Option<Uuid>,
},
Delete {
secret_ids: Vec<Uuid>,
},
#[clap(group = ArgGroup::new("edit_field").required(true).multiple(true))]
Edit {
secret_id: Uuid,
#[arg(long, group = "edit_field")]
Expand All @@ -126,6 +125,8 @@ enum SecretCommand {
value: Option<String>,
#[arg(long, group = "edit_field")]
note: Option<String>,
#[arg(long, group = "edit_field")]
project_id: Option<Uuid>,
},
Get {
secret_id: Uuid,
Expand Down Expand Up @@ -179,7 +180,7 @@ enum CreateCommand {
note: Option<String>,

#[arg(long, help = "The ID of the project this secret will be added to")]
project_id: Option<Uuid>,
project_id: Uuid,
},
}

Expand All @@ -200,6 +201,8 @@ enum EditCommand {
value: Option<String>,
#[arg(long, group = "edit_field")]
note: Option<String>,
#[arg(long, group = "edit_field")]
project_id: Option<Uuid>,
},
}

Expand Down Expand Up @@ -383,17 +386,37 @@ async fn process_commands() -> Result<()> {
| Commands::Delete {
cmd: DeleteCommand::Project { project_ids },
} => {
let project_count = project_ids.len();

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

if project_count > 1 {
println!("Projects deleted successfully.");
let mut projects_success = 0;
let mut projects_failed: Vec<(Uuid, String)> = Vec::new();

for project in result.data.iter() {
match &project.error {
Some(error_message) => {
projects_failed.push((project.id, error_message.to_owned()))
}
None => projects_success += 1,
}
}

if projects_success == 0 || projects_success > 1 {
println!("{} projects deleted successfully.", projects_success);
} else {
println!("Project deleted successfully.");
println!("{} project deleted successfully.", projects_success);
}

if projects_failed.len() > 1 {
println!("{} projects had errors:", projects_failed.len());
} else if projects_failed.len() == 1 {
println!("{} project had an error:", projects_failed.len());
}

for project in projects_failed {
println!("{}: {}", project.0, project.1);
}
}

Expand Down Expand Up @@ -466,7 +489,7 @@ async fn process_commands() -> Result<()> {
key,
value,
note: note.unwrap_or_default(),
project_ids: project_id.map(|p| vec![p]),
project_ids: Some(vec![project_id]),
})
.await?;
serialize_response(secret, cli.output, color);
Expand All @@ -479,6 +502,7 @@ async fn process_commands() -> Result<()> {
key,
value,
note,
project_id,
},
}
| Commands::Edit {
Expand All @@ -488,6 +512,7 @@ async fn process_commands() -> Result<()> {
key,
value,
note,
project_id,
},
} => {
let old_secret = client
Expand All @@ -505,6 +530,13 @@ async fn process_commands() -> Result<()> {
key: key.unwrap_or(old_secret.key),
value: value.unwrap_or(old_secret.value),
note: note.unwrap_or(old_secret.note),
project_ids: match project_id {
Some(id) => Some(vec![id]),
None => match old_secret.project_id {
Some(id) => Some(vec![id]),
None => bail!("Editing a secret requires a project_id."),
},
},
})
.await?;
serialize_response(secret, cli.output, color);
Expand All @@ -516,12 +548,38 @@ async fn process_commands() -> Result<()> {
| Commands::Delete {
cmd: DeleteCommand::Secret { secret_ids },
} => {
client
let result = client
.secrets()
.delete(SecretsDeleteRequest { ids: secret_ids })
.await?;

println!("Secret deleted correctly");
let mut secrets_success = 0;
let mut secrets_failed: Vec<(Uuid, String)> = Vec::new();

for secret in result.data.iter() {
match &secret.error {
Some(error_message) => {
secrets_failed.push((secret.id, error_message.to_owned()))
}
None => secrets_success += 1,
Hinton marked this conversation as resolved.
Show resolved Hide resolved
}
}

if secrets_success == 0 || secrets_success > 1 {
Hinton marked this conversation as resolved.
Show resolved Hide resolved
println!("{} secrets deleted successfully.", secrets_success);
} else {
println!("{} secret deleted successfully.", secrets_success);
}

if secrets_failed.len() > 1 {
println!("{} secrets had errors:", secrets_failed.len());
} else if secrets_failed.len() == 1 {
println!("{} secret had an error:", secrets_failed.len());
}

for secret in secrets_failed {
println!("{}: {}", secret.0, secret.1);
}
}

Commands::Config { .. } => {
Expand Down
3 changes: 3 additions & 0 deletions languages/csharp/schemas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,9 @@ public partial class SecretPutRequest
[JsonProperty("organizationId")]
public Guid OrganizationId { get; set; }

[JsonProperty("projectIds")]
public Guid[] ProjectIds { get; set; }

[JsonProperty("value")]
public string Value { get; set; }
}
Expand Down
2 changes: 2 additions & 0 deletions languages/js_webassembly/bitwarden_client/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ export interface SecretPutRequest {
* Organization ID of the secret to modify
*/
organizationId: string;
projectIds?: string[] | null;
value: string;
}

Expand Down Expand Up @@ -923,6 +924,7 @@ const typeMap: any = {
{ json: "key", js: "key", typ: "" },
{ json: "note", js: "note", typ: "" },
{ json: "organizationId", js: "organizationId", typ: "" },
{ json: "projectIds", js: "projectIds", typ: u(undefined, u(a(""), null)) },
{ json: "value", js: "value", typ: "" },
], false),
"SyncRequest": o([
Expand Down
6 changes: 5 additions & 1 deletion languages/python/BitwardenClient/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ class SecretPutRequest:
"""Organization ID of the secret to modify"""
organization_id: UUID
value: str
project_ids: Optional[List[UUID]] = None

@staticmethod
def from_dict(obj: Any) -> 'SecretPutRequest':
Expand All @@ -488,7 +489,8 @@ def from_dict(obj: Any) -> 'SecretPutRequest':
note = from_str(obj.get("note"))
organization_id = UUID(obj.get("organizationId"))
value = from_str(obj.get("value"))
return SecretPutRequest(id, key, note, organization_id, value)
project_ids = from_union([from_none, lambda x: from_list(lambda x: UUID(x), x)], obj.get("projectIds"))
return SecretPutRequest(id, key, note, organization_id, value, project_ids)

def to_dict(self) -> dict:
result: dict = {}
Expand All @@ -497,6 +499,8 @@ def to_dict(self) -> dict:
result["note"] = from_str(self.note)
result["organizationId"] = str(self.organization_id)
result["value"] = from_str(self.value)
if self.project_ids is not None:
result["projectIds"] = from_union([from_none, lambda x: from_list(lambda x: str(x), x)], self.project_ids)
return result


Expand Down
10 changes: 10 additions & 0 deletions support/schemas/bitwarden_json/Command.json
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,16 @@
"type": "string",
"format": "uuid"
},
"projectIds": {
"type": [
"array",
"null"
],
"items": {
"type": "string",
"format": "uuid"
}
},
"value": {
"type": "string"
}
Expand Down