For AI agents: the complete documentation index is at https://www.daytona.com/llms.txt. Append .md to any docs page URL to get it as Markdown.

Sign Up
Skip to Content

Secrets

type Secrets struct {
	// contains filtered or unexported fields
}

Secrets manages project secrets. Values are write-only and never retained. Obtain it from Client.Secrets.

Secrets.Delete

func (s *Secrets) Delete(ctx context.Context, name string) error

Delete deletes a secret by name. ErrNotFound is preserved.

Secrets.Get

func (s *Secrets) Get(ctx context.Context, name string) (*Secret, error)

Get fetches secret metadata by name. Values are never returned. ErrNotFound means the secret does not exist.

Secrets.GoString

func (s *Secrets) GoString() string

GoString returns a credential-free diagnostic name.

Secrets.List

func (s *Secrets) List(ctx context.Context, opts *ListSecretsOptions) (*Page[Secret], error)

List returns exactly one page of secret metadata, never secret values.

Secrets.ListAll

func (s *Secrets) ListAll(ctx context.Context, opts *ListSecretsOptions) iter.Seq2[Secret, error]

ListAll lazily traverses secret metadata pages, stopping on cancellation, errors, a repeated cursor, or when the consumer breaks.

Secrets.Set

func (s *Secrets) Set(ctx context.Context, name, value string, opts *SetSecretOptions) (*Secret, error)

Set creates or replaces a write-only secret and returns only metadata. A nonempty value and opts with nonempty AllowedDomains are required. Nil opts or invalid input returns ErrBadRequest before any request. Nil Description preserves stored metadata with one extra read (not atomic), unless IfNotExists is true. Required name and value remain positional to distinguish them from metadata.

Example:

client, err := daytona.New()
if err != nil {
	log.Fatal(err)
}
defer func() {
	if closeErr := client.Close(); closeErr != nil {
		log.Print(closeErr)
	}
}()

ctx := context.Background()
secret, err := client.Secrets().Set(ctx, "SERVICE_TOKEN", os.Getenv("SERVICE_TOKEN"), &daytona.SetSecretOptions{
	AllowedDomains: []string{"api.example.com"},
	IfNotExists:    true,
})
if err != nil {
	log.Fatal(err)
}
log.Print(secret.Name, secret.AllowedDomains) // Never contains the value.
if deleteErr := client.Secrets().Delete(ctx, secret.Name); deleteErr != nil {
	log.Print(deleteErr)
}

Secrets.String

func (s *Secrets) String() string

String returns a credential-free diagnostic name.

ListSecretsOptions

type ListSecretsOptions struct {
	// Cursor is the opaque continuation cursor.
	Cursor string
	// Limit is 1–200; zero uses the server default.
	Limit int
}

ListSecretsOptions selects one page of secret metadata.

SandboxSecretsInfo

type SandboxSecretsInfo struct {
	// Secrets names the attached project secrets.
	Secrets []string
	// DesiredRevision is the requested revision.
	DesiredRevision int64
	// ETag is the opaque token required by ReplaceSecrets.
	ETag string
	// AppliedRevision is nil until an applied revision is reported.
	AppliedRevision *int64
	// Status is the open apply-state vocabulary, such as pending or applied.
	Status string
	// Error is the server's apply failure explanation.
	Error string
	// CaptureStatus is the server's open secret-capture status vocabulary.
	CaptureStatus string
	// CaptureUnresolvedCount is nil unless an unresolved count was reported.
	CaptureUnresolvedCount *int32
}

SandboxSecretsInfo reports attached secret names and their asynchronous apply state. It never includes secret values.

Secret

type Secret struct {
	// Name is the project-unique secret name.
	Name string
	// AllowedDomains lists permitted HTTPS destination hosts.
	AllowedDomains []string
	// Description is nil when absent; a pointer to "" is an explicit empty description.
	Description *string
	// CreatedAt is the creation timestamp.
	CreatedAt time.Time
	// UpdatedAt is the metadata update timestamp.
	UpdatedAt time.Time
}

Secret contains caller-owned secret metadata, never the write-only value. Unknown server fields (including any value) are discarded at the boundary.

SetSecretOptions

type SetSecretOptions struct {
	// AllowedDomains is a required nonempty list of HTTPS hosts (exact or
	// "*.example.com"). ["*"] permits any verified HTTPS host, including an
	// attacker-controlled host. Domain syntax is checked by the API.
	AllowedDomains []string
	// Description replaces the description; a pointer to "" clears it.
	// Nil preserves the stored description via a non-atomic Get before Set.
	Description *string
	// IfNotExists sends If-None-Match: * and skips the description read.
	// An existing secret returns ErrSecretAlreadyExists.
	IfNotExists bool
}

SetSecretOptions controls replacement of a secret's value and metadata.