Documentation
¶
Overview ¶
Package identity owns gateway API-key identity and persistence.
Index ¶
Constants ¶
const ( // StorageSchemaVersion identifies the only supported identity schema. StorageSchemaVersion = 1 // StoragePrefix is the identity v1 storage namespace. StoragePrefix = "identity:v1:" )
Variables ¶
var ( // ErrMissingID reports an identity without a durable ID. ErrMissingID = errors.New("missing id") // ErrMissingHash reports an identity without a key hash. ErrMissingHash = errors.New("missing hash") // ErrMissingScopes reports an identity without any granted scope. ErrMissingScopes = errors.New("missing scopes") // ErrInvalidName reports an invalid identity name. ErrInvalidName = errors.New("invalid name: must be 1-255 characters") // ErrInvalidScope reports an empty identity scope. ErrInvalidScope = errors.New("invalid scope: must be non-empty") // ErrInvalidModel reports an empty allowed-model entry. ErrInvalidModel = errors.New("invalid model: must be non-empty") // ErrInvalidExpiration reports an expiration before identity creation. ErrInvalidExpiration = errors.New("expires_at must be after created_at") )
var ( // ErrRepositoryRequired reports a missing storage adapter. ErrRepositoryRequired = errors.New("identity storage is required") // ErrNotFound reports a missing identity. ErrNotFound = errors.New("identity not found") // ErrConflict reports an existing identity or stale revision. ErrConflict = errors.New("identity revision conflict") // ErrCorruptRecord reports invalid durable identity data. ErrCorruptRecord = errors.New("identity record is invalid") // ErrHashImmutable reports an attempted hash mutation. ErrHashImmutable = errors.New("identity hash is immutable") )
var ErrIssuerRequired = errors.New("identity issuer repository is required")
ErrIssuerRequired reports an absent identity repository.
Functions ¶
func ValidateName ¶ added in v1.0.1
ValidateName checks the public identity-name contract.
Types ¶
type APIKey ¶
type APIKey struct {
ID string `json:"id"`
Name string `json:"name"`
Hash string `json:"hash"`
Scopes []string `json:"scopes"`
AllowedModels []string `json:"allowed_models,omitempty"`
RateLimitConfig map[string]any `json:"rate_limit_config,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
Active bool `json:"active"`
CreatedAt time.Time `json:"created_at"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
}
APIKey is one gateway authentication identity.
func (APIKey) CanUseModel ¶
CanUseModel reports whether the identity can use a model.
func (APIKey) IsExpiredAt ¶
IsExpiredAt reports whether the identity expired at the supplied time.
type IssueRequest ¶ added in v1.0.1
type IssueRequest struct {
Name string
Scopes []string
Metadata map[string]any
ExpiresAt *time.Time
}
IssueRequest contains the durable attributes for a new gateway identity.
type IssueResult ¶ added in v1.0.1
IssueResult contains a new identity and its one-time plaintext credential. The repository stores only the credential hash.
type Issuer ¶ added in v1.0.1
type Issuer struct {
// contains filtered or unexported fields
}
Issuer creates gateway credentials and their durable identity records.
func NewIssuer ¶ added in v1.0.1
func NewIssuer(repository Repository) (*Issuer, error)
NewIssuer returns an identity issuer backed by repository.
func (*Issuer) Issue ¶ added in v1.0.1
func (i *Issuer) Issue(ctx context.Context, request IssueRequest) (IssueResult, error)
Issue creates one identity and returns its plaintext credential once.
func (*Issuer) IssueInitial ¶ added in v1.0.1
func (i *Issuer) IssueInitial(ctx context.Context, request IssueRequest) (IssueResult, error)
IssueInitial atomically creates the first identity in a repository.
type Repository ¶
type Repository interface {
Create(context.Context, APIKey) (Record, error)
CreateInitial(context.Context, APIKey) (Record, error)
ReleaseInitial(context.Context, string) error
GetByID(context.Context, string) (Record, error)
GetByHash(context.Context, string) (Record, error)
List(context.Context, int) ([]Record, error)
Update(context.Context, APIKey, uint64) (Record, error)
Delete(context.Context, string, uint64) error
}
Repository is the durable identity contract.