Skip to content
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

feat:Add /studio/v1/secrets endpoint for managing secrets in AI21 Studio API #78

Merged
merged 1 commit into from
Nov 26, 2024

Conversation

HavenDV
Copy link
Contributor

@HavenDV HavenDV commented Nov 26, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new endpoint for managing secrets in the AI21 Studio API, enabling users to retrieve, create, and delete secrets.
    • Added operations for GET, POST, and DELETE requests to handle secret management tasks effectively.
  • Bug Fixes

    • Improved error handling for validation issues across new operations.

Copy link

coderabbitai bot commented Nov 26, 2024

Walkthrough

The changes introduce a new endpoint /studio/v1/secrets to the AI21 Studio API, allowing for the management of secrets. This includes three operations: GET, POST, and DELETE. Each operation has specific parameters and responses, ensuring consistent error handling and functionality for retrieving, creating, and deleting secrets.

Changes

File Change Summary
src/libs/AI21/openapi.yaml Added new endpoint /studio/v1/secrets with operations: GET, POST, and DELETE for secret management.

Possibly related PRs

Suggested reviewers

  • github-actions

Poem

🐰 In the garden of secrets, we now can play,
With GET, POST, and DELETE, we brighten the day.
Hopping through code, with joy we will sing,
Managing secrets, oh what joy they bring! 🌼
So let’s celebrate this new API way,
With a twitch of our noses, hip-hip-hooray!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 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.

@github-actions github-actions bot enabled auto-merge November 26, 2024 12:45
@github-actions github-actions bot merged commit e2f4aa0 into main Nov 26, 2024
3 checks passed
@coderabbitai coderabbitai bot changed the title feat:@coderabbitai feat:Add /studio/v1/secrets endpoint for managing secrets in AI21 Studio API Nov 26, 2024
Copy link

@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: 4

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 39c93fe and cffe113.

