Files
remark42/backend/app/store/keys/keys.go
T
UmputunandGitHub 1b9ee3d763 feature/keystore (#185)
* add keyStore and switch all secret usage to this store

- implement static ks
- add shared secret

* lint: shadow in jwt and missing comment

* rename static key group to shared and use top-level shared secret

* move siteID extraction (from token) to internal func

* lint: merge var and assign for key test
2018-08-08 14:33:18 -05:00

28 lines
688 B
Go

package keys
import "github.com/pkg/errors"
// Store defines interface returning key for given site
// this key used for JWT and HMAC hashes
type Store interface {
Get(siteID string) (key string, err error)
}
// StaticStore implements keys.Store with a single, predefined key
type StaticStore struct {
key string
}
// NewStaticStore makes StaticStore instance with given key
func NewStaticStore(key string) *StaticStore {
return &StaticStore{key: key}
}
// Get returns static key for all sites, allows empty site
func (s *StaticStore) Get(siteID string) (key string, err error) {
if s.key == "" {
return "", errors.New("empty key for static key store")
}
return s.key, nil
}