access

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hash

func Hash(raw string) string

Hash returns the persisted key hash.

func NormalizeKind

func NormalizeKind(kind string) string

NormalizeKind defaults empty kind to service_account.

func Prefix

func Prefix(raw string) string

Prefix returns a short display prefix for an API key.

func ValidateKindRules

func ValidateKindRules(kind, ownerUserID, projectID, environmentID string) error

ValidateKindRules enforces personal vs service_account invariants.

Types

type APIKey

type APIKey struct {
	ID             string    `json:"id"`
	ProjectID      string    `json:"project_id,omitempty"`
	OrganizationID string    `json:"organization_id"`
	EnvironmentID  string    `json:"environment_id,omitempty"`
	Name           string    `json:"name"`
	Kind           string    `json:"kind"`
	OwnerUserID    string    `json:"owner_user_id,omitempty"`
	KeyPrefix      string    `json:"key_prefix"`
	Key            string    `json:"key,omitempty"` // plaintext only on create
	CreatedAt      time.Time `json:"created_at"`
}

APIKey is the write-model virtual API key.

func CreateAPIKey

func CreateAPIKey(
	ctx context.Context,
	repo APIKeyRepository,
	projects ProjectOrgChecker,
	envs EnvironmentProjectChecker,
	id, orgID, kind, ownerUserID, projectID, environmentID, name, rawKey string,
) (*APIKey, error)

CreateAPIKey validates kind/project rules and persists the key.

func NewAPIKey

func NewAPIKey(id, orgID, kind, ownerUserID, projectID, environmentID, name, rawKey string, now time.Time) (*APIKey, error)

NewAPIKey builds a validated key entity (does not check project membership).

type APIKeyRepository

type APIKeyRepository interface {
	ListByProject(ctx context.Context, projectID string) ([]APIKey, error)
	ListByOrg(ctx context.Context, orgID string) ([]APIKey, error)
	Get(ctx context.Context, keyID string) (*APIKey, error)
	Insert(ctx context.Context, key APIKey, keyHash string) error
	Delete(ctx context.Context, keyID string) error
	OrgID(ctx context.Context, keyID string) (string, error)
}

APIKeyRepository persists write-model API keys.

type EnvironmentProjectChecker

type EnvironmentProjectChecker interface {
	EnvironmentBelongsToProject(ctx context.Context, environmentID, projectID, orgID string) error
}

EnvironmentProjectChecker verifies an environment belongs to a project in an org.

type KeyKind

type KeyKind string

KeyKind is a typed API key kind.

const (
	KeyKindPersonal       KeyKind = snapshot.KeyKindPersonal
	KeyKindServiceAccount KeyKind = snapshot.KeyKindServiceAccount
)

func ParseKeyKind

func ParseKeyKind(kind string) (KeyKind, error)

ParseKeyKind validates and returns a KeyKind. Empty defaults to service_account.

func (KeyKind) IsPersonal

func (k KeyKind) IsPersonal() bool

IsPersonal reports whether the kind is personal.

func (KeyKind) String

func (k KeyKind) String() string

type ProjectOrgChecker

type ProjectOrgChecker interface {
	ProjectBelongsToOrg(ctx context.Context, projectID, orgID string) error
}

ProjectOrgChecker verifies a project belongs to an organization.

Jump to

Keyboard shortcuts

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