Skip to content

Modern Docker Management, Designed for Everyone

3.9 KB
Raw Blame
package apikey

import "time"

// PermissionGrant is one permission granted to an API key, optionally scoped
// to a single environment. Omit EnvironmentID for a global grant.
type PermissionGrant struct {
	Permission    string  `json:"permission" minLength:"1" doc:"Permission string" example:"containers:list"`
	EnvironmentID *string `json:"environmentId,omitempty" doc:"Environment ID to scope the grant to; omit for a global grant"`
}

// CreateApiKey represents the request body for creating an API key.
// Fields tagged with unorm and trim are trimmed and normalized to Unicode NFC.
type CreateApiKey struct {
	Name        string            `json:"name" minLength:"1" maxLength:"255" doc:"Name of the API key" example:"My API Key" unorm:"nfc" trim:"true"`
	Description *string           `json:"description,omitempty" maxLength:"1000" doc:"Optional description of the API key" unorm:"nfc" trim:"true"`
	ExpiresAt   *time.Time        `json:"expiresAt,omitempty" doc:"Optional expiration date for the API key"`
	Permissions []PermissionGrant `json:"permissions" minItems:"1" doc:"Permissions granted to this key. Cannot exceed the creator's own permissions."`
}

// CreateUserApiKey represents the request body for creating a personal API key.
// Personal keys carry no grants of their own; they inherit the owner's role
// permissions at authentication time.
type CreateUserApiKey struct {
	Name        string     `json:"name" minLength:"1" maxLength:"255" doc:"Name of the API key" example:"My API Key" unorm:"nfc" trim:"true"`
	Description *string    `json:"description,omitempty" maxLength:"1000" doc:"Optional description of the API key" unorm:"nfc" trim:"true"`
	ExpiresAt   *time.Time `json:"expiresAt,omitempty" doc:"Optional expiration date for the API key"`
}

// ApiKey represents an API key without the secret.
type ApiKey struct {
	ID          string            `json:"id" doc:"Unique identifier of the API key"`
	Name        string            `json:"name" doc:"Name of the API key"`
	Description *string           `json:"description,omitempty" doc:"Description of the API key"`
	KeyPrefix   string            `json:"keyPrefix" doc:"Prefix of the API key for identification"`
	UserID      *string           `json:"userId,omitempty" doc:"ID of the user who owns the API key"`
	Kind        string            `json:"kind" doc:"Key kind: 'scoped' keys use their own permission grants, 'personal' keys inherit the owner's role permissions"`
	IsStatic    bool              `json:"isStatic" doc:"Whether the API key is environment-managed and protected from deletion"`
	IsBootstrap bool              `json:"isBootstrap" doc:"Whether the API key is currently referenced by an environment as its pairing key (locked from manual edit / delete)"`
	ExpiresAt   *time.Time        `json:"expiresAt,omitempty" doc:"Expiration date of the API key"`
	LastUsedAt  *time.Time        `json:"lastUsedAt,omitempty" doc:"Last time the API key was used"`
	CreatedAt   time.Time         `json:"createdAt" doc:"Creation timestamp"`
	UpdatedAt   *time.Time        `json:"updatedAt,omitempty" doc:"Last update timestamp"`
	Permissions []PermissionGrant `json:"permissions" doc:"Permissions held by this key"`
}

// ApiKeyCreatedDto represents a newly created API key with the full secret.
type ApiKeyCreatedDto struct {
	ApiKey

	Key string `json:"key" doc:"The full API key secret (only shown once)"`
}

// UpdateApiKey represents the request body for updating an API key.
type UpdateApiKey struct {
	Name        *string           `json:"name,omitzero" maxLength:"255" doc:"New name for the API key" unorm:"nfc" trim:"true"`
	Description *string           `json:"description,omitzero" maxLength:"1000" doc:"New description for the API key" unorm:"nfc" trim:"true"`
	ExpiresAt   *time.Time        `json:"expiresAt,omitzero" doc:"New expiration date for the API key"`
	Permissions []PermissionGrant `json:"permissions,omitzero" doc:"Replace the key's permission grants. Omit to leave unchanged. Cannot exceed the updater's own permissions."`
}