Skip to content

Implement SDK generator engines #15063

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

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft

Conversation

adudek-bw
Copy link
Contributor

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-19976

📔 Objective

Hook up new SDK password/passphrase generation engines and put them behind a feature flag.

📸 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 Jun 3, 2025

Logo
Checkmarx One – Scan Summary & Details448d3461-a836-4cb6-9cc8-b42ff74f19b1

Great job, no security vulnerabilities found in this Pull Request

@adudek-bw adudek-bw requested a review from audreyality June 3, 2025 21:52
Copy link
Member

@audreyality audreyality left a comment

Choose a reason for hiding this comment

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

👍🏻 This is looking nice! I wasn't expecting it to be such a small amount of code!

🎨 If there's any lessons that you learned or things that you wish you'd known going in, please point them out to me (offline). I'm writing internals docs!

@@ -115,7 +116,7 @@ const SYSTEM_SERVICE_PROVIDER = new SafeInjectionToken<SystemServiceProvider>("S
}),
safeProvider({
provide: GENERATOR_SERVICE_PROVIDER,
useFactory: (
useFactory: async (
Copy link
Member

Choose a reason for hiding this comment

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

🤔 I'm pretty sure that factories can't be async.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops! Do you know of a way to unwrap Promise variables in a non-async factory? Or maybe which part of the code in which the feature flag can be unwrapped?

Copy link
Member

@audreyality audreyality Jun 4, 2025

Choose a reason for hiding this comment

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

Usually you'll want to unwrap it using the concatAsync operator in an observable pipe. The contributing docs has a complete list of options. Ignore the subscribe framing. The important part is the synchronous context.

Comment on lines +66 to +77
private metadataBySdkFlag(
algorithm: GeneratorMetadata<unknown & object>,
): GeneratorMetadata<unknown & object> {
if (this.useSdkService) {
if (algorithm.id == "password") {
return sdkPassword;
} else if (algorithm.id == "passphrase") {
return sdkPassphrase;
}
}
return algorithm;
}
Copy link
Member

Choose a reason for hiding this comment

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

💭 Most of the code in the metadata class is pretty high-level. It doesn't work directly with algorithms. It inspects types and directs lookups to externally-provided data. This code stands out because it's so low-level.

♻️ It's fully encapsulated, and the SDK doesn't have data to push into the provider, so this is totally cool. We'll just need to think about how to upgrade it when we start interning the metadata into the SDK.

🤔 Or maybe the trouble is that we should be swapping the engines during create on the stock password metadata.

❓ Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it def is pretty low level compared to the rest of the code. Ohhh, swapping them out at the metadata is an interesting idea. Would that mean that the creates functions for the non-sdk engines would check to see if the feature flag is enabled and if so create the sdk engine?

Copy link
Member

@audreyality audreyality Jun 4, 2025

Choose a reason for hiding this comment

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

I haven't thought out how it would work whatsoever. It would certainly need to be aware which mode it's using in order to know which version to create, but it wouldn't necessarily need the feature flag to do that. You could, for example, conditionally load the SDK based on the flag. If the SDK is loaded, it uses the SDK. Otherwise it uses the builtin version.

If you really want to get wild with it, you could lower it into the engine.

These ideas are all half-baked. If any of them sound feasible you can pursue them, but it's not necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahhhhh I like that

Copy link

sonarqubecloud bot commented Jun 4, 2025

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.

2 participants