projects

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 11 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 projects owns Core Projects and their API keys. A Project is one tenant with its own execution scope and assets; its API keys authenticate the public API as that Project. Archiving a Project revokes its keys and keeps its assets.

Index

Constants

View Source
const (
	ProjectNameMaxLength = 128
	KeyNameMaxLength     = 80
)

Display name limits, in Unicode code points. They are separate from the sandbox node name limit, which counts bytes.

View Source
const MaxListLimit = 100

MaxListLimit bounds one page of Projects or API keys.

Variables

View Source
var (
	// ErrNotFound reports a missing Project, key or list cursor, including a
	// malformed identifier.
	ErrNotFound = errors.New("project or API key not found")
	// ErrInvalidInput reports a malformed identifier for a new Project or key,
	// or a list page size outside 1..MaxListLimit.
	ErrInvalidInput = errors.New("invalid project input")
	// ErrArchived reports an operation that needs an active Project.
	ErrArchived = errors.New("project is archived")
	// ErrExists reports a Project ID that is already in use.
	ErrExists = errors.New("project ID already exists")
	// ErrAPIKeyExists reports an API key ID that is already in use.
	ErrAPIKeyExists = errors.New("API key ID already exists")
)

Functions

This section is empty.

Types

type APIKey

type APIKey struct {
	ID        string     `json:"id" binding:"required"`
	ProjectID string     `json:"project_id" binding:"required"`
	Name      string     `json:"name" binding:"required"`
	Prefix    string     `json:"prefix" binding:"required"`
	CreatedAt time.Time  `json:"created_at" binding:"required"`
	RevokedAt *time.Time `json:"revoked_at" extensions:"x-nullable" binding:"required"`
}

APIKey is the safe metadata of a Project API key. Core stores only the secret's SHA-256 digest and its display prefix.

type ArchiveProject

type ArchiveProject struct {
	ID string
}

ArchiveProject archives a Project and revokes all of its keys. Its assets remain.

type Binding

type Binding struct {
	Project   Project
	Principal identity.Principal
}

Binding is a Project with the principal its API keys authenticate as.

type CreateAPIKey

type CreateAPIKey struct {
	ProjectID, ID, Name string
}

CreateAPIKey issues a new secret in an active Project. The caller chooses the key ID.

type CreateProject

type CreateProject struct {
	ID, Name string
}

CreateProject creates an empty Project. The caller chooses its ID.

type IssuedAPIKey

type IssuedAPIKey struct {
	APIKey
	Key string `json:"key" binding:"required"`
}

IssuedAPIKey carries the secret once, in the response that issues it.

type KeyBinding

type KeyBinding struct {
	Key       APIKey
	Principal identity.Principal
}

KeyBinding is an active key with the principal it authenticates as.

type KeyIssuanceTx

type KeyIssuanceTx interface {
	// LoadProject returns the state of the locked Project.
	LoadProject(ctx context.Context) (LockedProject, error)
	// ApplyAPIKey stores the key. An ID already in use returns
	// ErrAPIKeyExists; a malformed ID returns ErrInvalidInput.
	ApplyAPIKey(ctx context.Context, key NewAPIKey) (APIKey, error)
}

KeyIssuanceTx is one key issuance transaction.

type KeyPage

type KeyPage struct {
	Data    []APIKey `json:"data" binding:"required"`
	HasMore bool     `json:"has_more" binding:"required"`
}

KeyPage is one page of a Project's keys ordered by ID.

type ListQuery

type ListQuery struct {
	After     string
	Limit     int
	Ascending bool
}

ListQuery selects one page ordered by ID. After, when set, must name an existing entry of the list.

func (ListQuery) Validate

func (q ListQuery) Validate() error

Validate rejects a page size outside 1..MaxListLimit.

type LockedProject

type LockedProject struct {
	Archived bool
}

LockedProject is the state a key issuance decides on.

type NameError

type NameError struct {
	// MaxLength is the name's limit in Unicode code points.
	MaxLength int
}

NameError rejects a Project or key display name.

func (*NameError) Error

func (e *NameError) Error() string

type NewAPIKey

type NewAPIKey struct {
	ID, Name, Prefix string
	Digest           [sha256.Size]byte
}

NewAPIKey is a key to store: its display prefix and secret digest, never the secret.

type NewProject

