mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add bulk user secret import endpoint and SDK client (PLAT-240) (#26724)
Adds `POST /api/v2/users/{user}/secrets/batch` and
`codersdk.Client.ImportUserSecrets` to import env, JSON, or YAML secrets
atomically. The endpoint validates each entry, rolls back the full batch
on conflicts or limits, omits secret values from responses and audit
logs, and imports keys that cannot be injected as environment variables
with an empty `env_name`.
Part of the [PLAT-240 bulk secret import
stack](https://linear.app/codercom/issue/PLAT-240). Reviewed and updated
by Coder Agents on behalf of @dylanhuff-at-coder.
This commit is contained in:
Generated
+95
@@ -11027,6 +11027,73 @@ const docTemplate = `{
|
||||
]
|
||||
}
|
||||
},
|
||||
"/api/v2/users/{user}/secrets/batch": {
|
||||
"post": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Secrets"
|
||||
],
|
||||
"summary": "Import user secrets from a file",
|
||||
"operationId": "import-user-secrets-from-a-file",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "User ID, username, or me",
|
||||
"name": "user",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"description": "Import secrets request",
|
||||
"name": "request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/codersdk.ImportUserSecretsRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": "Created",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/codersdk.UserSecret"
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/codersdk.Response"
|
||||
}
|
||||
},
|
||||
"409": {
|
||||
"description": "Conflict",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/codersdk.Response"
|
||||
}
|
||||
},
|
||||
"413": {
|
||||
"description": "Request Entity Too Large",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/codersdk.Response"
|
||||
}
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"CoderSessionToken": []
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/api/v2/users/{user}/secrets/{name}": {
|
||||
"get": {
|
||||
"produces": [
|
||||
@@ -20578,6 +20645,21 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"codersdk.ImportUserSecretsRequest": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"content",
|
||||
"format"
|
||||
],
|
||||
"properties": {
|
||||
"content": {
|
||||
"type": "string"
|
||||
},
|
||||
"format": {
|
||||
"$ref": "#/definitions/codersdk.SecretsFileFormat"
|
||||
}
|
||||
}
|
||||
},
|
||||
"codersdk.InboxNotification": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -23647,6 +23729,19 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"codersdk.SecretsFileFormat": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"env",
|
||||
"json",
|
||||
"yaml"
|
||||
],
|
||||
"x-enum-varnames": [
|
||||
"SecretsFileFormatEnv",
|
||||
"SecretsFileFormatJSON",
|
||||
"SecretsFileFormatYAML"
|
||||
]
|
||||
},
|
||||
"codersdk.ServerSentEvent": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
Generated
+82
@@ -9780,6 +9780,67 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"/api/v2/users/{user}/secrets/batch": {
|
||||
"post": {
|
||||
"consumes": ["application/json"],
|
||||
"produces": ["application/json"],
|
||||
"tags": ["Secrets"],
|
||||
"summary": "Import user secrets from a file",
|
||||
"operationId": "import-user-secrets-from-a-file",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "User ID, username, or me",
|
||||
"name": "user",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"description": "Import secrets request",
|
||||
"name": "request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/codersdk.ImportUserSecretsRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": "Created",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/codersdk.UserSecret"
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/codersdk.Response"
|
||||
}
|
||||
},
|
||||
"409": {
|
||||
"description": "Conflict",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/codersdk.Response"
|
||||
}
|
||||
},
|
||||
"413": {
|
||||
"description": "Request Entity Too Large",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/codersdk.Response"
|
||||
}
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"CoderSessionToken": []
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/api/v2/users/{user}/secrets/{name}": {
|
||||
"get": {
|
||||
"produces": ["application/json"],
|
||||
@@ -18738,6 +18799,18 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"codersdk.ImportUserSecretsRequest": {
|
||||
"type": "object",
|
||||
"required": ["content", "format"],
|
||||
"properties": {
|
||||
"content": {
|
||||
"type": "string"
|
||||
},
|
||||
"format": {
|
||||
"$ref": "#/definitions/codersdk.SecretsFileFormat"
|
||||
}
|
||||
}
|
||||
},
|
||||
"codersdk.InboxNotification": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -21682,6 +21755,15 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"codersdk.SecretsFileFormat": {
|
||||
"type": "string",
|
||||
"enum": ["env", "json", "yaml"],
|
||||
"x-enum-varnames": [
|
||||
"SecretsFileFormatEnv",
|
||||
"SecretsFileFormatJSON",
|
||||
"SecretsFileFormatYAML"
|
||||
]
|
||||
},
|
||||
"codersdk.ServerSentEvent": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
Reference in New Issue
Block a user