Skip to content

Commit 1fed28d

Browse files
feat: add secrets generator to the Python SDK (#1344)
## 🎟️ Tracking https://bitwarden.atlassian.net/browse/SM-1603 ## 📔 Objective Add a secret generator to the Python SDK. ## ⏰ Reminders before review - Contributor guidelines followed - All formatters and local linters executed and passed - Written new unit and / or integration tests where applicable - Protected functional changes with optionality (feature flags) - Used internationalization (i18n) for all UI strings - CI builds passed - Communicated to DevOps any deployment requirements - Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team ## 🦮 Reviewer guidelines <!-- Suggested interactions but feel free to use (or not) as you desire! --> - 👍 (`:+1:`) or similar for great changes - 📝 (`:memo:`) or ℹ️ (`:information_source:`) for notes or general info - ❓ (`:question:`) for questions - 🤔 (`:thinking:`) or 💭 (`:thought_balloon:`) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion - 🎨 (`:art:`) for suggestions / improvements - ❌ (`:x:`) or ⚠️ (`:warning:`) for more significant problems or concerns needing attention - 🌱 (`:seedling:`) or ♻️ (`:recycle:`) for future improvements or indications of technical debt - ⛏ (`:pick:`) for minor or nitpick changes
1 parent af88a91 commit 1fed28d

File tree

19 files changed

+505
-95
lines changed

19 files changed

+505
-95
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ members = ["crates/*"]
77
# Update using `cargo set-version -p bitwarden <new-version>`
88
version = "1.0.0"
99
authors = ["Bitwarden Inc"]
10-
edition = "2021"
10+
edition = "2024"
1111
# Note: Changing rust-version should be considered a breaking change
1212
rust-version = "1.85"
1313
homepage = "https://bitwarden.com"

crates/bitwarden-c/src/c.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub struct CClient {
1717
client: Client,
1818
}
1919

20-
#[no_mangle]
20+
#[unsafe(no_mangle)]
2121
pub extern "C" fn run_command(c_str_ptr: *const c_char, client_ptr: *const CClient) -> *mut c_char {
2222
let client = unsafe { ffi_ref!(client_ptr) };
2323
let input_str = str::from_utf8(unsafe { CStr::from_ptr(c_str_ptr) }.to_bytes())
@@ -35,7 +35,7 @@ pub extern "C" fn run_command(c_str_ptr: *const c_char, client_ptr: *const CClie
3535

3636
type OnCompletedCallback = unsafe extern "C" fn(result: *mut c_char) -> ();
3737

38-
#[no_mangle]
38+
#[unsafe(no_mangle)]
3939
pub extern "C" fn run_command_async(
4040
c_str_ptr: *const c_char,
4141
client_ptr: *const CClient,
@@ -74,7 +74,7 @@ pub extern "C" fn run_command_async(
7474
}
7575

7676
// Init client, potential leak! You need to call free_mem after this!
77-
#[no_mangle]
77+
#[unsafe(no_mangle)]
7878
pub extern "C" fn init(c_str_ptr: *const c_char) -> *mut CClient {
7979
// This will only fail if another logger was already initialized, so we can ignore the result
8080
let _ = env_logger::try_init();
@@ -97,19 +97,19 @@ pub extern "C" fn init(c_str_ptr: *const c_char) -> *mut CClient {
9797
}
9898

9999
// Free mem
100-
#[no_mangle]
100+
#[unsafe(no_mangle)]
101101
pub extern "C" fn free_mem(client_ptr: *mut CClient) {
102102
std::mem::drop(unsafe { Box::from_raw(client_ptr) });
103103
}
104104

105-
#[no_mangle]
105+
#[unsafe(no_mangle)]
106106
pub extern "C" fn abort_and_free_handle(join_handle_ptr: *mut tokio::task::JoinHandle<()>) {
107107
let join_handle = unsafe { Box::from_raw(join_handle_ptr) };
108108
join_handle.abort();
109109
std::mem::drop(join_handle);
110110
}
111111

112-
#[no_mangle]
112+
#[unsafe(no_mangle)]
113113
pub extern "C" fn free_handle(join_handle_ptr: *mut tokio::task::JoinHandle<()>) {
114114
std::mem::drop(unsafe { Box::from_raw(join_handle_ptr) });
115115
}

crates/bitwarden-json/src/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl Client {
2525
let mut cmd_value: serde_json::Value = match serde_json::from_str(input_str) {
2626
Ok(cmd) => cmd,
2727
Err(e) => {
28-
return Response::error(format!("Invalid command string: {}", e)).into_string()
28+
return Response::error(format!("Invalid command string: {}", e)).into_string();
2929
}
3030
};
3131

@@ -45,7 +45,7 @@ impl Client {
4545
let cmd: Command = match serde_json::from_value(cmd_value) {
4646
Ok(cmd) => cmd,
4747
Err(e) => {
48-
return Response::error(format!("Invalid command value: {}", e)).into_string()
48+
return Response::error(format!("Invalid command value: {}", e)).into_string();
4949
}
5050
};
5151

crates/bitwarden-wasm/src/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::rc::Rc;
44
use argon2::{Algorithm, Argon2, Params, Version};
55
use bitwarden_json::client::Client as JsonClient;
66
use js_sys::Promise;
7-
use log::{set_max_level, Level};
7+
use log::{Level, set_max_level};
88
use wasm_bindgen::prelude::*;
99
use wasm_bindgen_futures::future_to_promise;
1010

crates/bws/src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::path::PathBuf;
22

33
use bitwarden_cli::Color;
4-
use clap::{builder::ValueParser, ArgGroup, Parser, Subcommand, ValueEnum};
4+
use clap::{ArgGroup, Parser, Subcommand, ValueEnum, builder::ValueParser};
55
use clap_complete::Shell;
66
use uuid::Uuid;
77

crates/bws/src/command/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use std::{path::PathBuf, str::FromStr};
77
use bitwarden::auth::AccessToken;
88
use clap::CommandFactory;
99
use clap_complete::Shell;
10-
use color_eyre::eyre::{bail, Result};
10+
use color_eyre::eyre::{Result, bail};
1111

12-
use crate::{config, util, Cli, ProfileKey};
12+
use crate::{Cli, ProfileKey, config, util};
1313

1414
pub(crate) fn completions(shell: Option<Shell>) -> Result<()> {
1515
let Some(shell) = shell.or_else(Shell::from_env) else {

crates/bws/src/command/project.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
use bitwarden::{
2+
Client,
23
secrets_manager::{
4+
ClientProjectsExt,
35
projects::{
46
ProjectCreateRequest, ProjectGetRequest, ProjectPutRequest, ProjectsDeleteRequest,
57
ProjectsListRequest,
68
},
7-
ClientProjectsExt,
89
},
9-
Client,
1010
};
11-
use color_eyre::eyre::{bail, Result};
11+
use color_eyre::eyre::{Result, bail};
1212
use uuid::Uuid;
1313

1414
use crate::{
15-
render::{serialize_response, OutputSettings},
1615
ProjectCommand,
16+
render::{OutputSettings, serialize_response},
1717
};
1818

1919
pub(crate) async fn process_command(

crates/bws/src/command/run.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ use std::{
55
};
66

77
use bitwarden::{
8+
Client,
89
secrets_manager::{
9-
secrets::{SecretIdentifiersByProjectRequest, SecretIdentifiersRequest, SecretsGetRequest},
1010
ClientSecretsExt,
11+
secrets::{SecretIdentifiersByProjectRequest, SecretIdentifiersRequest, SecretsGetRequest},
1112
},
12-
Client,
1313
};
14-
use color_eyre::eyre::{bail, Result};
14+
use color_eyre::eyre::{Result, bail};
1515
use itertools::Itertools;
1616
use uuid::Uuid;
1717
use which::which;
1818

1919
use crate::{
20-
util::{is_valid_posix_name, uuid_to_posix},
2120
ACCESS_TOKEN_KEY_VAR_NAME,
21+
util::{is_valid_posix_name, uuid_to_posix},
2222
};
2323

2424
// Essential environment variables that should be preserved even when `--no-inherit-env` is used
@@ -80,7 +80,10 @@ pub(crate) async fn run(
8080

8181
if !uuids_as_keynames {
8282
if let Some(duplicate) = secrets.iter().map(|s| &s.key).duplicates().next() {
83-
bail!("Multiple secrets with name: '{}'. Use --uuids-as-keynames or use unique names for secrets", duplicate);
83+
bail!(
84+
"Multiple secrets with name: '{}'. Use --uuids-as-keynames or use unique names for secrets",
85+
duplicate
86+
);
8487
}
8588
}
8689

crates/bws/src/command/secret.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
use bitwarden::{
2+
Client,
23
secrets_manager::{
4+
ClientSecretsExt,
35
secrets::{
46
SecretCreateRequest, SecretGetRequest, SecretIdentifiersByProjectRequest,
57
SecretIdentifiersRequest, SecretPutRequest, SecretResponse, SecretsDeleteRequest,
68
SecretsGetRequest,
79
},
8-
ClientSecretsExt,
910
},
10-
Client,
1111
};
12-
use color_eyre::eyre::{bail, Result};
12+
use color_eyre::eyre::{Result, bail};
1313
use uuid::Uuid;
1414

1515
use crate::{
16-
render::{serialize_response, OutputSettings},
1716
SecretCommand,
17+
render::{OutputSettings, serialize_response},
1818
};
1919

2020
#[derive(Debug)]

crates/bws/src/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ use std::{
44
path::{Path, PathBuf},
55
};
66

7-
use color_eyre::eyre::{bail, Result};
7+
use color_eyre::eyre::{Result, bail};
88
use directories::BaseDirs;
99
use serde::{Deserialize, Serialize};
1010

11-
use crate::cli::{ProfileKey, DEFAULT_CONFIG_DIRECTORY, DEFAULT_CONFIG_FILENAME};
11+
use crate::cli::{DEFAULT_CONFIG_DIRECTORY, DEFAULT_CONFIG_FILENAME, ProfileKey};
1212

1313
#[derive(Debug, Serialize, Deserialize, Default)]
1414
pub(crate) struct Config {

0 commit comments

Comments
 (0)