type NewProject struct {
	ID, Name string
	// OrganizationID and ExternalProjectID form the execution scope the
	// Project's keys authenticate as, and SubjectID is their subject.
	OrganizationID, ExternalProjectID, SubjectID string
}

NewProject is a Project to store. The adapter allocates its tenant.

type Page

type Page struct {
	Data    []Project `json:"data" binding:"required"`
	HasMore bool      `json:"has_more" binding:"required"`
}

Page is one page of Projects ordered by ID.

type Project

type Project struct {
	ID             string     `json:"id" binding:"required"`
	Name           string     `json:"name" binding:"required"`
	CreatedAt      time.Time  `json:"created_at" binding:"required"`
	ArchivedAt     *time.Time `json:"archived_at" extensions:"x-nullable" binding:"required"`
	ActiveKeyCount int64      `json:"active_key_count" binding:"required"`
	TenantID       string     `json:"-"`
}

Project is a Core Project as administrators see it.

type Reader

type Reader interface {
	// GetProject returns ErrNotFound for a missing Project or malformed ID.
	GetProject(ctx context.Context, id string) (Binding, error)
	// ListProjects returns ErrNotFound when query.After names no Project.
	ListProjects(ctx context.Context, query ListQuery) (Page, error)
	// ListAPIKeys returns every key of the Project, including revoked keys. It
	// returns ErrNotFound for a missing Project or when query.After names no key
	// of this Project.
	ListAPIKeys(ctx context.Context, projectID string, query ListQuery) (KeyPage, error)
	// ResolveAPIKey returns the active key with this secret digest, in an
	// active Project, or ErrNotFound.
	ResolveAPIKey(ctx context.Context, digest [sha256.Size]byte) (KeyBinding, error)
	// APIKeyDigestExists reports whether any key, including a revoked key or a
	// key of an archived Project, has this secret digest.
	APIKeyDigestExists(ctx context.Context, digest [sha256.Size]byte) (bool, error)
}

Reader answers Project and key queries.

type RenameProject

type RenameProject struct {
	ID, Name string
}

RenameProject changes a Project's display name, archived or not.

type RevokeAPIKey

type RevokeAPIKey struct {
	ProjectID, ID string
}

RevokeAPIKey revokes one key. Revoking a revoked key succeeds.

type Service

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

Service runs the Project and key administration use cases. Reads go to the Reader directly.

func NewService

func NewService(storage Storage) (*Service, error)

func (*Service) ArchiveProject

func (s *Service) ArchiveProject(ctx context.Context, command ArchiveProject) (Project, error)

func (*Service) CreateAPIKey

func (s *Service) CreateAPIKey(ctx context.Context, command CreateAPIKey) (IssuedAPIKey, error)

func (*Service) CreateProject

func (s *Service) CreateProject(ctx context.Context, command CreateProject) (Project, error)

func (*Service) RenameProject

func (s *Service) RenameProject(ctx context.Context, command RenameProject) (Project, error)

func (*Service) RevokeAPIKey

func (s *Service) RevokeAPIKey(ctx context.Context, command RevokeAPIKey) error

type Storage

type Storage interface {
	// CreateProject stores the Project with a new tenant and its execution
	// scope. An ID already in use returns ErrExists; a malformed ID returns
	// ErrInvalidInput.
	CreateProject(ctx context.Context, project NewProject) (Project, error)
	// RenameProject returns ErrNotFound for a missing Project.
	RenameProject(ctx context.Context, id, name string) (Project, error)
	// ArchiveProject archives the Project and revokes all of its keys. Both are
	// idempotent. It returns ErrNotFound for a missing Project.
	ArchiveProject(ctx context.Context, id string) (Project, error)
	// WithKeyIssuance runs issue while it holds a shared lock on the Project, so
	// the Project cannot be archived until the new key commits. It returns
	// ErrNotFound for a missing Project without calling issue.
	WithKeyIssuance(ctx context.Context, projectID string, issue func(KeyIssuanceTx) error) error
	// RevokeAPIKey revokes one key of the Project, idempotently. It returns
	// ErrNotFound for a missing Project or a key of another Project.
	RevokeAPIKey(ctx context.Context, projectID, keyID string) error
}

Storage is the persistence the Project use cases write through. Each method runs in one transaction and records its administrator audit row in that transaction, from the source in the context; a missing or malformed source aborts the write.

Jump to

Keyboard shortcuts

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