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(api): Add slug in entities #415

Closed rajdip-b closed 3 weeks ago

rajdip-b commented 3 weeks ago

User description

Description

This PR added a slug field to the following entities:

The motivation behind this PR is very simple, to have user-friendly unique entity names rather than IDs. For example, If there is a workspace named My Org, it will have a slug value of my-org-4tm2. The old way of accessing this resource would be using the following:

GET /api/workspace/<workspaceId>

The new way would be this:

GET /api/workspace/<workspaceSlug>

So, we would be using:

GET /api/workspace/my-org-4tm2

Along with that, there are also a lot of refactorings in the E2E test files.


PR Type

enhancement, tests, documentation


Description


Changes walkthrough 📝

Relevant files
Tests
6 files
workspace.e2e.spec.ts
Refactor workspace tests to use slugs and improve coverage

apps/api/src/workspace/workspace.e2e.spec.ts
  • Updated imports and refactored test cases to use slug instead of id.
  • Added new test cases for workspace operations using slug.
  • Grouped related test cases into describe blocks for better
    organization.
  • Enhanced test coverage for workspace-related events and operations.
  • +1056/-1013
    integration.e2e.spec.ts
    Refactor integration tests to use slugs and improve coverage

    apps/api/src/integration/integration.e2e.spec.ts
  • Updated imports and refactored test cases to use slug instead of id.
  • Added new test cases for integration operations using slug.
  • Grouped related test cases into describe blocks for better
    organization.
  • Enhanced test coverage for integration-related events and operations.
  • +468/-456
    project.e2e.spec.ts
    Refactor E2E Tests to Use Slugs for Projects and Workspaces

    apps/api/src/project/project.e2e.spec.ts
  • Updated test cases to use workspaceSlug and projectSlug instead of
    IDs.
  • Added new test cases for slug-based project operations.
  • Refactored tests into descriptive sections for better organization.
  • Introduced checks for slug existence and uniqueness.
  • +534/-522
    secret.e2e.spec.ts
    Refactor E2E Tests to Use Slugs for Secrets and Environments

    apps/api/src/secret/secret.e2e.spec.ts
  • Updated test cases to use workspaceSlug, projectSlug, and
    environmentSlug.
  • Refactored tests into descriptive sections for better organization.
  • Added new test cases for slug-based secret operations.
  • Introduced checks for slug existence and uniqueness.
  • +704/-693
    workspace-role.e2e.spec.ts
    Refactor workspace role tests to use slugs                             

    apps/api/src/workspace-role/workspace-role.e2e.spec.ts
  • Updated test cases to use slug instead of id for workspace roles.
  • Refactored test descriptions for better organization and readability.
  • Added new test cases for scenarios involving slugs.
  • Modified imports to reflect new file paths.
  • +668/-613
    variable.e2e.spec.ts
    Refactor variable tests to use slugs                                         

    apps/api/src/variable/variable.e2e.spec.ts
  • Updated test cases to use slug instead of id for variables and
    projects.
  • Refactored test descriptions and organized them into describe blocks.
  • Added new test cases for scenarios involving slugs.
  • Modified imports to reflect new file paths.
  • +572/-559
    Enhancement
    6 files
    authority-checker.service.ts
    Update authority checks to use slugs for entities               

    apps/api/src/common/authority-checker.service.ts
  • Updated authority checks to use slug instead of id.
  • Refactored imports for collective authority functions.
  • Improved error messages to reflect slug usage.
  • +35/-27 
    event.controller.ts
    Update event controller to use workspace slugs                     

    apps/api/src/event/controller/event.controller.ts
  • Changed event retrieval to use workspaceSlug instead of workspaceId.
  • Updated parameter names and annotations to reflect slug usage.
  • +3/-3     
    project.service.ts
    Implement Slug-Based Operations and Refactor Project Service

    apps/api/src/project/service/project.service.ts
  • Replaced ID-based operations with slug-based operations for projects
    and workspaces.
  • Added slug generation for projects, environments, and other entities.
  • Refactored authority checks to use slugs.
  • Improved utility imports and organized code structure.
  • +101/-75
    workspace.service.ts
    Update workspace service to use slugs                                       

    apps/api/src/workspace/service/workspace.service.ts
  • Replaced usage of id with slug for workspace operations.
  • Added slug generation for workspaces during updates.
  • Updated method signatures to accept slugs instead of ids.
  • Refactored imports to reflect new file paths.
  • +204/-186
    environment.service.ts
    Update environment service to use slugs                                   

    apps/api/src/environment/service/environment.service.ts
  • Replaced usage of id with slug for environment operations.
  • Added slug generation for environments during creation and updates.
  • Updated method signatures to accept slugs instead of ids.
  • Refactored imports to reflect new file paths.
  • +43/-27 
    create-workspace-role.ts
    Update DTO to use project slugs                                                   

    apps/api/src/workspace-role/dto/create-workspace-role/create-workspace-role.ts
  • Changed projectIds to projectSlugs in the CreateWorkspaceRole DTO.
  • +1/-1     
    Documentation
    1 files
    paginate.ts
    Add documentation to paginate function                                     

    apps/api/src/common/paginate.ts
  • Added JSDoc comments for the paginate function.
  • Corrected a typo in a comment within the paginate function.
  • +9/-1     
    Additional files (token-limit)
    47 files
    environment.e2e.spec.ts
    ...                                                                                                           

    apps/api/src/environment/environment.e2e.spec.ts ...
    +349/-315
    event.e2e.spec.ts
    ...                                                                                                           

    apps/api/src/event/event.e2e.spec.ts ...
    +176/-103
    api-key.e2e.spec.ts
    ...                                                                                                           

    apps/api/src/api-key/api-key.e2e.spec.ts ...
    +272/-238
    secret.service.ts
    ...                                                                                                           

    apps/api/src/secret/service/secret.service.ts ...
    +117/-101
    variable.service.ts
    ...                                                                                                           

    apps/api/src/variable/service/variable.service.ts ...
    +113/-104
    integration.service.ts
    ...                                                                                                           

    apps/api/src/integration/service/integration.service.ts ...
    +76/-61 
    workspace-role.service.ts
    ...                                                                                                           

    apps/api/src/workspace-role/service/workspace-role.service.ts ...
    +83/-51 
    workspace.controller.ts
    ...                                                                                                           

    apps/api/src/workspace/controller/workspace.controller.ts ...
    +63/-55 
    api-key.service.ts
    ...                                                                                                           

    apps/api/src/api-key/service/api-key.service.ts ...
    +34/-38 
    slug-generator.ts
    ...                                                                                                           

    apps/api/src/common/slug-generator.ts ...
    +150/-0 
    project.controller.ts
    ...                                                                                                           

    apps/api/src/project/controller/project.controller.ts ...
    +27/-27 
    secret.controller.ts
    ...                                                                                                           

    apps/api/src/secret/controller/secret.controller.ts ...
    +28/-28 
    variable.controller.ts
    ...                                                                                                           

    apps/api/src/variable/controller/variable.controller.ts ...
    +27/-27 
    integration.controller.ts
    ...                                                                                                           

    apps/api/src/integration/controller/integration.controller.ts ...
    +18/-15 
    util.ts
    ...                                                                                                           

    apps/api/src/common/util.ts ...
    +105/-0 
    environment.controller.ts
    ...                                                                                                           

    apps/api/src/environment/controller/environment.controller.ts ...
    +22/-15 
    workspace-role.controller.ts
    ...                                                                                                           

    apps/api/src/workspace-role/controller/workspace-role.controller.ts ...
    +18/-18 
    environment.ts
    ...                                                                                                           

    apps/api/src/common/environment.ts ...
    +62/-2   
    collective-authorities.ts
    ...                                                                                                           

    apps/api/src/common/collective-authorities.ts ...
    +95/-0   
    event.service.ts
    ...                                                                                                           

    apps/api/src/event/service/event.service.ts ...
    +18/-10 
    user.ts
    ...                                                                                                           

    apps/api/src/common/user.ts ...
    +76/-0   
    change-notifier.socket.ts
    ...                                                                                                           

    apps/api/src/socket/change-notifier.socket.ts ...
    +25/-40 
    cryptography.ts
    ...                                                                                                           

    apps/api/src/common/cryptography.ts ...
    +83/-0   
    api-key.controller.ts
    ...                                                                                                           

    apps/api/src/api-key/controller/api-key.controller.ts ...
    +15/-9   
    event.ts
    ...                                                                                                           

    apps/api/src/common/event.ts ...
    +42/-4   
    cryptography.spec.ts
    ...                                                                                                           

    apps/api/src/common/cryptography.spec.ts ...
    +59/-0   
    workspace.ts
    ...                                                                                                           

    apps/api/src/common/workspace.ts ...
    +22/-5   
    util.spec.ts
    ...                                                                                                           

    apps/api/src/common/util.spec.ts ...
    +2/-40   
    user.service.ts
    ...                                                                                                           

    apps/api/src/user/service/user.service.ts ...
    +10/-5   
    auth.guard.ts
    ...                                                                                                           

    apps/api/src/auth/guard/auth/auth.guard.ts ...
    +3/-3     
    user.controller.spec.ts
    ...                                                                                                           

    apps/api/src/user/controller/user.controller.spec.ts ...
    +5/-1     
    query.transform.pipe.ts
    ...                                                                                                           

    apps/api/src/common/pipes/query.transform.pipe.ts ...
    +19/-1   
    user.service.spec.ts
    ...                                                                                                           

    apps/api/src/user/service/user.service.spec.ts ...
    +5/-1     
    feedback.e2e.spec.ts
    ...                                                                                                           

    apps/api/src/feedback/feedback.e2e.spec.ts ...
    +2/-2     
    auth.service.ts
    ...                                                                                                           

    apps/api/src/auth/service/auth.service.ts ...
    +2/-2     
    create.integration.ts
    ...                                                                                                           

    apps/api/src/integration/dto/create.integration/create.integration.ts ...
    +2/-2     
    auth.controller.ts
    ...                                                                                                           

    apps/api/src/auth/controller/auth.controller.ts ...
    +1/-1     
    main.ts
    ...                                                                                                           

    apps/api/src/main.ts ...
    +1/-1     
    socket.types.ts
    ...                                                                                                           

    apps/api/src/socket/socket.types.ts ...
    +3/-9     
    integration.types.ts
    ...                                                                                                           

    apps/api/src/integration/integration.types.ts ...
    +4/-0     
    fork.project.ts
    ...                                                                                                           

    apps/api/src/project/dto/fork.project/fork.project.ts ...
    +1/-1     
    query.transform.pipe.spec.ts
    ...                                                                                                           

    apps/api/src/common/pipes/query.transform.pipe.spec.ts ...
    +8/-1     
    create.secret.ts
    ...                                                                                                           

    apps/api/src/secret/dto/create.secret/create.secret.ts ...
    +1/-1     
    create.variable.ts
    ...                                                                                                           

    apps/api/src/variable/dto/create.variable/create.variable.ts ...
    +1/-1     
    create.workspace.ts
    ...                                                                                                           

    apps/api/src/workspace/dto/create.workspace/create.workspace.ts ...
    +1/-1     
    migration.sql
    ...                                                                                                           

    apps/api/src/prisma/migrations/20240908063241_add_slug/migration.sql ...
    +68/-0   
    schema.prisma
    ...                                                                                                           

    apps/api/src/prisma/schema.prisma ...
    +21/-13 

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

    codecov[bot] commented 3 weeks ago

    Codecov Report

    Attention: Patch coverage is 94.53861% with 29 lines in your changes missing coverage. Please review.

    Project coverage is 87.77%. Comparing base (ce50743) to head (a9f4373). Report is 150 commits behind head on develop.

    Files with missing lines Patch % Lines
    apps/api/src/socket/change-notifier.socket.ts 0.00% 9 Missing :warning:
    apps/api/src/common/slug-generator.ts 88.05% 8 Missing :warning:
    apps/api/src/common/util.ts 78.26% 5 Missing :warning:
    apps/api/src/common/environment.ts 86.66% 2 Missing :warning:
    ...pps/api/src/workspace/service/workspace.service.ts 96.72% 2 Missing :warning:
    apps/api/src/api-key/service/api-key.service.ts 92.30% 1 Missing :warning:
    apps/api/src/common/user.ts 95.23% 1 Missing :warning:
    ...api/src/environment/service/environment.service.ts 94.11% 1 Missing :warning:
    Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #415 +/- ## =========================================== - Coverage 91.71% 87.77% -3.94% =========================================== Files 111 102 -9 Lines 2510 2635 +125 Branches 469 401 -68 =========================================== + Hits 2302 2313 +11 - Misses 208 322 +114 ``` | [Flag](https://app.codecov.io/gh/keyshade-xyz/keyshade/pull/415/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=keyshade-xyz) | Coverage Δ | | |---|---|---| | [api-e2e-tests](https://app.codecov.io/gh/keyshade-xyz/keyshade/pull/415/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=keyshade-xyz) | `87.77% <94.53%> (-3.94%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=keyshade-xyz#carryforward-flags-in-the-pull-request-comment) to find out more.

    :umbrella: View full report in Codecov by Sentry.
    :loudspeaker: Have feedback on the report? Share it here.

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

    CI Failure Feedback 🧐

    **Action:** Validate Cli
    **Failed stage:** [Build](https://github.com/keyshade-xyz/keyshade/actions/runs/10775158702/job/29878939243) [❌]
    **Failure summary:** The action failed due to a TypeScript compilation error:
  • In the file src/commands/environment/get.environment.ts at line 48, column 37, the code attempted to
    access a property getEnvironmentById on the type EnvironmentController.
  • The property getEnvironmentById does not exist on EnvironmentController. The error message suggests
    that the intended property might be getEnvironment.
  • This caused the TypeScript compiler (tsc) to exit with code 2, leading to the failure of the build
    command.
  • Relevant error logs: ```yaml 1: ##[group]Operating System 2: Ubuntu ... 273: > tsc && tsc-alias 274: ##[endgroup] 275: Tasks: 1 successful, 1 total 276: Cached: 0 cached, 1 total 277: Time: 2.319s 278: • Packages in scope: cli 279: • Running build in 1 packages 280: • Remote caching disabled 281: ##[error]cli#build: command (/home/runner/work/keyshade/keyshade/apps/cli) /home/runner/setup-pnpm/node_modules/.bin/pnpm run build exited (2) 282: cli:build 283: cache miss, executing 620fe2664ae7dba2 284: > cli@1.0.0 build /home/runner/work/keyshade/keyshade/apps/cli 285: > tsc && tsc-alias 286: ##[error]src/commands/environment/get.environment.ts(48,37): error TS2551: Property 'getEnvironmentById' does not exist on type 'EnvironmentController'. Did you mean 'getEnvironment'? 287: ELIFECYCLE  Command failed with exit code 2. 288: [ERROR] command finished with error: command (/home/runner/work/keyshade/keyshade/apps/cli) /home/runner/setup-pnpm/node_modules/.bin/pnpm run build exited (2) 289: Tasks: 0 successful, 1 total 290: Cached: 0 cached, 1 total 291: Time: 2.138s 292: Failed: cli#build 293: ERROR run failed: command exited (2) 294: ELIFECYCLE  Command failed with exit code 2. 295: ##[error]Process completed with exit code 2. ```

    ✨ CI feedback usage guide:
    The CI feedback tool (`/checks)` automatically triggers when a PR has a failed check. The tool analyzes the failed checks and provides several feedbacks: - Failed stage - Failed test name - Failure summary - Relevant error logs In addition to being automatically triggered, the tool can also be invoked manually by commenting on a PR: ``` /checks "https://github.com/{repo_name}/actions/runs/{run_number}/job/{job_number}" ``` where `{repo_name}` is the name of the repository, `{run_number}` is the run number of the failed check, and `{job_number}` is the job number of the failed check. #### Configuration options - `enable_auto_checks_feedback` - if set to true, the tool will automatically provide feedback when a check is failed. Default is true. - `excluded_checks_list` - a list of checks to exclude from the feedback, for example: ["check1", "check2"]. Default is an empty list. - `enable_help_text` - if set to true, the tool will provide a help message with the feedback. Default is true. - `persistent_comment` - if set to true, the tool will overwrite a previous checks comment with the new feedback. Default is true. - `final_update_message` - if `persistent_comment` is true and updating a previous checks message, the tool will also create a new message: "Persistent checks updated to latest commit". Default is true. See more information about the `checks` tool in the [docs](https://pr-agent-docs.codium.ai/tools/ci_feedback/).
    rajdip-b commented 2 weeks ago

    :tada: This PR is included in version 2.5.0 :tada:

    The release is available on GitHub release

    Your semantic-release bot :package::rocket: