-
Couldn't load subscription status.
- Fork 11
feat(api): add unraid-api --delete command
#1289
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
Conversation
WalkthroughThis pull request introduces a new CLI script in the package configuration to allow for direct execution. It adds a new Changes
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
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (4)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
deleteKeysmethod 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)
📒 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 existingcommandscript 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
unlinkto 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
DeleteApiKeyAnswerstype andDeleteApiKeyQuestionSetare correctly added to support the new delete functionality.Also applies to: 9-9
15-15: KeyOptions interface properly extended.The optional
deleteproperty is correctly added to theKeyOptionsinterface, 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
--deleteflag functionality.
94-100: Delete flag option correctly implemented.The
--deleteflag 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.
|
Thanks dude, good work on this. |
|
This plugin has been deployed to Cloudflare R2 and is available for testing. |
🤖 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>
Summary by CodeRabbit