keyshade-xyz / keyshade

Realtime secret and configuration management tool, with the best in class security and seamless integration support
https://keyshade.xyz
Mozilla Public License 2.0
196 stars 96 forks source link

feat(cli): added cli on projects #305

Closed yogesh1801 closed 2 weeks ago

yogesh1801 commented 3 months ago

User description

Description

Give a summary of the change that you have made

Fixes #298

Dependencies

Mention any dependencies/packages used

Future Improvements

Mention any improvements to be done in future related to any file/feature

Mentions

Mention and tag the people

Screenshots of relevant screens

Add screenshots of relevant screens

Developer's checklist

If changes are made in the code:

Documentation Update


PR Type

Enhancement


Description


Changes walkthrough 📝

Relevant files
Enhancement
project.command.ts
Add CLI commands for project management                                   

apps/cli/src/commands/project/project.command.ts
  • Added new CLI commands for project operations: list, get, create,
    update, delete, and fork.
  • Implemented methods to handle these commands, including logging and
    API calls.
  • +101/-0 
    project.types.d.ts
    Define TypeScript interfaces for project data                       

    apps/cli/src/commands/project/project.types.d.ts
  • Defined TypeScript interfaces for Project and ProjectData.
  • Included properties for project details and environment creation.
  • +27/-0   
    project.ts
    Implement ProjectController for project API interactions 

    apps/cli/src/http/project.ts
  • Implemented ProjectController with methods to list, get, and create
    projects via API calls.
  • Included error handling for API responses.
  • +70/-0   

    💡 PR-Agent usage: Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    codiumai-pr-agent-free[bot] commented 3 months ago

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review [1-5] 3
    🧪 Relevant tests No
    🔒 Security concerns No
    ⚡ Key issues to review Incomplete Implementation:
    The createProject method in project.command.ts has a comment "need to correct this" and the projectData variable is not initialized before being used, which could lead to runtime errors.
    Hardcoded Values:
    The baseurl and apikey are hardcoded in the methods of ProjectController, which is not a good practice for maintainability and security. Consider fetching these from a configuration file or environment variables.
    Error Handling:
    The methods in ProjectController throw errors but do not handle them. It would be beneficial to implement error handling where these methods are called to manage failures gracefully.
    Missing Implementation:
    The updateProject, deleteProject, and forkProject methods in project.command.ts are defined but not implemented.
    codiumai-pr-agent-free[bot] commented 3 months ago

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Initialize projectData with a default value to prevent runtime errors ___ **The variable projectData in the createProject method is declared but not initialized
    before use. This could lead to runtime errors if the method tries to access properties of
    projectData. Initialize projectData with a default value or ensure it is assigned a value
    before usage.** [apps/cli/src/commands/project/project.command.ts [84-91]](https://github.com/keyshade-xyz/keyshade/pull/305/files#diff-90cdda045317e5a39cf6195e384cd20837f355b7b14128882aa42edae5bdb1caR84-R91) ```diff -let projectData: ProjectData +let projectData: ProjectData = { name: '', description: '' } // Provide default values or fetch them as needed Logger.info(`creating the project`) const response = await ProjectController.createProject( 'baseurl', 'apikey', workspaceId, projectData ) ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 9 Why: This suggestion addresses a potential runtime error by ensuring `projectData` is initialized before use, which is crucial for preventing crashes.
    9
    Best practice
    Use arrow functions to ensure this is bound correctly in command actions ___ **The action methods in command definitions are using anonymous functions which capture this
    context implicitly. This might lead to issues where this does not refer to the
    ProjectCommand instance as expected. Use arrow functions to ensure the correct binding of
    this.** [apps/cli/src/commands/project/project.command.ts [13-15]](https://github.com/keyshade-xyz/keyshade/pull/305/files#diff-90cdda045317e5a39cf6195e384cd20837f355b7b14128882aa42edae5bdb1caR13-R15) ```diff -.action((workspaceId) => { - this.listProjects(workspaceId) -}) +.action((workspaceId) => this.listProjects(workspaceId)) ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 8 Why: Using arrow functions ensures the correct binding of `this`, which is important for the proper functioning of the command actions.
    8
    Possible issue
    Implement or remove the placeholder forkProject method ___ **The forkProject method currently does not implement any functionality. If this method is
    intended to be used, implement the necessary logic or remove the command if it is not
    needed.** [apps/cli/src/commands/project/project.command.ts [100]](https://github.com/keyshade-xyz/keyshade/pull/305/files#diff-90cdda045317e5a39cf6195e384cd20837f355b7b14128882aa42edae5bdb1caR100-R100) ```diff -private async forkProject(projectId: string) {} +private async forkProject(projectId: string) { + // Implementation goes here + Logger.info(`Forking project: ${projectId}`) + // More code... +} ```
    Suggestion importance[1-10]: 7 Why: Implementing or removing the placeholder method is important for code completeness and clarity, though it is not immediately critical.
    7
    Maintainability
    Refactor repetitive helpCommand usage into a helper function ___ **The helpCommand method is used repeatedly with the same parameters across different
    commands. Consider creating a helper function to reduce redundancy and improve
    maintainability.** [apps/cli/src/commands/project/project.command.ts [12-44]](https://github.com/keyshade-xyz/keyshade/pull/305/files#diff-90cdda045317e5a39cf6195e384cd20837f355b7b14128882aa42edae5bdb1caR12-R44) ```diff -.helpCommand('-h, --help', 'Display this help message') +.helpCommand(...defaultHelpOptions()) ```
    Suggestion importance[1-10]: 6 Why: This suggestion improves code maintainability by reducing redundancy, though it does not address a critical issue.
    6
    rajdip-b commented 2 months ago

    Hey @yogesh1801! Would you please go through the profile command, and understand how we organize the files and folders?

    Also, we have updated our docs to include the architecture of the CLI. You can refer that aswell.

    rajdip-b commented 1 month ago

    @yogesh1801 any updates?

    rajdip-b commented 2 weeks ago

    Closing due to inactivity