apikey

package
v11.1.4-modfix Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	QuotaTargetSrv quota.TargetSrv = "api_key"
	QuotaTarget    quota.Target    = "api_key"
)

Variables

View Source
var (
	ErrNotFound          = errors.New("API key not found")
	ErrInvalid           = errors.New("invalid API key")
	ErrInvalidExpiration = errors.New("negative value for SecondsToLive")
	ErrDuplicate         = errors.New("API key, organization ID and name must be unique")
)

Functions

This section is empty.

Types

type APIKey

type APIKey struct {
	ID               int64        `db:"id" xorm:"pk autoincr 'id'"`
	OrgID            int64        `db:"org_id" xorm:"org_id"`
	Name             string       `db:"name"`
	Key              string       `db:"key"`
	Role             org.RoleType `db:"role"`
	Created          time.Time    `db:"created"`
	Updated          time.Time    `db:"updated"`
	LastUsedAt       *time.Time   `xorm:"last_used_at" db:"last_used_at"`
	Expires          *int64       `db:"expires"`
	ServiceAccountId *int64       `db:"service_account_id"`
	IsRevoked        *bool        `xorm:"is_revoked" db:"is_revoked"`
}

func (APIKey) TableName

func (k APIKey) TableName() string

type AddCommand

type AddCommand struct {
	Name             string       `json:"name" binding:"Required"`
	Role             org.RoleType `json:"role" binding:"Required"`
	OrgID            int64        `json:"-" xorm:"org_id"`
	Key              string       `json:"-"`
	SecondsToLive    int64        `json:"secondsToLive"`
	ServiceAccountID *int64       `json:"-"`
}

swagger:model AddAPIKeyCommand

type DeleteCommand

type DeleteCommand struct {
	ID    int64 `json:"id"`
	OrgID int64 `json:"-"`
}

type GetApiKeysQuery

type GetApiKeysQuery struct {
	OrgID          int64
	IncludeExpired bool
	User           identity.Requester
}

type GetByIDQuery

type GetByIDQuery struct {
	ApiKeyID int64
}

type GetByNameQuery

type GetByNameQuery struct {
	KeyName string
	OrgID   int64
}

type Service

type Service interface {
	GetAPIKeys(ctx context.Context, query *GetApiKeysQuery) (res []*APIKey, err error)
	GetAllAPIKeys(ctx context.Context, orgID int64) ([]*APIKey, error)
	DeleteApiKey(ctx context.Context, cmd *DeleteCommand) error
	AddAPIKey(ctx context.Context, cmd *AddCommand) (res *APIKey, err error)
	GetApiKeyById(ctx context.Context, query *GetByIDQuery) (res *APIKey, err error)
	GetApiKeyByName(ctx context.Context, query *GetByNameQuery) (res *APIKey, err error)
	GetAPIKeyByHash(ctx context.Context, hash string) (*APIKey, error)
	UpdateAPIKeyLastUsedDate(ctx context.Context, tokenID int64) error
	// IsDisabled returns true if the API key is not available for use.
	IsDisabled(ctx context.Context, orgID int64) (bool, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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