Skip to content

Conversation

@pujitm
Copy link
Member

@pujitm pujitm commented Mar 28, 2025

Summary by CodeRabbit

  • New Features
    • Introduced a new command that lets users run the CLI tool directly without initiating a build process.
    • Enhanced the CLI experience by adding interactive options for API key deletion, allowing users to select and remove keys with confirmation prompts.
    • Added a method to delete specified API keys from the system, improving key management capabilities.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 28, 2025

Walkthrough

This pull request introduces a new CLI script in the package configuration to allow for direct execution. It adds a new deleteApiKeys method in the API key service to remove keys from disk and memory, complete with error handling. Additionally, the CLI command now supports a --delete flag that routes deletion through a new interactive prompt, implemented via an added questions module. Finally, the new deletion question set is integrated into the CLI module's dependency injection.

Changes

File(s) Change Summary
api/package.json Added new script "command:raw": "./dist/cli.js" to run the CLI directly.
api/.../auth/api-key.service.ts Introduced deleteApiKeys method to verify and delete API keys from disk and memory; added unlink import from fs/promises.
api/.../cli/apikey/api-key.command.ts, api/.../cli/apikey/delete-api-key.questions.ts, api/.../cli/cli.module.ts Extended CLI functionality with new --delete flag: updated KeyOptions, added parseDelete and deleteKeys methods, created a deletion question set for user prompts, and registered it in the CLI module.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant C as ApiKeyCommand
    participant Q as DeleteApiKeyQuestionSet
    participant S as ApiKeyService
    participant F as Filesystem

    U->>C: Run CLI with "--delete"
    C->>C: Parse delete flag (parseDelete)
    C->>Q: Prompt for API key selection
    Q->>U: Display available API keys
    U->>Q: Select keys for deletion
    Q->>C: Return selected keys
    C->>S: Call deleteApiKeys(selected keys)
    S->>S: Verify keys in memory
    S->>F: Delete API key files concurrently
    F-->>S: Confirm deletion or report errors
    S->>S: Update in-memory store
    S-->>C: Return outcome of deletion
    C->>U: Log deletion count or error message
Loading

Suggested reviewers

  • mdatelle
  • zackspear

Poem

In a realm of code so neat and bright,
API keys bid farewell with a swift delight.
New commands whisper secrets through the night,
As keys vanish in a graceful, coded flight.
A playful dance of logic, precise and light.
Cheers to our changes, shining ever so right!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 4cff1a8 and a180677.

📒 Files selected for processing (1)
  • api/src/unraid-api/cli/apikey/delete-api-key.questions.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • api/src/unraid-api/cli/apikey/delete-api-key.questions.ts
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Build Web App
  • GitHub Check: Build API
  • GitHub Check: Test API
  • GitHub Check: Cloudflare Pages

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
api/src/unraid-api/cli/apikey/api-key.command.ts (1)

102-126: Well-implemented delete functionality with thorough error handling.

The deleteKeys method handles all necessary cases: no keys found, no keys selected, and deletion errors.

Consider improving error handling on line 123 by using a more specific type than as any.

- this.logger.error(error as any);
+ this.logger.error(error instanceof Error ? error.message : String(error));
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 234017a and 4cff1a8.

