secret

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package secret is the endpoint group of the secrets in the vaults of the controller: the vaults, the metadata of each key, and a write of a value. No method gives a value.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoVault is a vault that controller.secrets.vaults does not name.
	ErrNoVault = errors.New("vault not found")
	// ErrNoKey is a key that is not in its vault.
	ErrNoKey = errors.New("key not found")
)
View Source
var Group = endpoint.Register(endpoint.Define(
	"secret", "Manage the secrets in the vaults of the controller",
	endpoint.Area(area.Secrets),
	endpoint.Title("Secret Management API"),
	endpoint.Tag("secret_operations", "Secret",
		"The vaults of the controller and the metadata of their keys. No operation gives a value."),
	endpoint.CommandLong("A secret is a key in a vault of the controller. A request uses it as a\n"+
		"reference, secret://<vault>/<key>. These commands write a value and read the\n"+
		"metadata of each key. Only reveal shows a value, with secret:reveal, which\n"+
		"only the admin role has."),
	endpoint.SubDoc("vault", "Read the vaults of the controller"),
	endpoint.Uses[Deps](),
	endpoint.Get[VaultListInput, VaultListResponse]("vaults").
		Handle(VaultList).
		CommandSub("vault").
		Use("list").
		ID("GetSecretVaults").
		Describe("List the vaults").
		Explain("List each vault of controller.secrets.vaults, with its type, its targets "+
			"and whether it answers.").
		Returns("The vaults of the controller.").
		Command("List the vaults of the controller",
			"The list shows each vault of controller.secrets.vaults. A vault that does\n"+
				"not answer is a backend that the controller cannot reach now.").
		Example("").
		Prints(sampleVaults).
		Example("--json"),
	endpoint.Get[ListInput, ListResponse]("list").
		Handle(List).
		Key("vault").
		ID("GetSecrets").
		Describe("List the keys of a vault").
		Explain("List the metadata of each key of a vault: its version, when it changed "+
			"and who changed it. The list has no value.").
		Returns("The keys of the vault.").
		Command("List the keys of a vault",
			"The list shows the metadata of each key, and no value. A request uses a\n"+
				"key as secret://<vault>/<key>.").
		Example("--vault default").
		Prints(sampleList).
		Example("--vault default --json").
		Fails("a vault name that is not letters, digits, - or _", ListInput{Vault: "a.b"}).
		Fails("a vault name over 64 characters", ListInput{Vault: long(65)}).
		Errors(noVault404),
	endpoint.Get[GetInput, Info]("get").
		Handle(Get).
		Key("vault", "key").
		ID("GetSecret").
		Describe("Get the metadata of a key").
		Explain("Get the version of a key, when it changed and who changed it. "+
			"The answer has no value.").
		Returns("The metadata of the key.").
		Command("Get the metadata of a key", "The command shows the metadata of the key, and never its value.").
		Example("--vault default --key registry-token").
		Prints(sampleInfo).
		Example("--vault default --key registry-token --json").
		Fails("a vault name that is not letters, digits, - or _", GetInput{Vault: "a.b", Key: "k"}).
		Fails("a vault name over 64 characters", GetInput{Vault: long(65), Key: "k"}).
		Fails("a key that is not letters, digits, - or _", GetInput{Vault: "default", Key: "a.b"}).
		Fails("a key over 128 characters", GetInput{Vault: "default", Key: long(129)}).
		Errors(noVault404, endpoint.NotFound(ErrNoKey, "The vault has no key with that name.")),
	endpoint.Get[RevealInput, Value]("reveal").
		Handle(Reveal).
		Key("vault", "key").
		Action("value").
		Permission(types.PermSecretReveal).
		AdminOnly().
		ID("GetSecretValue").
		Describe("Reveal the value of a key").
		Explain("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.").
		Returns("The value of the key.").
		Command("Print the value of a key",
			"The command prints only the value, with no heading and no trace line, so a\n"+
				"pipe gets the value. --json prints {\"value\": \"...\"}. The audit log\n"+
				"records each call. A request that uses the secret gives its reference,\n"+
				"secret://<vault>/<key>, not the value.").
		Example("--vault default --key registry-token").
		Prints(sampleValue).
		Example("--vault default --key registry-token --json").
		Fails("a vault name that is not letters, digits, - or _", RevealInput{Vault: "a.b", Key: "k"}).
		Fails("a vault name over 64 characters", RevealInput{Vault: long(65), Key: "k"}).
		Fails("a key that is not letters, digits, - or _", RevealInput{Vault: "default", Key: "a.b"}).
		Fails("a key over 128 characters", RevealInput{Vault: "default", Key: long(129)}).
		Errors(noVault404, endpoint.NotFound(ErrNoKey, "The vault has no key with that name.")),
	endpoint.Put[UpdateInput, Info]("update").
		Handle(Update).
		Key("vault", "key").
		ID("PutSecret").
		Describe("Write the value of a key").
		Explain("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.").
		Returns("The metadata of the key after the write.").
		Command("Write the value of a key",
			"The command reads the value from standard input with --value -, so the\n"+
				"value is not in the shell history. A request then uses the key as\n"+
				"secret://<vault>/<key>.").
		Example("--vault default --key registry-token --value -",
			"Read the value from standard input").
		Prints(sampleUpdate).
		Check("client secret get", "--vault default --key registry-token",
			"vault", "default", "key", "registry-token", "version", "{out.version}", "value", command.Absent).
		Check("client secret reveal", "--vault default --key registry-token", "value", "int-cli-value").
		Fails("no value", UpdateInput{Vault: "default", Key: "k"}).
		Fails("a value over 64 KiB", UpdateInput{Vault: "default", Key: "k", Body: body(65537)}).
		Fails("a vault name that is not letters, digits, - or _", UpdateInput{Vault: "a.b", Key: "k", Body: body(1)}).
		Fails("a vault name over 64 characters", UpdateInput{Vault: long(65), Key: "k", Body: body(1)}).
		Fails("a key that is not letters, digits, - or _", UpdateInput{Vault: "default", Key: "a.b", Body: body(1)}).
		Fails("a key over 128 characters", UpdateInput{Vault: "default", Key: long(129), Body: body(1)}).
		Errors(noVault404),
	endpoint.Delete[DeleteInput, struct{}]("delete").
		Handle(Delete).
		Key("vault", "key").
		ID("DeleteSecret").
		Describe("Delete a key").
		Explain("Delete a key from its vault. A request that uses its reference after "+
			"that fails.").
		Returns("The key is deleted.").
		Status(http.StatusNoContent).
		Command("Delete a key from a vault", "").
		Example("--vault default --key registry-token").
		CheckFails("client secret get", "--vault default --key registry-token", "not_found").
		Fails("a vault name that is not letters, digits, - or _", DeleteInput{Vault: "a.b", Key: "k"}).
		Fails("a vault name over 64 characters", DeleteInput{Vault: long(65), Key: "k"}).
		Fails("a key that is not letters, digits, - or _", DeleteInput{Vault: "default", Key: "a.b"}).
		Fails("a key over 128 characters", DeleteInput{Vault: "default", Key: long(129)}).
		Errors(noVault404, endpoint.NotFound(ErrNoKey, "The vault has no key with that name.")),
))

