Skip to content

PM-34033 - Add user & org API key seeding and improve CLI output#7324

Merged
theMickster merged 2 commits intomainfrom
seeder/PM-34033-user-and-org-api-keys
Mar 27, 2026
Merged

PM-34033 - Add user & org API key seeding and improve CLI output#7324
theMickster merged 2 commits intomainfrom
seeder/PM-34033-user-and-org-api-keys

Conversation

@theMickster
Copy link
Copy Markdown
Contributor

@theMickster theMickster commented Mar 27, 2026

🎟️ Tracking

PM-34033

📔 Objective

  1. Improve the Seeder Utility by implementing user api and organizational API key generation.
  2. Improve the output in the console window because, well, it stunk. Created a format that should be both human readable AND computer readable for future scripting to consume the output from the utility and pipe the data as needed.
  3. Since we were already needing to work on the result records; it was time to refactor them into proper .cs files.

@theMickster theMickster added the ai-review-vnext Request a Claude code review using the vNext workflow label Mar 27, 2026
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Refactored from util/Seeder/Pipeline/RecipeOrchestrator.cs

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 27, 2026

Overall Assessment: APPROVE

This PR adds organization API key seeding via a new CreateOrganizationApiKeyStep, improves user API key generation by switching from GUID truncation to CoreHelpers.SecureRandomString(30), refactors result models into dedicated files with richer fields (API keys, passwords), and standardizes CLI output formatting through a shared ConsoleOutput helper. All changes are scoped to the dev seeder utility (util/Seeder and util/SeederUtility) with no production code impact.

Code Review Details

No findings identified. The new step follows the established pipeline pattern (step registration, context state, bulk commit ordering), the BulkCommitter correctly inserts the org API key in FK-safe order before users, and the result model refactoring cleanly separates internal pipeline state from public-facing result types.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Refactored from util/Seeder/Recipes/OrganizationRecipe.cs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Refactored from `util/Seeder/Recipes/IndividualUserRecipe.cs

public int KdfIterations { get; set; } = 5_000;

[Option("mangle", Description = "Enable ID mangling for test isolation")]
public bool Mangle { get; set; } = false;
Copy link
Copy Markdown
Contributor Author

@theMickster theMickster Mar 27, 2026

Choose a reason for hiding this comment

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

This is tech debt cleanup that shouldn't have been added


private static GlobalSettings LoadGlobalSettings()
{
Console.WriteLine("Loading global settings...");
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Pointless to have this in the output...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I really dig the flare we have here with the art work, but time to trim it down 😉
I will likely add a switch to skip this all-together when automated processes (like CI/CD or Bash scripts) call the CLI, but for now I am keeping it because it's still neat.

@theMickster theMickster marked this pull request as ready for review March 27, 2026 10:57
{
var org = context.RequireOrganization();

var apiKey = new OrganizationApiKey
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was taken directly from src/Core/AdminConsole/OrganizationFeatures/OrganizationApiKeys/CreateOrganizationApiKeyCommand.cs.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 27, 2026

Logo
Checkmarx One – Scan Summary & Details50933f16-5a2c-42d1-9d06-05ca9468e374

Great job! No new security vulnerabilities introduced in this pull request

Premium = premium,
MaxStorageGb = maxStorageGb,
ApiKey = Guid.NewGuid().ToString("N")[..30],
ApiKey = CoreHelpers.SecureRandomString(30),
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was taken directly form src/Core/Auth/UserFeatures/Registration/Implementations/RegisterUserCommand.cs

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 57.91%. Comparing base (5833e34) to head (ee443c2).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7324   +/-   ##
=======================================
  Coverage   57.91%   57.91%           
=======================================
  Files        2045     2045           
  Lines       90235    90235           
  Branches     8024     8024           
=======================================
+ Hits        52263    52264    +1     
+ Misses      36105    36104    -1     
  Partials     1867     1867           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Individual is not a particularly descriptive name. Is it an individual user, organization, folder, cipher?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Renamed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems both very specific and generic at the same time. Isn't the result dependent on what you are seeding?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Renamed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here, the name is very generic but it's tied to an organization .

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Renamed

@theMickster theMickster enabled auto-merge (squash) March 27, 2026 13:28
@sonarqubecloud
Copy link
Copy Markdown

@theMickster theMickster merged commit 612cdb9 into main Mar 27, 2026
60 checks passed
@theMickster theMickster deleted the seeder/PM-34033-user-and-org-api-keys branch March 27, 2026 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review-vnext Request a Claude code review using the vNext workflow

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants