Skip to content

Commit

Permalink
SM-1371: Add Generators to bitwarden-json
Browse files Browse the repository at this point in the history
  • Loading branch information
coltonhurst committed Aug 3, 2024
1 parent 87522ef commit c45d686
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
11 changes: 9 additions & 2 deletions crates/bitwarden-json/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#[cfg(feature = "secrets")]
use bitwarden::secrets_manager::{ClientProjectsExt, ClientSecretsExt};
use bitwarden::secrets_manager::{ClientGeneratorsExt, ClientProjectsExt, ClientSecretsExt};
#[cfg(feature = "internal")]
use bitwarden::vault::ClientVaultExt;
use bitwarden::ClientSettings;

#[cfg(feature = "secrets")]
use crate::command::{ProjectsCommand, SecretsCommand};
use crate::command::{GeneratorsCommand, ProjectsCommand, SecretsCommand};
use crate::{
command::Command,
response::{Response, ResponseIntoString},
Expand Down Expand Up @@ -89,6 +89,13 @@ impl Client {
ProjectsCommand::Update(req) => client.projects().update(&req).await.into_string(),
ProjectsCommand::Delete(req) => client.projects().delete(req).await.into_string(),
},

#[cfg(feature = "secrets")]
Command::Generators(cmd) => match cmd {
GeneratorsCommand::GenerateSecret(req) => {
client.generators().generate_secret(req).await.into_string()

Check warning on line 96 in crates/bitwarden-json/src/client.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-json/src/client.rs#L94-L96

Added lines #L94 - L96 were not covered by tests
}
},
}
}

Expand Down
13 changes: 13 additions & 0 deletions crates/bitwarden-json/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use bitwarden::{
auth::login::AccessTokenLoginRequest,
secrets_manager::{
generators::GenerateSecretRequest,
projects::{
ProjectCreateRequest, ProjectGetRequest, ProjectPutRequest, ProjectsDeleteRequest,
ProjectsListRequest,
Expand Down Expand Up @@ -76,6 +77,8 @@ pub enum Command {
Secrets(SecretsCommand),
#[cfg(feature = "secrets")]
Projects(ProjectsCommand),
#[cfg(feature = "secrets")]
Generators(GeneratorsCommand),
}

#[cfg(feature = "secrets")]
Expand Down Expand Up @@ -175,3 +178,13 @@ pub enum ProjectsCommand {
/// Returns: [ProjectsDeleteResponse](bitwarden::secrets_manager::projects::ProjectsDeleteResponse)
Delete(ProjectsDeleteRequest),
}

#[cfg(feature = "secrets")]
#[derive(Serialize, Deserialize, JsonSchema, Debug)]

Check warning on line 183 in crates/bitwarden-json/src/command.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-json/src/command.rs#L183

Added line #L183 was not covered by tests
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub enum GeneratorsCommand {
/// Generate a secret value
///
/// Returns: [GenerateSecretResponse](bitwarden::secrets_manager::generators::GenerateSecretResponse)
GenerateSecret(GenerateSecretRequest),
}
2 changes: 1 addition & 1 deletion crates/bitwarden-sm/src/client_generators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl<'a> ClientGenerators<'a> {
Self { client }
}

Check warning on line 14 in crates/bitwarden-sm/src/client_generators.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-sm/src/client_generators.rs#L12-L14

Added lines #L12 - L14 were not covered by tests

pub async fn generate(
pub async fn generate_secret(
&self,
input: GenerateSecretRequest,
) -> Result<GenerateSecretResponse, GenerateSecretError> {
Expand Down

0 comments on commit c45d686

Please sign in to comment.