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

Add run_command_async #993

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open

Add run_command_async #993

wants to merge 27 commits into from

Conversation

justindbaur
Copy link
Member

🎟️ Tracking

📔 Objective

  • Bumps .NET to 8 (latest LTS)
  • Uses [LibraryImport] for auto-marshalling of function
  • Adds run_command_async method in bitwarden-c that allows for a non-blocking call that can notify the caller when the action is completed.
  • Task-ifies one of the C# SDK calls into the SDK.
    • This only updates one method to be async for now but all of them can be changed
    • This is a breaking change so would be a good idea before a 1.0.0 release.

📸 Screenshots

⏰ 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

  • 👍 (:+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

Copy link
Contributor

github-actions bot commented Aug 23, 2024

Logo
Checkmarx One – Scan Summary & Details2d6d383c-0e65-45d7-8644-7bfb01d94c73

No New Or Fixed Issues Found

Copy link

codecov bot commented Aug 23, 2024

Codecov Report

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

Project coverage is 58.08%. Comparing base (0ae6d73) to head (aaff4f5).

Files with missing lines Patch % Lines
crates/bitwarden-c/src/c.rs 0.00% 39 Missing ⚠️
crates/bitwarden-json/src/client.rs 0.00% 15 Missing ⚠️
crates/bitwarden-json/src/command.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #993      +/-   ##
==========================================
- Coverage   58.31%   58.08%   -0.24%     
==========================================
  Files         193      193              
  Lines       13553    13608      +55     
==========================================
  Hits         7904     7904              
- Misses       5649     5704      +55     

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

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.

Overall LGTM, just some small details.

languages/csharp/Bitwarden.Sdk/BitwardenLibrary.cs Outdated Show resolved Hide resolved
Comment on lines 57 to 58
[target.'cfg(debug_assertions)'.dependencies]
tokio = { version = "1.36.0", features = ["rt", "macros", "time"] }
Copy link
Member Author

Choose a reason for hiding this comment

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

I barely know what I did here, I need the time feature but only in debug, is this the right way to go?

Copy link
Member

Choose a reason for hiding this comment

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

It is, but I can't say I'm a fan of different behaviors on debug and release builds.

Copy link
Member Author

Choose a reason for hiding this comment

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

This feels like the exact thing a debug build is for, it helps you write tests to make sure you've built the language wrapper correctly. That said I was able to move it into the bitwarden-json crate instead of core.

@justindbaur
Copy link
Member Author

I added support for CancellationToken which will cancel an ongoing call to rust. To ensure I did this correctly I added some debug only commands. I also converted all the C# methods to be Task returning and to optionally take a CancellationToken.

@Hinton Hinton requested a review from a team September 9, 2024 08:54
Comment on lines 27 to 48

#[cfg(debug_assertions)]
pub async fn cancellation_test(&mut self, duration_millis: u64) -> Result<i32> {
use std::time::Duration;

tokio::time::sleep(Duration::from_millis(duration_millis)).await;
println!("After wait #1");
tokio::time::sleep(Duration::from_millis(duration_millis)).await;
println!("After wait #2");
tokio::time::sleep(Duration::from_millis(duration_millis)).await;
println!("After wait #3");
Ok(42)
}

#[cfg(debug_assertions)]
pub fn error_test(&mut self) -> Result<i32> {
use crate::Error;

Err(Error::Internal(std::borrow::Cow::Borrowed(
"This is an error.",
)))
}
Copy link
Member

Choose a reason for hiding this comment

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

Are these needed in the core crate? Consider moving them to a separate test crate, or bitwarden-c, or remove it completely.

Copy link
Member Author

Choose a reason for hiding this comment

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

I moved them to bitwarden-json, if I moved it into bitwarden-c I would have to double parse the input string to check for special commands. Do you think that is alright?

Copy link
Member

Choose a reason for hiding this comment

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

Why not just expose two regular functions for it?

Copy link
Member Author

Choose a reason for hiding this comment

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

The cancellation test is mostly testing the very code written in run_command_async so we'd have to expose a method with very similar internals to that and repeat ourselves. The error test is testing that the C# wrapper properly handles how errors are given back to it through the bitwarden-json crate.

Copy link
Member

Choose a reason for hiding this comment

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

I'll let @bitwarden/team-secrets-manager-dev decide if they want to accept net 8 as the new target.

languages/csharp/Bitwarden.Sdk.Tests/GlobalUsings.cs Outdated Show resolved Hide resolved
crates/bitwarden-c/src/c.rs Outdated Show resolved Hide resolved
Comment on lines 57 to 58
[target.'cfg(debug_assertions)'.dependencies]
tokio = { version = "1.36.0", features = ["rt", "macros", "time"] }
Copy link
Member

Choose a reason for hiding this comment

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

It is, but I can't say I'm a fan of different behaviors on debug and release builds.

@Hinton
Copy link
Member

Hinton commented Sep 9, 2024

I added SM as reviewers, we should try and get this in before the 1.0 release of the C# sdk.

@justindbaur justindbaur requested a review from Hinton September 10, 2024 17:47
Comment on lines +194 to +200
#[cfg(debug_assertions)]
#[derive(Serialize, Deserialize, JsonSchema, Debug)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub enum DebugCommand {
CancellationTest { duration_millis: u64 },
ErrorTest {},
}
Copy link
Member

Choose a reason for hiding this comment

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

An alternative way. of doing this would be to add one or two separate commands to bitwarden-c.

Copy link
Member

@Hinton Hinton left a comment

Choose a reason for hiding this comment

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

I think this seems fine from my perspective. I'll let SM do the final review and cover the csharp files.

Copy link
Member

@coltonhurst coltonhurst left a comment

Choose a reason for hiding this comment

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

This looks good to me, thanks @justindbaur!

Have you tested that state files still work on the client creation and during token renewal?

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.

4 participants