restkeys

package
v1.117.6 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Error describes internal rest keys error.
	Error = errs.Class("rest keys service")

	// ErrDuplicateKey is error type that occurs when a generated account
	// management api key already exists.
	ErrDuplicateKey = errs.Class("duplicate key")

	// ErrInvalidKey is an error type that occurs when a user submits a key
	// that does not match anything in the database.
	ErrInvalidKey = errs.Class("invalid key")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	DefaultExpiration time.Duration `help:"expiration to use if user does not specify an rest key expiration" default:"720h"`
}

Config contains configuration parameters for rest keys.

type Service

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

Service handles operations regarding rest keys.

func NewService

func NewService(db oidc.OAuthTokens, config Config) *Service

NewService creates a new rest keys service.

func (*Service) Create

func (s *Service) Create(ctx context.Context, userID uuid.UUID, expiration time.Duration) (apiKey string, expiresAt time.Time, err error)

Create creates and inserts an rest key into the db.

func (*Service) GenerateNewKey

func (s *Service) GenerateNewKey(ctx context.Context) (apiKey, hash string, err error)

GenerateNewKey generates a new account management api key.

func (*Service) GetUserAndExpirationFromKey

func (s *Service) GetUserAndExpirationFromKey(ctx context.Context, apiKey string) (userID uuid.UUID, exp time.Time, err error)

GetUserAndExpirationFromKey gets the userID and expiration date attached to an account management api key.

func (*Service) HashKey

func (s *Service) HashKey(ctx context.Context, apiKey string) (hash string, err error)

HashKey returns a hash of api key. This is used for hashing inside GetUserFromKey.

func (*Service) InsertIntoDB

func (s *Service) InsertIntoDB(ctx context.Context, oAuthToken oidc.OAuthToken, now time.Time, expiration time.Duration) (expiresAt time.Time, err error)

InsertIntoDB checks OAuthTokens DB for a token before inserting. This is because OAuthTokens DB allows duplicate tokens, but we can't have duplicate api keys.

func (*Service) Revoke

func (s *Service) Revoke(ctx context.Context, apiKey string) (err error)

Revoke revokes an account management api key.

Jump to

Keyboard shortcuts

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