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-1147] Switch to try_init with pyo3_log #676

Merged
merged 2 commits into from Apr 11, 2024
Merged

[SM-1147] Switch to try_init with pyo3_log #676

merged 2 commits into from Apr 11, 2024

Conversation

coltonhurst
Copy link
Member

Type of change

  • Bug fix
  • New feature development
  • Tech debt (refactoring, code cleanup, dependency upgrades, etc)
  • Build/deploy pipeline (DevOps)
  • Other

Objective

When running the ansible-playbook command, we needed to export the following variable: export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES. This suppresses fork safety warnings on Mac OS. With this set, you can safely query for individual secrets. However, if you query for secrets within an Ansible loop or with a Jinja2 template, we receive an error that is caused by setting up a logger more than once. (This error comes from the pyo3_log crate.)

If we switch to using the pyo3_log::try_init function, we ignore the case where a logger is already set up if the attempt fails. This happens because the pyo3_log::init function can panic. This also introduces panic safety.

Code changes

  • client.rs: Switch to try_init

Before you submit

  • Please add unit tests where it makes sense to do so

@coltonhurst coltonhurst self-assigned this Mar 21, 2024
@coltonhurst coltonhurst requested review from Hinton, dani-garcia and a team March 21, 2024 19:51
Copy link

codecov bot commented Mar 21, 2024

Codecov Report

Attention: Patch coverage is 0% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 60.59%. Comparing base (67e743f) to head (4c5b926).

Files Patch % Lines
crates/bitwarden-py/src/client.rs 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #676      +/-   ##
==========================================
- Coverage   60.61%   60.59%   -0.02%     
==========================================
  Files         170      170              
  Lines       10387    10390       +3     
==========================================
  Hits         6296     6296              
- Misses       4091     4094       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

dani-garcia
dani-garcia previously approved these changes Mar 22, 2024
Copy link
Member

@dani-garcia dani-garcia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, we're already doing the same thing for the c and napi bindings, seems like we forgot this one.

let _ = env_logger::try_init();

let _ = env_logger::Builder::from_default_env()
.filter_level(convert_level(log_level.unwrap_or(LogLevel::Info)))
.try_init();

Thomas-Avery
Thomas-Avery previously approved these changes Mar 22, 2024
Copy link
Contributor

@Thomas-Avery Thomas-Avery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@coltonhurst
Copy link
Member Author

Added a comment and let for consistency across crates in 4c5b926.

@Hinton Hinton mentioned this pull request Apr 9, 2024
1 task
@djsmith85 djsmith85 linked an issue Apr 9, 2024 that may be closed by this pull request
1 task
@coltonhurst coltonhurst merged commit b4205cc into main Apr 11, 2024
67 checks passed
@coltonhurst coltonhurst deleted the sm/sm-1147 branch April 11, 2024 13:59
@coltonhurst coltonhurst changed the title SM-1147: Switch to try_init with pyo3_log [SM-1147] Switch to try_init with pyo3_log Apr 11, 2024
@mittkkoo
Copy link

mittkkoo commented Apr 23, 2024

I'm sorry for the dumb question, but how to implement this fix on my side? I'm using Bitwarden Secrets with the ansible lookup plugin. I did cargo build in crates/bws as in the newest state of the main branch and then cargo install --path ., but what next? The lookup plugin still fails with a panic error as before.

@jacobfelknor
Copy link

jacobfelknor commented Apr 24, 2024

@mittkkoo, I'm facing the same issue as you with the Ansible integration.

If you followed the directions for setup in the Bitwarden Documentation, I believe it doesn't use the bws cli you installed/built with cargo (maintainer, please correct me if I'm wrong), but instead only uses the bitwarden-sdk PyPI package.

I think we must wait until a new version of bitwarden-sdk is published to PyPI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PanicExecption in python sdk
6 participants