⛔ Files ignored due to path filters (16)
  • src/libs/AI21/Generated/AI21.Ai21Api.g.cs is excluded by !**/generated/**
  • src/libs/AI21/Generated/AI21.IAi21Api.g.cs is excluded by !**/generated/**
  • src/libs/AI21/Generated/AI21.ISecretsClient.V1SecretStorage.g.cs is excluded by !**/generated/**
  • src/libs/AI21/Generated/AI21.ISecretsClient.V1SecretStorage2.g.cs is excluded by !**/generated/**
  • src/libs/AI21/Generated/AI21.ISecretsClient.V1SecretStorage3.g.cs is excluded by !**/generated/**
  • src/libs/AI21/Generated/AI21.ISecretsClient.g.cs is excluded by !**/generated/**
  • src/libs/AI21/Generated/AI21.Models.V1SecretStorageResponse.Json.g.cs is excluded by !**/generated/**
  • src/libs/AI21/Generated/AI21.Models.V1SecretStorageResponse.g.cs is excluded by !**/generated/**
  • src/libs/AI21/Generated/AI21.Models.V1SecretStorageResponse2.Json.g.cs is excluded by !**/generated/**
  • src/libs/AI21/Generated/AI21.Models.V1SecretStorageResponse2.g.cs is excluded by !**/generated/**
  • src/libs/AI21/Generated/AI21.Models.V1SecretStorageResponse3.Json.g.cs is excluded by !**/generated/**
  • src/libs/AI21/Generated/AI21.Models.V1SecretStorageResponse3.g.cs is excluded by !**/generated/**
  • src/libs/AI21/Generated/AI21.SecretsClient.V1SecretStorage.g.cs is excluded by !**/generated/**
  • src/libs/AI21/Generated/AI21.SecretsClient.V1SecretStorage2.g.cs is excluded by !**/generated/**
  • src/libs/AI21/Generated/AI21.SecretsClient.V1SecretStorage3.g.cs is excluded by !**/generated/**
  • src/libs/AI21/Generated/AI21.SecretsClient.g.cs is excluded by !**/generated/**
📒 Files selected for processing (1)
  • src/libs/AI21/openapi.yaml (1 hunks)

Comment on lines +395 to +424
delete:
tags:
- Secrets
summary: Delete Secret
operationId: v1_secret_storage
parameters:
- name: secret_name
in: query
required: true
schema:
title: Secret Name
type: string
- name: request_start_time
in: query
schema:
title: Request Start Time
type: integer
default: '1730898900272'
responses:
'200':
description: Successful Response
content:
application/json:
schema: { }
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve DELETE operation design

The current DELETE operation design can be improved:

  1. Resource identifier (secret_name) should be in the path, not query
  2. Missing appropriate status codes for different scenarios

Implement these improvements:

-   /studio/v1/secrets:
+   /studio/v1/secrets/{secret_name}:
    delete:
      tags:
        - Secrets
      summary: Delete Secret
      operationId: v1_secret_storage
      parameters:
-       - name: secret_name
-         in: query
+       - name: secret_name
+         in: path
          required: true
          schema:
            title: Secret Name
            type: string
      responses:
        '200':
          description: Successful Response
+         content:
+           application/json:
+             schema:
+               type: object
+               required:
+                 - status
+               properties:
+                 status:
+                   type: string
+                   enum: [success]
+       '404':
+         description: Secret not found
+         content:
+           application/json:
+             schema:
+               type: object
+               required:
+                 - error
+               properties:
+                 error:
+                   type: string
+                   enum: [secret_not_found]
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
delete:
tags:
- Secrets
summary: Delete Secret
operationId: v1_secret_storage
parameters:
- name: secret_name
in: query
required: true
schema:
title: Secret Name
type: string
- name: request_start_time
in: query
schema:
title: Request Start Time
type: integer
default: '1730898900272'
responses:
'200':
description: Successful Response
content:
application/json:
schema: { }
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
delete:
tags:
- Secrets
summary: Delete Secret
operationId: v1_secret_storage
parameters:
- name: secret_name
in: path
required: true
schema:
title: Secret Name
type: string
- name: request_start_time
in: query
schema:
title: Request Start Time
type: integer
default: '1730898900272'
responses:
'200':
description: Successful Response
content:
application/json:
schema:
type: object
required:
- status
properties:
status:
type: string
enum: [success]
'404':
description: Secret not found
content:
application/json:
schema:
type: object
required:
- error
properties:
error:
type: string
enum: [secret_not_found]
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'

Comment on lines +359 to +394
post:
tags:
- Secrets
summary: Save Secret
operationId: v1_secret_storage
parameters:
- name: secret_name
in: query
required: true
schema:
title: Secret Name
type: string
- name: secret_value
in: query
required: true
schema:
title: Secret Value
type: string
- name: request_start_time
in: query
schema:
title: Request Start Time
type: integer
default: '1730898900272'
responses:
'200':
description: Successful Response
content:
application/json:
schema: { }
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Security issues in POST operation design

Critical security concerns in the secret creation endpoint:

  1. Secret values are exposed in query parameters, which:
    • Appear in server logs
    • Are visible in browser history
    • May be cached by proxies
  2. Missing validation rules for secret names and values

Implement these security improvements:

    post:
      tags:
        - Secrets
      summary: Save Secret
      operationId: v1_secret_storage
-     parameters:
-       - name: secret_name
-         in: query
-         required: true
-         schema:
-           title: Secret Name
-           type: string
-       - name: secret_value
-         in: query
-         required: true
-         schema:
-           title: Secret Value
-           type: string
+     requestBody:
+       required: true
+       content:
+         application/json:
+           schema:
+             type: object
+             required:
+               - name
+               - value
+             properties:
+               name:
+                 type: string
+                 pattern: ^[a-zA-Z][a-zA-Z0-9_-]{1,64}$
+                 description: Secret name must start with a letter and contain only alphanumeric characters, underscores, and hyphens
+               value:
+                 type: string
+                 maxLength: 4096
+                 description: Secret value with maximum length of 4KB
+               description:
+                 type: string
+                 maxLength: 1024
+                 description: Optional description of the secret
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
post:
tags:
- Secrets
summary: Save Secret
operationId: v1_secret_storage
parameters:
- name: secret_name
in: query
required: true
schema:
title: Secret Name
type: string
- name: secret_value
in: query
required: true
schema:
title: Secret Value
type: string
- name: request_start_time
in: query
schema:
title: Request Start Time
type: integer
default: '1730898900272'
responses:
'200':
description: Successful Response
content:
application/json:
schema: { }
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
post:
tags:
- Secrets
summary: Save Secret
operationId: v1_secret_storage
requestBody:
required: true
content:
application/json:
schema:
type: object
required:
- name
- value
properties:
name:
type: string
pattern: ^[a-zA-Z][a-zA-Z0-9_-]{1,64}$
description: Secret name must start with a letter and contain only alphanumeric characters, underscores, and hyphens
value:
type: string
maxLength: 4096
description: Secret value with maximum length of 4KB
description:
type: string
maxLength: 1024
description: Optional description of the secret
responses:
'200':
description: Successful Response
content:
application/json:
schema: { }
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'

Comment on lines +335 to +358
get:
tags:
- Secrets
summary: Get Secret List
operationId: v1_secret_storage
parameters:
- name: request_start_time
in: query
schema:
title: Request Start Time
type: integer
default: '1730898900272'
responses:
'200':
description: Successful Response
content:
application/json:
schema: { }
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance GET operation with pagination and filtering

The GET operation for listing secrets lacks essential features for managing large sets of secrets:

  1. No pagination support
  2. No filtering capabilities
  3. No sorting options

Add pagination and filtering parameters:

    get:
      tags:
        - Secrets
      summary: Get Secret List
      operationId: v1_secret_storage
      parameters:
        - name: request_start_time
          in: query
          schema:
            title: Request Start Time
            type: integer
            default: '1730898900272'
+       - name: limit
+         in: query
+         schema:
+           type: integer
+           minimum: 1
+           maximum: 100
+           default: 20
+           description: Maximum number of secrets to return
+       - name: offset
+         in: query
+         schema:
+           type: integer
+           minimum: 0
+           default: 0
+           description: Number of secrets to skip
+       - name: name_prefix
+         in: query
+         schema:
+           type: string
+           description: Filter secrets by name prefix
+       - name: sort
+         in: query
+         schema:
+           type: string
+           enum: [name_asc, name_desc, created_at_asc, created_at_desc]
+           default: name_asc
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
get:
tags:
- Secrets
summary: Get Secret List
operationId: v1_secret_storage
parameters:
- name: request_start_time
in: query
schema:
title: Request Start Time
type: integer
default: '1730898900272'
responses:
'200':
description: Successful Response
content:
application/json:
schema: { }
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
get:
tags:
- Secrets
summary: Get Secret List
operationId: v1_secret_storage
parameters:
- name: request_start_time
in: query
schema:
title: Request Start Time
type: integer
default: '1730898900272'
- name: limit
in: query
schema:
type: integer
minimum: 1
maximum: 100
default: 20
description: Maximum number of secrets to return
- name: offset
in: query
schema:
type: integer
minimum: 0
default: 0
description: Number of secrets to skip
- name: name_prefix
in: query
schema:
type: string
description: Filter secrets by name prefix
- name: sort
in: query
schema:
type: string
enum: [name_asc, name_desc, created_at_asc, created_at_desc]
default: name_asc
responses:
'200':
description: Successful Response
content:
application/json:
schema: { }
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'

Comment on lines +334 to +424
/studio/v1/secrets:
get:
tags:
- Secrets
summary: Get Secret List
operationId: v1_secret_storage
parameters:
- name: request_start_time
in: query
schema:
title: Request Start Time
type: integer
default: '1730898900272'
responses:
'200':
description: Successful Response
content:
application/json:
schema: { }
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
post:
tags:
- Secrets
summary: Save Secret
operationId: v1_secret_storage
parameters:
- name: secret_name
in: query
required: true
schema:
title: Secret Name
type: string
- name: secret_value
in: query
required: true
schema:
title: Secret Value
type: string
- name: request_start_time
in: query
schema:
title: Request Start Time
type: integer
default: '1730898900272'
responses:
'200':
description: Successful Response
content:
application/json:
schema: { }
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
delete:
tags:
- Secrets
summary: Delete Secret
operationId: v1_secret_storage
parameters:
- name: secret_name
in: query
required: true
schema:
title: Secret Name
type: string
- name: request_start_time
in: query
schema:
title: Request Start Time
type: integer
default: '1730898900272'
responses:
'200':
description: Successful Response
content:
application/json:
schema: { }
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical issues in the secrets management endpoint specification

Several issues need to be addressed in the secrets management endpoint:

  1. Using the same operationId ('v1_secret_storage') for different operations will cause issues with code generation tools. Each operation should have a unique identifier.
  2. Success responses are defined with empty schemas (schema: {}), which could lead to inconsistent implementations.
  3. Missing operation descriptions and examples make the API harder to understand and use.

Apply these changes to improve the specification:

  /studio/v1/secrets:
    get:
      tags:
        - Secrets
      summary: Get Secret List
-     operationId: v1_secret_storage
+     operationId: v1_list_secrets
+     description: Retrieve a list of secret names available in the organization.
      # ... parameters ...
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
+               type: object
+               required:
+                 - secrets
+               properties:
+                 secrets:
+                   type: array
+                   items:
+                     type: string
+                   description: List of secret names
    post:
      tags:
        - Secrets
      summary: Save Secret
-     operationId: v1_secret_storage
+     operationId: v1_create_secret
+     description: Create or update a secret with the specified name and value.
      # ... parameters ...
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
+               type: object
+               required:
+                 - status
+               properties:
+                 status:
+                   type: string
+                   enum: [success]
    delete:
      tags:
        - Secrets
      summary: Delete Secret
-     operationId: v1_secret_storage
+     operationId: v1_delete_secret
+     description: Delete a secret by its name.
      # ... parameters ...
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
+               type: object
+               required:
+                 - status
+               properties:
+                 status:
+                   type: string
+                   enum: [success]
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/studio/v1/secrets:
get:
tags:
- Secrets
summary: Get Secret List
operationId: v1_secret_storage
parameters:
- name: request_start_time
in: query
schema:
title: Request Start Time
type: integer
default: '1730898900272'
responses:
'200':
description: Successful Response
content:
application/json:
schema: { }
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
post:
tags:
- Secrets
summary: Save Secret
operationId: v1_secret_storage
parameters:
- name: secret_name
in: query
required: true
schema:
title: Secret Name
type: string
- name: secret_value
in: query
required: true
schema:
title: Secret Value
type: string
- name: request_start_time
in: query
schema:
title: Request Start Time
type: integer
default: '1730898900272'
responses:
'200':
description: Successful Response
content:
application/json:
schema: { }
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
delete:
tags:
- Secrets
summary: Delete Secret
operationId: v1_secret_storage
parameters:
- name: secret_name
in: query
required: true
schema:
title: Secret Name
type: string
- name: request_start_time
in: query
schema:
title: Request Start Time
type: integer
default: '1730898900272'
responses:
'200':
description: Successful Response
content:
application/json:
schema: { }
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
/studio/v1/secrets:
get:
tags:
- Secrets
summary: Get Secret List
operationId: v1_list_secrets
description: Retrieve a list of secret names available in the organization.
parameters:
- name: request_start_time
in: query
schema:
title: Request Start Time
type: integer
default: '1730898900272'
responses:
'200':
description: Successful Response
content:
application/json:
schema:
type: object
required:
- secrets
properties:
secrets:
type: array
items:
type: string
description: List of secret names
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
post:
tags:
- Secrets
summary: Save Secret
operationId: v1_create_secret
description: Create or update a secret with the specified name and value.
parameters:
- name: secret_name
in: query
required: true
schema:
title: Secret Name
type: string
- name: secret_value
in: query
required: true
schema:
title: Secret Value
type: string
- name: request_start_time
in: query
schema:
title: Request Start Time
type: integer
default: '1730898900272'
responses:
'200':
description: Successful Response
content:
application/json:
schema:
type: object
required:
- status
properties:
status:
type: string
enum: [success]
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
delete:
tags:
- Secrets
summary: Delete Secret
operationId: v1_delete_secret
description: Delete a secret by its name.
parameters:
- name: secret_name
in: query
required: true
schema:
title: Secret Name
type: string
- name: request_start_time
in: query
schema:
title: Request Start Time
type: integer
default: '1730898900272'
responses:
'200':
description: Successful Response
content:
application/json:
schema:
type: object
required:
- status
properties:
status:
type: string
enum: [success]
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'

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.

1 participant