apikey

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunAPIKeyCmd

func RunAPIKeyCmd(rt mdk.Runtime, args []string) error

RunAPIKeyCmd executes the CLI logic to generate a new API key.

Types

type APIKey

type APIKey struct {
	ID        string         `gorm:"primaryKey" json:"id"`
	Name      string         `gorm:"default:'';not null" json:"name"`
	Key       string         `gorm:"uniqueIndex;not null" json:"key"`
	ActorID   string         `gorm:"not null" json:"actor_id"`
	Actor     auth.Actor     `gorm:"foreignKey:ActorID" json:"actor"`
	ExpiresAt *time.Time     `json:"expires_at,omitempty"`
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}

APIKey represents a secret key used for authentication.

type APIKeyInfo

type APIKeyInfo struct {
	ID        string     `json:"id"`
	Name      string     `json:"name"`
	ActorID   string     `json:"actorId"`
	ExpiresAt *time.Time `json:"expiresAt,omitempty"`
	CreatedAt time.Time  `json:"createdAt"`
}

type GeneratedAPIKey

type GeneratedAPIKey struct {
	ID        string     `json:"id"`
	Name      string     `json:"name"`
	Key       string     `json:"key"`
	ActorID   string     `json:"actorId"`
	ExpiresAt *time.Time `json:"expiresAt,omitempty"`
	CreatedAt time.Time  `json:"createdAt"`
}

type Module

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

func NewModule

func NewModule() *Module

func (*Module) APIKeyMiddleware added in v0.4.0

func (m *Module) APIKeyMiddleware(next http.Handler) http.Handler

func (*Module) CreateAPIKey

func (m *Module) CreateAPIKey(ctx context.Context, actorID string, name string, expiresAt *time.Time) (*APIKey, error)

CreateAPIKey generates a new secure API key for the given actor.

func (*Module) CreateAPIKeyResolver

func (m *Module) CreateAPIKeyResolver(ctx context.Context, name string, expiresAt *time.Time) (*GeneratedAPIKey, error)

func (*Module) FieldResolvers

func (m *Module) FieldResolvers() map[string]any

func (*Module) GetActorByAPIKey

func (m *Module) GetActorByAPIKey(ctx context.Context, key string) (mdk.Actor, error)

GetActorByAPIKey retrieves an actor associated with a given API key.

func (*Module) ID

func (m *Module) ID() string

func (*Module) Init

func (m *Module) Init(ctx context.Context, rt mdk.Runtime) error

func (*Module) ListAPIKeys

func (m *Module) ListAPIKeys(ctx context.Context, actorID string) ([]*APIKey, error)

ListAPIKeys lists all active API keys for the given actor.

func (*Module) ListAPIKeysResolver

func (m *Module) ListAPIKeysResolver(ctx context.Context) ([]*APIKeyInfo, error)

func (*Module) Middlewares added in v0.4.0

func (m *Module) Middlewares() []func(http.Handler) http.Handler

Middlewares implements mdk.MiddlewareProvider interface.

func (*Module) Models

func (m *Module) Models() []any

func (*Module) Mutations

func (m *Module) Mutations() map[string]any

func (*Module) Queries

func (m *Module) Queries() map[string]any

func (*Module) RevokeAPIKey

func (m *Module) RevokeAPIKey(ctx context.Context, actorID string, keyID string) (bool, error)

RevokeAPIKey deletes/revokes an API key.

func (*Module) RevokeAPIKeyResolver

func (m *Module) RevokeAPIKeyResolver(ctx context.Context, id string) (bool, error)

func (*Module) Routes

func (m *Module) Routes() []mdk.Route

func (*Module) Shutdown

func (m *Module) Shutdown(ctx context.Context) error

Jump to

Keyboard shortcuts

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