Skip to main content

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​

MethodReturnsPermissionDescription
Vaults(ctx)*Response[VaultListResponse]secret:readList the vaults.
List(ctx, vault)*Response[SecretListResponse]secret:readList the keys of a vault.
Get(ctx, vault, key)*Response[SecretInfo]secret:readGet the metadata of a key.
Update(ctx, input)*Response[SecretInfo]secret:writeWrite the value of a key.
Delete(ctx, vault, key)errorsecret:writeDelete a key.
Reveal(ctx, vault, key)*Response[SecretValue]secret:revealReveal 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​

FieldTypeDescription
BystringWho did the last update, or empty when it is not known.
Changedtime.TimeWhen the last update occurred.
KeystringThe name of the key.
VaultstringThe name of the vault.
Versionint641 for the first value of the key, and one more for each update.

SecretListResponse​

FieldTypeDescription
Items[]SecretInfoThe keys of the vault, sorted by key.
TotalItemsintThe number of keys.

SecretUpdateInput​

FieldTypeDescription
VaultstringThe vault of the path. The name of the vault, such as default.
KeystringThe key of the path. The name of the key, such as registry-token.
ValuestringThe value of the key, which no method gives back. A secret: a reference, secret:///, or the value.

SecretValue​

FieldTypeDescription
ValuestringThe value of the key.

VaultInfo​

FieldTypeDescription
AnswersboolWhether the vault answered a list of its keys.
NamestringThe name of the vault, as a reference gives it.
Targets[]stringThe targets that its secrets can go to. Empty is each host.
TypestringThe type of the vault, such as nats.

VaultListResponse​

FieldTypeDescription
Items[]VaultInfoThe vaults of the controller.
TotalItemsintThe number of vaults.

Example​

examples/sdk/client/secret.go runs each example of this page. With no argument, it lists them.