authorization

package
v0.0.0-...-7578c0e Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const APITokenPrefixLength = 8

Variables

This section is empty.

Functions

func Extract

func Extract(prefixedpwd string) (string, string, error)

func IsValidScope

func IsValidScope(scope APITokenScope) bool

Types

type APIToken

type APIToken struct {
	Username  string        `json:"username,omitempty" db:"username"`
	Prefix    string        `json:"prefix,omitempty" db:"prefix"`
	Name      string        `json:"name,omitempty" db:"name"`
	CreatedAt *time.Time    `json:"created_at,omitempty" db:"created_at"`
	ExpiresAt *time.Time    `json:"expires_at,omitempty" db:"expires_at"`
	Scope     APITokenScope `json:"scope,omitempty" db:"scope"`
	Token     string        `json:"token,omitempty" db:"token"`
}

type APITokenScope

type APITokenScope string
const (
	APITokenRead        APITokenScope = "read"
	APITokenReadWrite   APITokenScope = "read+write"
	APITokenClientsAuth APITokenScope = "clients-auth"
)

type DbProvider

type DbProvider interface {
	Get(ctx context.Context, username, prefix string) (*APIToken, error)
	GetByName(ctx context.Context, username, name string) (*APIToken, error)
	GetAll(ctx context.Context, username string) ([]*APIToken, error)
	Save(ctx context.Context, tokenLine *APIToken) error
	Delete(ctx context.Context, username, prefix string) error
	io.Closer
}

type Manager

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

func NewManager

func NewManager(db DbProvider) *Manager

func (*Manager) Close

func (m *Manager) Close() error

func (*Manager) Create

func (m *Manager) Create(ctx context.Context, tokenLine *APIToken) error

func (*Manager) Delete

func (m *Manager) Delete(ctx context.Context, username, prefix string) error

func (*Manager) Get

func (m *Manager) Get(ctx context.Context, username, prefix string) (*APIToken, error)

func (*Manager) GetAll

func (m *Manager) GetAll(ctx context.Context, username string) ([]*APIToken, error)

func (*Manager) Save

func (m *Manager) Save(ctx context.Context, tokenLine *APIToken) error

type SqliteProvider

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

func NewSqliteProvider

func NewSqliteProvider(db *sqlx.DB) *SqliteProvider

func (*SqliteProvider) Close

func (p *SqliteProvider) Close() error

func (*SqliteProvider) Delete

func (p *SqliteProvider) Delete(ctx context.Context, username, prefix string) error

func (*SqliteProvider) Get

func (p *SqliteProvider) Get(ctx context.Context, username, prefix string) (*APIToken, error)

func (*SqliteProvider) GetAll

func (p *SqliteProvider) GetAll(ctx context.Context, username string) ([]*APIToken, error)

func (*SqliteProvider) GetByName

func (p *SqliteProvider) GetByName(ctx context.Context, username, name string) (*APIToken, error)

func (*SqliteProvider) Save

func (p *SqliteProvider) Save(ctx context.Context, tokenLine *APIToken) (err error)

Jump to

Keyboard shortcuts

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