Secret
c.Secret calls the API's Secret group. The vaults of the controller and the
metadata of their keys. No operation gives a value.
Methods
| Method | Returns | Permission | Description |
|---|---|---|---|
Vaults(ctx) | *Response[VaultListResponse] | secret:read | List the vaults. |
List(ctx, vault) | *Response[SecretListResponse] | secret:read | List the keys of a vault. |
Get(ctx, vault, key) | *Response[SecretInfo] | secret:read | Get the metadata of a key. |
Update(ctx, input) | *Response[SecretInfo] | secret:write | Write the value of a key. |
Delete(ctx, vault, key) | error | secret:write | Delete a key. |
Reveal(ctx, vault, key) | *Response[SecretValue] | secret:reveal | Reveal the value of a key. |
Vaults
func (s *SecretService) Vaults(
ctx context.Context,
) (*Response[VaultListResponse], error)
List the vaults.
List each vault of controller.secrets.vaults, with its type, its targets and whether it answers.
It sends GET /api/secret, and needs the permission secret:read.
The examples of the method's definition:
List the vaults, go run secret.go vaults:
resp, err := c.Secret.Vaults(ctx)
List
func (s *SecretService) List(
ctx context.Context,
vault string,
) (*Response[SecretListResponse], error)
List the keys of a vault.
List the metadata of each key of a vault: its version, when it changed and who changed it. The list has no value.
It sends GET /api/secret/{vault}, and needs the permission secret:read.
The examples of the method's definition:
List the keys of a vault, go run secret.go list:
resp, err := c.Secret.List(ctx, "default")
Get
func (s *SecretService) Get(
ctx context.Context,
vault string,
key string,
) (*Response[SecretInfo], error)
Get the metadata of a key.
Get the version of a key, when it changed and who changed it. The answer has no value.
It sends GET /api/secret/{vault}/{key}, and needs the permission
secret:read.
The examples of the method's definition:
Get the metadata of a key, go run secret.go get:
resp, err := c.Secret.Get(ctx, "default", "registry-token")
Update
func (s *SecretService) Update(
ctx context.Context,
input SecretUpdateInput,
) (*Response[SecretInfo], error)
Write the value of a key.
Write a value as the next version of a key, or as version 1 of a new key. The answer is the metadata of the key. The API never gives the value back.
It sends PUT /api/secret/{vault}/{key}, and needs the permission
secret:write.
The examples of the method's definition:
Read the value from standard input, go run secret.go update:
resp, err := c.Secret.Update(ctx, client.SecretUpdateInput{
Key: "registry-token",
Value: "-",
Vault: "default",
})
Delete
func (s *SecretService) Delete(
ctx context.Context,
vault string,
key string,
) error
Delete a key.
Delete a key from its vault. A request that uses its reference after that fails.
It sends DELETE /api/secret/{vault}/{key}, and needs the permission
secret:write.
The examples of the method's definition:
Delete a key, go run secret.go delete:
err := c.Secret.Delete(ctx, "default", "registry-token")
Reveal
func (s *SecretService) Reveal(
ctx context.Context,
vault string,
key string,
) (*Response[SecretValue], error)
Reveal the value of a key.
Get the value of a key, for a tool that needs the value itself. It is the one method that gives a value, and it needs secret:reveal, which only the admin role has. The audit log records each call, with the vault, the key and the caller, and never the value.
It sends GET /api/secret/{vault}/{key}/value, and needs the permission
secret:reveal.
The examples of the method's definition:
Reveal the value of a key, go run secret.go reveal:
resp, err := c.Secret.Reveal(ctx, "default", "registry-token")
Types
The fields of each type are the properties of its schema in the API's spec.
SecretInfo
| Field | Type | Description |
|---|---|---|
By | string | Who did the last update, or empty when it is not known. |
Changed | time.Time | When the last update occurred. |
Key | string | The name of the key. |
Vault | string | The name of the vault. |
Version | int64 | 1 for the first value of the key, and one more for each update. |
SecretListResponse
| Field | Type | Description |
|---|---|---|
Items | []SecretInfo | The keys of the vault, sorted by key. |
TotalItems | int | The number of keys. |
SecretUpdateInput
| Field | Type | Description |
|---|---|---|
Vault | string | The vault of the path. The name of the vault, such as default. |
Key | string | The key of the path. The name of the key, such as registry-token. |
Value | string | The value of the key, which no method gives back. A secret: a reference, secret:// |
SecretValue
| Field | Type | Description |
|---|---|---|
Value | string | The value of the key. |
VaultInfo
| Field | Type | Description |
|---|---|---|
Answers | bool | Whether the vault answered a list of its keys. |
Name | string | The name of the vault, as a reference gives it. |
Targets | []string | The targets that its secrets can go to. Empty is each host. |
Type | string | The type of the vault, such as nats. |
VaultListResponse
| Field | Type | Description |
|---|---|---|
Items | []VaultInfo | The vaults of the controller. |
TotalItems | int | The number of vaults. |
Example
examples/sdk/client/secret.go
runs each example of this page. With no argument, it lists them.