feat: add user secrets SDK types and db2sdk converters (#24102)

Adds the SDK types and database-to-SDK conversion helpers for the user secrets feature.
This commit is contained in:
Zach
2026-04-08 16:48:41 -06:00
committed by GitHub
parent 506fba9ebf
commit 9b91af8ab7
3 changed files with 122 additions and 0 deletions
+38
View File
@@ -1715,3 +1715,41 @@ func ChatDiffStatus(chatID uuid.UUID, status *database.ChatDiffStatus) codersdk.
return result
}
// UserSecret converts a database ListUserSecretsRow (metadata only,
// no value) to an SDK UserSecret.
func UserSecret(secret database.ListUserSecretsRow) codersdk.UserSecret {
return codersdk.UserSecret{
ID: secret.ID,
Name: secret.Name,
Description: secret.Description,
EnvName: secret.EnvName,
FilePath: secret.FilePath,
CreatedAt: secret.CreatedAt,
UpdatedAt: secret.UpdatedAt,
}
}
// UserSecretFromFull converts a full database UserSecret row to an
// SDK UserSecret, omitting the value and encryption key ID.
func UserSecretFromFull(secret database.UserSecret) codersdk.UserSecret {
return codersdk.UserSecret{
ID: secret.ID,
Name: secret.Name,
Description: secret.Description,
EnvName: secret.EnvName,
FilePath: secret.FilePath,
CreatedAt: secret.CreatedAt,
UpdatedAt: secret.UpdatedAt,
}
}
// UserSecrets converts a slice of database ListUserSecretsRow to
// SDK UserSecret values.
func UserSecrets(secrets []database.ListUserSecretsRow) []codersdk.UserSecret {
result := make([]codersdk.UserSecret, 0, len(secrets))
for _, s := range secrets {
result = append(result, UserSecret(s))
}
return result
}
+41
View File
@@ -0,0 +1,41 @@
package codersdk
import (
"time"
"github.com/google/uuid"
)
// UserSecret represents a user secret's metadata. The secret value
// is never included in API responses.
type UserSecret struct {
ID uuid.UUID `json:"id" format:"uuid"`
Name string `json:"name"`
Description string `json:"description"`
EnvName string `json:"env_name"`
FilePath string `json:"file_path"`
CreatedAt time.Time `json:"created_at" format:"date-time"`
UpdatedAt time.Time `json:"updated_at" format:"date-time"`
}
// CreateUserSecretRequest is the payload for creating a new user
// secret. Name and Value are required. All other fields are optional
// and default to empty string.
type CreateUserSecretRequest struct {
Name string `json:"name"`
Value string `json:"value"`
Description string `json:"description,omitempty"`
EnvName string `json:"env_name,omitempty"`
FilePath string `json:"file_path,omitempty"`
}
// UpdateUserSecretRequest is the payload for partially updating a
// user secret. At least one field must be non-nil. Pointer fields
// distinguish "not sent" (nil) from "set to empty string" (pointer
// to empty string).
type UpdateUserSecretRequest struct {
Value *string `json:"value,omitempty"`
Description *string `json:"description,omitempty"`
EnvName *string `json:"env_name,omitempty"`
FilePath *string `json:"file_path,omitempty"`
}
+43
View File
@@ -2811,6 +2811,20 @@ export interface CreateUserRequestWithOrgs {
readonly service_account?: boolean;
}
// From codersdk/usersecrets.go
/**
* CreateUserSecretRequest is the payload for creating a new user
* secret. Name and Value are required. All other fields are optional
* and default to empty string.
*/
export interface CreateUserSecretRequest {
readonly name: string;
readonly value: string;
readonly description?: string;
readonly env_name?: string;
readonly file_path?: string;
}
// From codersdk/workspaces.go
export type CreateWorkspaceBuildReason =
| "cli"
@@ -7686,6 +7700,20 @@ export interface UpdateUserQuietHoursScheduleRequest {
readonly schedule: string;
}
// From codersdk/usersecrets.go
/**
* UpdateUserSecretRequest is the payload for partially updating a
* user secret. At least one field must be non-nil. Pointer fields
* distinguish "not sent" (nil) from "set to empty string" (pointer
* to empty string).
*/
export interface UpdateUserSecretRequest {
readonly value?: string;
readonly description?: string;
readonly env_name?: string;
readonly file_path?: string;
}
// From codersdk/workspaces.go
export interface UpdateWorkspaceACL {
/**
@@ -8038,6 +8066,21 @@ export interface UserRoles {
readonly organization_roles: Record<string, string[]>;
}
// From codersdk/usersecrets.go
/**
* UserSecret represents a user secret's metadata. The secret value
* is never included in API responses.
*/
export interface UserSecret {
readonly id: string;
readonly name: string;
readonly description: string;
readonly env_name: string;
readonly file_path: string;
readonly created_at: string;
readonly updated_at: string;
}
// From codersdk/users.go
export type UserStatus = "active" | "dormant" | "suspended";