apikey

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2024 License: MIT Imports: 10 Imported by: 0

README

apikey

Simple module to create, read, write, check API keys stored in a redis database.

Keys are readable strings. Permissions are associated with the key. Permissions are 32 bit unsigned integers to be used as bitmaps.

Documentation

Index

Constants

View Source
const DefaultKeyExpiry = time.Duration(time.Hour * oneHundredAndEightyDays)

Variables

This section is empty.

Functions

func Can

func Can(ctx context.Context, client *redis.Client, logger zerolog.Logger, key string, perm KeyPermissions) (bool, error)

Can returns true if a Key has a particular permission

func HashedKey

func HashedKey(key string) string

hashKey hashes a new key

Types

type APIKey

type APIKey struct {
	Permissions KeyPermissions `json:"permissions"`
	Expires     time.Time      `json:"expires"`
	Created     time.Time      `json:"created"`
	Owner       string         `json:"owner"`
	Email       string         `json:"email"`
	CreatedBy   string         `json:"createdBy"`
	Comment     string         `json:"comment"`
}

func GetKey

func GetKey(ctx context.Context, client *redis.Client, logger zerolog.Logger, key string) (*APIKey, error)

Returns the permissions associated with a raw key if it exists. Returns an empty string if not

func NewKey

func NewKey(ctx context.Context, client *grsearch.Client, logger zerolog.Logger, owner, email, creator, comment string, permissions KeyPermissions) (string, *APIKey, error)

NewKey returns a random string to be used as a key with the specified permissions and default expirty

func NewKeyWithExpiry

func NewKeyWithExpiry(ctx context.Context, client *grsearch.Client, logger zerolog.Logger, owner, email, creator, comment string, permissions KeyPermissions, expiry time.Duration) (string, *APIKey, error)

NewKeyWithExpiry returns a random string to be used as a key with the specified permissions and expiry

type KeyPermissions

type KeyPermissions uint32

Jump to

Keyboard shortcuts

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