Group is the secret group's definition.

Functions

func Delete

func Delete(
	ctx context.Context,
	d Deps,
	in DeleteInput,
) (struct{}, error)

Delete deletes the key from the vault.

Types

type DeleteInput

type DeleteInput struct {
	Vault string `` /* 133-byte string literal not displayed */
	Key   string `` /* 140-byte string literal not displayed */
}

DeleteInput names the key to delete.

type Deps

type Deps struct {
	// Vaults are the vaults of controller.secrets.vaults. Nil when the
	// controller opened none; each method then has no vault.
	Vaults Vaults
}

Deps is what the group's handlers use.

type GetInput

type GetInput struct {
	Vault string `` /* 133-byte string literal not displayed */
	Key   string `` /* 140-byte string literal not displayed */
}

GetInput names one key of a vault.

type Info

type Info struct {
	Vault   string    `json:"vault"   doc:"The name of the vault."                                          example:"default"              table:"-"`
	Key     string    `json:"key"     doc:"The name of the key."                                            example:"registry-token"`
	Version int64     `json:"version" doc:"1 for the first value of the key, and one more for each update." example:"3"`
	Changed time.Time `` /* 139-byte string literal not displayed */
	By      string    `` /* 148-byte string literal not displayed */
	// contains filtered or unexported fields
}

