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
- Variables
- type APIKey
- type ArchiveProject
- type Binding
- type CreateAPIKey
- type CreateProject
- type IssuedAPIKey
- type KeyBinding
- type KeyIssuanceTx
- type KeyPage
- type ListQuery
- type LockedProject
- type NameError
- type NewAPIKey
- type NewProject
- type Page
- type Project
- type Reader
- type RenameProject
- type RevokeAPIKey
- type Service
- func (s *Service) ArchiveProject(ctx context.Context, command ArchiveProject) (Project, error)
- func (s *Service) CreateAPIKey(ctx context.Context, command CreateAPIKey) (IssuedAPIKey, error)
- func (s *Service) CreateProject(ctx context.Context, command CreateProject) (Project, error)
- func (s *Service) RenameProject(ctx context.Context, command RenameProject) (Project, error)
- func (s *Service) RevokeAPIKey(ctx context.Context, command RevokeAPIKey) error
- type Storage
Constants ¶
const ( ProjectNameMaxLength = 128 KeyNameMaxLength = 80 )
Display name limits, in Unicode code points. They are separate from the sandbox node name limit, which counts bytes.
const MaxListLimit = 100
MaxListLimit bounds one page of Projects or API keys.
Variables ¶
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"`
ProjectID string `json:"project_id"`
Name string `json:"name"`
Prefix string `json:"prefix"`
CreatedAt time.Time `json:"created_at"`
RevokedAt *time.Time `json:"revoked_at"`
}
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 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 ¶
IssuedAPIKey carries the secret once, in the response that issues it.
type KeyBinding ¶
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 ListQuery ¶
ListQuery selects one page ordered by ID. After, when set, must name an existing entry of the list.
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.
type NewAPIKey ¶
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 Project ¶
type Project struct {
ID string `json:"id"`
Name string `json:"name"`
CreatedAt time.Time `json:"created_at"`
ArchivedAt *time.Time `json:"archived_at"`
ActiveKeyCount int64 `json:"active_key_count"`
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 (*Service) ArchiveProject ¶
func (*Service) CreateAPIKey ¶
func (s *Service) CreateAPIKey(ctx context.Context, command CreateAPIKey) (IssuedAPIKey, error)
func (*Service) CreateProject ¶
func (*Service) RenameProject ¶
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.