Documentation
¶
Overview ¶
Package apikeys manages the keys of the HTTP API (/api). An administrator creates a key per service (Moodle, a backup script, ...) with a description, and can disable or delete it without touching the others. Only a SHA-256 hash of each key is stored; the key is shown once.
Index ¶
- Constants
- Variables
- func Hash(key string) string
- type Manager
- func (m *Manager) Check(key string) (*db.APIKey, bool)
- func (m *Manager) Create(description string) (string, db.APIKey, error)
- func (m *Manager) Delete(id string) error
- func (m *Manager) Import(key, description string) (bool, error)
- func (m *Manager) List() ([]db.APIKey, error)
- func (m *Manager) SetDisabled(id string, disabled bool) error
Constants ¶
const (
// MaxDescription is the longest description, in characters.
MaxDescription = 200
)
Variables ¶
var ( // ErrNoDescription is returned for an empty description. ErrNoDescription = errors.New("a description is required") // ErrDescriptionTooLong is returned for a description over MaxDescription. ErrDescriptionTooLong = errors.New("the description is too long") )
Functions ¶
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager creates and checks API keys.
func NewManager ¶
func NewManager(store db.APIKeyMethods) *Manager
NewManager returns a Manager on store.
func (*Manager) Check ¶
Check reports whether key is a stored, enabled key, and records its use. Keys are compared by their hash, so the comparison takes the same time for every wrong key.
func (*Manager) Create ¶
Create makes a new key. The returned string is the key; it cannot be recovered later.
func (*Manager) Import ¶
Import stores an existing key (from an APIKEY.txt), unless it is stored already. It reports whether it stored it.