Skip to content

Commit

Permalink
Merge branch 'main' into ps/argon2-publish
Browse files Browse the repository at this point in the history
  • Loading branch information
dani-garcia authored Apr 15, 2024
2 parents 92eeea5 + 499e213 commit 1ada3f5
Show file tree
Hide file tree
Showing 20 changed files with 59 additions and 1,871 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/publish-rust-crates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,21 @@ on:
required: true
default: true
type: boolean
publish_bitwarden-cli:
description: "Publish bitwarden-cli crate"
required: true
default: true
type: boolean
publish_bitwarden-generators:
description: "Publish bitwarden-generators crate"
required: true
default: true
type: boolean
publish_bitwarden-exporters:
description: "Publish bitwarden-exporters crate"
required: true
default: true
type: boolean

defaults:
run:
Expand Down Expand Up @@ -72,7 +82,9 @@ jobs:
PUBLISH_BITWARDEN_API_API: ${{ github.event.inputs.publish_bitwarden-api-api }}
PUBLISH_BITWARDEN_API_IDENTITY: ${{ github.event.inputs.publish_bitwarden-api-identity }}
PUBLISH_BITWARDEN_CRYPTO: ${{ github.event.inputs.publish_bitwarden-crypto }}
PUBLISH_BITWARDEN_CLI: ${{ github.event.inputs.publish_bitwarden-cli }}
PUBLISH_BITWARDEN_GENERATORS: ${{ github.event.inputs.publish_bitwarden-generators }}
PUBLISH_BITWARDEN_EXPORTERS: ${{ github.event.inputs.publish_bitwarden-exporters }}
run: |
if [[ "$PUBLISH_BITWARDEN" == "false" ]] && [[ "$PUBLISH_BITWARDEN_API_API" == "false" ]] && [[ "$PUBLISH_BITWARDEN_API_IDENTITY" == "false" ]]; then
echo "==================================="
Expand Down Expand Up @@ -104,11 +116,21 @@ jobs:
PACKAGES_LIST="$PACKAGES_LIST bitwarden-crypto"
fi
if [[ "$PUBLISH_BITWARDEN_CLI" == "true" ]]; then
PACKAGES_COMMAND="$PACKAGES_COMMAND -p bitwarden-cli"
PACKAGES_LIST="$PACKAGES_LIST bitwarden-cli"
fi
if [[ "$PUBLISH_BITWARDEN_GENERATORS" == "true" ]]; then
PACKAGES_COMMAND="$PACKAGES_COMMAND -p bitwarden-generators"
PACKAGES_LIST="$PACKAGES_LIST bitwarden-generators"
fi
if [[ "$PUBLISH_BITWARDEN_EXPORTERS" == "true" ]]; then
PACKAGES_COMMAND="$PACKAGES_COMMAND -p bitwarden-generators"
PACKAGES_LIST="$PACKAGES_LIST bitwarden-generators"
fi
echo "Packages command: " $PACKAGES_COMMAND
echo "Packages list: " $PACKAGES_LIST
Expand Down
3 changes: 0 additions & 3 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
target
languages/*
!/languages/kotlin
languages/kotlin/*
!/languages/kotlin/doc.md
schemas
/crates/bitwarden-napi/src-ts/bitwarden_client/schemas.ts
about.hbs
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/bitwarden-api-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ url = ">=2.3.1, <3"
uuid = { version = ">=1.3.3, <2", features = ["serde"] }
[dependencies.reqwest]
version = ">=0.12, <0.13"
features = ["json", "multipart"]
features = ["http2", "json", "multipart"]
default-features = false

[dev-dependencies]
2 changes: 1 addition & 1 deletion crates/bitwarden-api-identity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ url = ">=2.3.1, <3"
uuid = { version = ">=1.3.3, <2", features = ["serde"] }
[dependencies.reqwest]
version = ">=0.12, <0.13"
features = ["json", "multipart"]
features = ["http2", "json", "multipart"]
default-features = false

[dev-dependencies]
6 changes: 6 additions & 0 deletions crates/bitwarden-cli/src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ pub enum Color {
}

impl Color {
/**
* Evaluate if colors are supported
*/
pub fn is_enabled(self) -> bool {
match self {
Color::No => false,
Expand All @@ -17,6 +20,9 @@ impl Color {
}
}

/**
* Installs color_eyre, if Color is disabled we use an empty theme to disable error colors.
*/
pub fn install_color_eyre(color: Color) -> color_eyre::Result<(), color_eyre::Report> {
if color.is_enabled() {
color_eyre::install()
Expand Down
1 change: 1 addition & 0 deletions crates/bitwarden-generators/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mobile = ["dep:uniffi"] # Mobile-specific features
bitwarden-crypto = { workspace = true }
rand = ">=0.8.5, <0.9"
reqwest = { version = ">=0.12, <0.13", features = [
"http2",
"json",
], default-features = false }
schemars = { version = ">=0.8.9, <0.9", features = ["uuid1", "chrono"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub async fn generate_with_api_url(
"new-masked-email": {
"state": "enabled",
"description": "",
"url": website,
"forDomain": website,
"emailPrefix": null,
},
},
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-napi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const accessToken = "-- REDACTED --";

const client = new BitwardenClient(settings, LogLevel.Info);

// Authenticating using a service accounts access token
// Authenticating using a machine account access token
const result = await client.loginWithAccessToken(accessToken);
if (!result.success) {
throw Error("Authentication failed");
Expand Down
5 changes: 4 additions & 1 deletion crates/bitwarden-py/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ pub struct BitwardenClient(JsonClient);
impl BitwardenClient {
#[new]
pub fn new(settings_string: Option<String>) -> Self {
pyo3_log::init();
// This will only fail if another logger was already initialized, so we can ignore the
// result
let _ = pyo3_log::try_init();

Self(JsonClient::new(settings_string))
}

Expand Down
4 changes: 3 additions & 1 deletion crates/bitwarden-uniffi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

## Generating documentation

If desired we have some scripts that generates markdown documentation from the rustdoc output.

```bash
cargo +nightly rustdoc -p bitwarden -- -Zunstable-options --output-format json
cargo +nightly rustdoc -p bitwarden-uniffi -- -Zunstable-options --output-format json
npm run schemas

npx ts-node ./support/docs/docs.ts > languages/kotlin/doc.md
npx ts-node ./support/docs/docs.ts > doc.md
```
1 change: 1 addition & 0 deletions crates/bitwarden/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ hmac = ">=0.12.1, <0.13"
log = ">=0.4.18, <0.5"
rand = ">=0.8.5, <0.9"
reqwest = { version = ">=0.12, <0.13", features = [
"http2",
"json",
], default-features = false }
schemars = { version = ">=0.8.9, <0.9", features = ["uuid1", "chrono"] }
Expand Down
1 change: 1 addition & 0 deletions crates/bws/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ bat = { version = "0.24.0", features = [
"regex-onig",
], default-features = false }
bitwarden = { workspace = true, features = ["secrets"] }
bitwarden-cli = { workspace = true }
chrono = { version = "0.4.35", features = [
"clock",
"std",
Expand Down
16 changes: 5 additions & 11 deletions crates/bws/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use bitwarden::{
},
},
};
use bitwarden_cli::{install_color_eyre, Color};
use clap::{ArgGroup, CommandFactory, Parser, Subcommand};
use clap_complete::Shell;
use color_eyre::eyre::{bail, Result};
Expand All @@ -24,7 +25,7 @@ mod render;
mod state;

use config::ProfileKey;
use render::{serialize_response, Color, Output};
use render::{serialize_response, Output};
use uuid::Uuid;

#[derive(Parser, Debug)]
Expand All @@ -40,7 +41,7 @@ struct Cli {
#[arg(short = 'c', long, global = true, value_enum, default_value_t = Color::Auto, help="Use colors in the output")]
color: Color,

#[arg(short = 't', long, global = true, env = ACCESS_TOKEN_KEY_VAR_NAME, hide_env_values = true, help="Specify access token for the service account")]
#[arg(short = 't', long, global = true, env = ACCESS_TOKEN_KEY_VAR_NAME, hide_env_values = true, help="Specify access token for the machine account")]
access_token: Option<String>,

#[arg(
Expand Down Expand Up @@ -236,16 +237,9 @@ const SERVER_URL_KEY_VAR_NAME: &str = "BWS_SERVER_URL";
#[allow(clippy::comparison_chain)]
async fn process_commands() -> Result<()> {
let cli = Cli::parse();
let color = cli.color;

let color = cli.color.is_enabled();
if color {
color_eyre::install()?;
} else {
// Use an empty theme to disable error coloring
color_eyre::config::HookBuilder::new()
.theme(color_eyre::config::Theme::new())
.install()?;
}
install_color_eyre(color)?;

let Some(command) = cli.command else {
let mut cmd = Cli::command();
Expand Down
24 changes: 4 additions & 20 deletions crates/bws/src/render.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use bitwarden::secrets_manager::{projects::ProjectResponse, secrets::SecretResponse};
use bitwarden_cli::Color;
use chrono::{DateTime, Utc};
use clap::ValueEnum;
use comfy_table::Table;
Expand All @@ -15,29 +16,12 @@ pub(crate) enum Output {
None,
}

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Debug)]
pub(crate) enum Color {
No,
Yes,
Auto,
}

impl Color {
pub(crate) fn is_enabled(self) -> bool {
match self {
Color::No => false,
Color::Yes => true,
Color::Auto => supports_color::on(supports_color::Stream::Stdout).is_some(),
}
}
}

const ASCII_HEADER_ONLY: &str = " -- ";

pub(crate) fn serialize_response<T: Serialize + TableSerialize<N>, const N: usize>(
data: T,
output: Output,
color: bool,
color: Color,
) {
match output {
Output::JSON => {
Expand Down Expand Up @@ -101,8 +85,8 @@ pub(crate) fn serialize_response<T: Serialize + TableSerialize<N>, const N: usiz
}
}

fn pretty_print(language: &str, data: &str, color: bool) {
if color {
fn pretty_print(language: &str, data: &str, color: Color) {
if color.is_enabled() {
bat::PrettyPrinter::new()
.input_from_bytes(data.as_bytes())
.language(language)
Expand Down
2 changes: 1 addition & 1 deletion languages/java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ repositories {
def branchName = "git branch --show-current".execute().text.trim()

if (branchName == "main") {
def content = ['grep', '-o', '^version = ".*"', '../../crates/bitwarden/Cargo.toml'].execute().text.trim()
def content = ['grep', '-o', '^version = ".*"', '../../Cargo.toml'].execute().text.trim()
def match = ~/version = "(.*)"/
def matcher = match.matcher(content)
matcher.find()
Expand Down
6 changes: 3 additions & 3 deletions languages/js/sdk-client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1ada3f5

Please sign in to comment.