apikeys

package
v1.19.8 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2021 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoSecret = errs.Class("no apikey error")

ErrNoSecret represents errors from the apikey database.

View Source
var (
	// ErrService defines secret service error.
	ErrService = errs.Class("secret service error")
)

Functions

This section is empty.

Types

type APIKey

type APIKey struct {
	// Secret is PK of the table and keeps unique value sno apikey token
	Secret Secret

	CreatedAt time.Time `json:"createdAt"`
}

APIKey describing apikey model in the database.

type DB

type DB interface {
	// Store stores apikey token into db.
	Store(ctx context.Context, secret APIKey) error

	// Check checks if unique apikey exists in db by token.
	Check(ctx context.Context, token Secret) error

	// Revoke removes token from db.
	Revoke(ctx context.Context, token Secret) error
}

DB is interface for working with apikey tokens.

architecture: Database

type Secret

type Secret [32]byte

Secret stores token of storagenode APIkey.

func NewSecret

func NewSecret() (Secret, error)

NewSecret creates new apikey secret.

func TokenSecretFromBase64

func TokenSecretFromBase64(s string) (Secret, error)

TokenSecretFromBase64 creates new apikey token from base64 string.

func (Secret) IsZero

func (secret Secret) IsZero() bool

IsZero returns if the apikey token is not set.

func (Secret) String

func (secret Secret) String() string

String implements Stringer.

type Service

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

Service responsible for operations with storagenode's uniq secret.

architecture: Service

func NewService

func NewService(db DB) *Service

NewService is a constructor for service.

func (*Service) Check

func (service *Service) Check(ctx context.Context, secret Secret) (err error)

Check returns error if api key does not exists.

func (*Service) Issue

func (service *Service) Issue(ctx context.Context) (apiKey APIKey, err error)

Issue generates new api key and stores it into db.

func (*Service) Remove

func (service *Service) Remove(ctx context.Context, secret Secret) (err error)

Remove revokes apikey, deletes it from db.

Jump to

Keyboard shortcuts

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