📒 Files selected for processing (5)
  • api/package.json (1 hunks)
  • api/src/unraid-api/auth/api-key.service.ts (3 hunks)
  • api/src/unraid-api/cli/apikey/api-key.command.ts (2 hunks)
  • api/src/unraid-api/cli/apikey/delete-api-key.questions.ts (1 hunks)
  • api/src/unraid-api/cli/cli.module.ts (2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
api/src/unraid-api/cli/apikey/api-key.command.ts (2)
api/src/graphql/generated/api/types.ts (1)
  • Permission (1119-1123)
api/src/unraid-api/cli/apikey/delete-api-key.questions.ts (1)
  • DeleteApiKeyAnswers (6-8)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Test API
  • GitHub Check: Build Web App
  • GitHub Check: Build API
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (11)
api/package.json (1)

20-20: Looks good - convenience script added.

The new script entry "command:raw": "./dist/cli.js" provides a direct way to execute the CLI without building first, which is useful for faster execution when the build is already up-to-date. This complements the existing command script that includes a build step.

api/src/unraid-api/cli/cli.module.ts (1)

8-8: Proper integration of the DeleteApiKeyQuestionSet.

The import and registration of the DeleteApiKeyQuestionSet in the DEFAULT_PROVIDERS array correctly integrates the new functionality into the dependency injection system.

Also applies to: 54-54

api/src/unraid-api/auth/api-key.service.ts (3)

3-3: Imported unlink for file deletion operations.

The addition of unlink to the imports is necessary for the new API key deletion functionality.


26-26: Added batchProcess utility for parallel operations.

The batchProcess import is appropriate for handling concurrent file operations in the new deleteApiKeys method.


317-347: Well-implemented deleteApiKeys method with proper error handling.

The new method includes:

  • Verification that keys exist before attempting deletion
  • Parallel processing for efficient file operations
  • In-memory state updates after deletion
  • Comprehensive error handling
  • Clear documentation

The implementation is robust and follows good patterns for batch operations.

api/src/unraid-api/cli/apikey/delete-api-key.questions.ts (1)

1-35: Well-structured question set for API key deletion.

The DeleteApiKeyQuestionSet is properly implemented with:

  • Clean interface definition for answers
  • Appropriate injection of required services
  • Well-formatted key choices that include name, description, and ID
  • Standard question pattern using nest-commander decorators

This implementation provides a user-friendly way to select multiple API keys for deletion.

api/src/unraid-api/cli/apikey/api-key.command.ts (5)

5-5: Imports properly added for new delete functionality.

The imports for DeleteApiKeyAnswers type and DeleteApiKeyQuestionSet are correctly added to support the new delete functionality.

Also applies to: 9-9


15-15: KeyOptions interface properly extended.

The optional delete property is correctly added to the KeyOptions interface, maintaining consistency with the existing interface structure.


23-23: Command description updated to include delete functionality.

The description now properly informs users about the new --delete flag functionality.


94-100: Delete flag option correctly implemented.

The --delete flag is implemented consistently with the existing pattern for command options.


128-136: Run method properly handles the new delete option.

The run method signature is updated to include the delete option with appropriate default value, and the implementation cleanly handles the delete workflow.

@elibosley
Copy link
Member

Thanks dude, good work on this.

@pujitm pujitm merged commit 2f09445 into main Mar 28, 2025
8 checks passed
@pujitm pujitm deleted the feat/del-apikey branch March 28, 2025 14:17
@github-actions
Copy link
Contributor

This plugin has been deployed to Cloudflare R2 and is available for testing.
Download it at this URL:

https://preview.dl.unraid.net/unraid-api/tag/PR1289/dynamix.unraid.net.plg

elibosley pushed a commit that referenced this pull request Apr 2, 2025
🤖 I have created a release *beep* *boop*
---


## [4.5.0](v4.4.1...v4.5.0)
(2025-04-02)


### Features

* add webgui theme switcher component
([#1304](#1304))
([e2d00dc](e2d00dc))
* api plugin system & offline versioned dependency vendoring
([#1252](#1252))
([9f492bf](9f492bf))
* **api:** add `unraid-api --delete` command
([#1289](#1289))
([2f09445](2f09445))
* basic array controls
([#1291](#1291))
([61fe696](61fe696))
* basic docker controls
([#1292](#1292))
([12eddf8](12eddf8))
* copy to webgui repo script docs + wc build options
([#1285](#1285))
([e54f189](e54f189))


### Bug Fixes

* additional url fixes
([4b2763c](4b2763c))
* **api:** redirect benign pnpm postinstall warning to log file
([#1290](#1290))
([7fb7849](7fb7849))
* **deps:** update dependency chalk to v5
([#1296](#1296))
([6bed638](6bed638))
* **deps:** update dependency diff to v7
([#1297](#1297))
([3c6683c](3c6683c))
* disable all config watchers
([#1306](#1306))
([5c1b435](5c1b435))
* extract callbacks to library
([#1280](#1280))
([2266139](2266139))
* OEM plugin issues ([#1288](#1288))
([d5a3d0d](d5a3d0d))
* replace files lost during pruning
([d0d2ff6](d0d2ff6))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@coderabbitai coderabbitai bot mentioned this pull request Aug 18, 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.

3 participants