autokey

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2020 License: MIT Imports: 6 Imported by: 0

README

autokey

autokey is a Go library that automatically generates and rotates a base 64 encoded key which can be used to sign JWTs.

This package provides a Manager struct that has only two methods:

  • Start(interrupt chan struct{}) that starts the manager loop (it should be run this in its own goroutine). The interrept channel is used to signal to the listener goroutine that the manager has stops.
  • Stop() is used to stops the manager loop by closing the timer and its stop channel.

Once started, the manager will try to find if a key has already been stored and create a new one if there is no key stored. Then it will start a timer and automatically renew the key periodically.

The storage of the key is defined by an interface so it is pluggable. A environment storage is provided.

This package also provides the consumer interface that defines how to retrieve the key. So if your struct or function needs to access the key, you can use this interface. It is helpful for tests and decoupling.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Consumer

type Consumer interface {
	Get() (string, error)
}

Consumer defines an object that is able to retrieve the key

func NewEnvConsumer

func NewEnvConsumer(envVar string) Consumer

NewEnvConsumer inits a new EnvConsumer

type EnvConsumer

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

EnvConsumer is key consumer that is able to retrieve the key from the environment

func (*EnvConsumer) Get

func (c *EnvConsumer) Get() (string, error)

Get retrieves the key from the environment An error is returned instead is the environment key was not set

type EnvStorage

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

EnvStorage stores the key in the environment

func (*EnvStorage) IsStored

func (s *EnvStorage) IsStored() (bool, error)

IsStored checks if the environment variable is set

func (*EnvStorage) Store

func (s *EnvStorage) Store(key string) error

Store set the key in the environment

type Manager

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

Manager is responsible for generating and rotating the application key that is used to sign JWTs The key is a base 64 encoded random string

func NewManager

func NewManager(storage Storage, keySize int, rotationTime time.Duration) *Manager

NewManager is a constructor for Manager

func (*Manager) Start

func (m *Manager) Start(interrupt chan struct{}) error

Start starts the rotation loop

func (*Manager) Stop

func (m *Manager) Stop()

Stop stops the rotation loop

type MockConsumer

type MockConsumer struct {
	mock.Mock
}

MockConsumer is an autogenerated mock type for the Consumer type

func (*MockConsumer) Get

func (_m *MockConsumer) Get() (string, error)

Get provides a mock function with given fields:

type Storage

type Storage interface {
	Store(key string) error
	IsStored() (bool, error)
}

Storage defines how a key is stored

func NewEnvStorage

func NewEnvStorage(envVar string) Storage

NewEnvStorage inits a new EnvStorage

Jump to

Keyboard shortcuts

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