Info is the metadata of one key. It has no value: no method gives one.

func Get

func Get(
	ctx context.Context,
	d Deps,
	in GetInput,
) (Info, error)

Get is the metadata of one key, and not its value.

func Update

func Update(
	ctx context.Context,
	d Deps,
	in UpdateInput,
) (Info, error)

Update writes the value as the next version of the key, and records the subject of the token as who changed it. The answer is the metadata.

type ListInput

type ListInput struct {
	Vault string `` /* 127-byte string literal not displayed */
}

ListInput names the vault whose keys to list.

type ListResponse

type ListResponse struct {
	Items      []Info `` /* 174-byte string literal not displayed */
	TotalItems int    `` /* 186-byte string literal not displayed */
	// contains filtered or unexported fields
}

ListResponse is the metadata of each key of a vault.

func List

func List(
	ctx context.Context,
	d Deps,
	in ListInput,
) (ListResponse, error)

List is the metadata of each key of a vault, and no value.

type RevealInput

type RevealInput struct {
	Vault string `` /* 133-byte string literal not displayed */
	Key   string `` /* 140-byte string literal not displayed */
}

RevealInput names the key whose value to reveal.

type UpdateInput

type UpdateInput struct {
	Vault string        `` /* 133-byte string literal not displayed */
	Key   string        `` /* 140-byte string literal not displayed */
	Body  UpdateRequest `json:"body"  in:"body" validate:"required"`
}

UpdateInput is the key to write, and its new value.

type UpdateRequest

type UpdateRequest struct {
	Value secretvalue.Value `json:"value" validate:"required,max=65536" doc:"The value of the key, which no method gives back"`
	// contains filtered or unexported fields
}

UpdateRequest is the value of a key. The API never gives it back.

type Value

type Value struct {
	Value string `json:"value" doc:"The value of the key." example:"glpat-xxxxxxxxxxxxxxxxxxxx" render:"body"`
	// contains filtered or unexported fields
}

Value is the value of a key: the answer of reveal only. The CLI prints it as it is, for a pipe.

func Reveal

func Reveal(
	ctx context.Context,
	d Deps,
	in RevealInput,
) (Value, error)

Reveal is the value of one key: the one method that gives a value. The route checks secret:reveal; the audit log records the call by its path, and the value goes only into the answer.

type VaultInfo

type VaultInfo struct {
	Name    string   `json:"name"    doc:"The name of the vault, as a reference gives it."             example:"default"`
	Type    string   `json:"type"    doc:"The type of the vault, such as nats."                        example:"nats"`
	Targets []string `json:"targets" doc:"The targets that its secrets can go to. Empty is each host."                   empty:"each host"`
	Answers bool     `json:"answers" doc:"Whether the vault answered a list of its keys."              example:"true"`
}

VaultInfo is one vault of controller.secrets.vaults.

type VaultListInput

type VaultListInput struct{}

VaultListInput is the input of vault list, which has none.

type VaultListResponse

type VaultListResponse struct {
	Items      []VaultInfo `` /* 144-byte string literal not displayed */
	TotalItems int         `` /* 156-byte string literal not displayed */
	// contains filtered or unexported fields
}

VaultListResponse is each vault of the controller.

func VaultList

func VaultList(
	ctx context.Context,
	d Deps,
	_ VaultListInput,
) (VaultListResponse, error)

VaultList is each vault of the controller, with its type, its targets and whether it answers a list of its keys.

type Vaults

type Vaults interface {
	Names() []string
	Get(name string) (vault.Vault, bool)
	Spec(name string) (vault.Spec, bool)
}

Vaults are the vaults of the controller, by name. A *vault.Set is one.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL