Documentation ¶
Overview ¶
Package keybroker implements a background broker conmtinous retrieval of public keys from multiple different type of sources.
Example ¶
package main import ( "context" "io/ioutil" "time" "github.com/LUSHDigital/core/workers/keybroker" ) var ctx context.Context func main() { broker := keybroker.NewRSA(&keybroker.Config{ Source: keybroker.JWTPublicKeySources, Interval: 5 * time.Second, }) // Run the broker go broker.Run(ctx, ioutil.Discard) // Queue retrieval of new key broker.Renew() // Copy the current public key held by the broker broker.Copy() }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrEmptyURL represents an error for when an expected url is an empty string ErrEmptyURL = ErrGetKeySource{"url cannot be empty"} // ErrEmptyFilePath represents an error for when an expected file path is an empty string ErrEmptyFilePath = ErrGetKeySource{"file path cannot be empty"} // ErrEmptyString represents an error for when an expected string should contain a public key ErrEmptyString = ErrGetKeySource{"string cannot be empty"} )
var ( // JWTPublicKeyEnvStringSource represents the source of an RSA public key as a string JWTPublicKeyEnvStringSource = StringSource(os.Getenv("JWT_PUBLIC_KEY")) // JWTPublicKeyEnvHTTPSource represents the source of an RSA public key at a HTTP GET destination JWTPublicKeyEnvHTTPSource = HTTPSource(os.Getenv("JWT_PUBLIC_KEY_URL")) // JWTPublicKeyEnvFileSource represents the source of an RSA public key on disk JWTPublicKeyEnvFileSource = FileSource(os.Getenv("JWT_PUBLIC_KEY_PATH")) // JWTPublicKeyDefaultFileSource represents the source of an RSA public key on disk JWTPublicKeyDefaultFileSource = FileSource("/usr/local/var/jwt.pub") // JWTPublicKeySources represents a chain of sources for JWT Public Keys in order of priority JWTPublicKeySources = Sources{ JWTPublicKeyEnvStringSource, JWTPublicKeyEnvFileSource, JWTPublicKeyEnvHTTPSource, JWTPublicKeyDefaultFileSource, } )
var ( // DefaultRSA is an empty RSA public key DefaultRSA = &rsa.PublicKey{E: 0, N: big.NewInt(0)} )
Functions ¶
This section is empty.
Types ¶
type ErrGetKeySource ¶
type ErrGetKeySource struct {
// contains filtered or unexported fields
}
ErrGetKeySource represents an error when failing to get the source
func (ErrGetKeySource) Error ¶
func (e ErrGetKeySource) Error() string
type ErrNoSourcesResolved ¶
type ErrNoSourcesResolved struct {
N int
}
ErrNoSourcesResolved represents an error for when no sources could be resolved at all
func (ErrNoSourcesResolved) Error ¶
func (e ErrNoSourcesResolved) Error() string
type ErrReadResponse ¶
type ErrReadResponse struct {
// contains filtered or unexported fields
}
ErrReadResponse represents an error when failing to read the source data
func (ErrReadResponse) Error ¶
func (e ErrReadResponse) Error() string
type HTTPSource ¶
type HTTPSource string
HTTPSource defines a source with a URL to resolve over HTTP
type RSAPublicKeyBroker ¶
type RSAPublicKeyBroker struct {
// contains filtered or unexported fields
}
RSAPublicKeyBroker defines the implementation for brokering an RSA public key
func NewRSA ¶
func NewRSA(config *Config) *RSAPublicKeyBroker
NewRSA returns a rsa public key broker based on configuration.
func (*RSAPublicKeyBroker) Check ¶
func (b *RSAPublicKeyBroker) Check() ([]string, bool)
Check will see if the broker is ready.
func (*RSAPublicKeyBroker) Close ¶
func (b *RSAPublicKeyBroker) Close()
Close stops the ticker and releases resources
func (*RSAPublicKeyBroker) Copy ¶
func (b *RSAPublicKeyBroker) Copy() rsa.PublicKey
Copy returns a shallow copy o the RSA public key
func (*RSAPublicKeyBroker) Renew ¶
func (b *RSAPublicKeyBroker) Renew()
Renew will inform the broker to force renewal of the key
type RSAPublicKeyCopier ¶
RSAPublicKeyCopier represents behaviour for distributing copies of public keys
type Renewer ¶
type Renewer interface {
Renew()
}
Renewer represents behaviour for marking a broker for renewal
Directories ¶
Path | Synopsis |
---|---|
Package keybrokermock implements no-op mocks for the keys package
|
Package keybrokermock implements no-op mocks for the keys package |