apikeys

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (

	// MaxDescription is the longest description, in characters.
	MaxDescription = 200
)

Variables

View Source
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

func Hash

func Hash(key string) string

Hash is the stored form of a key.

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

func (m *Manager) Check(key string) (*db.APIKey, bool)

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

func (m *Manager) Create(description string) (string, db.APIKey, error)

Create makes a new key. The returned string is the key; it cannot be recovered later.

func (*Manager) Delete

func (m *Manager) Delete(id string) error

Delete removes a key for good.

func (*Manager) Import

func (m *Manager) Import(key, description string) (bool, error)

Import stores an existing key (from an APIKEY.txt), unless it is stored already. It reports whether it stored it.

func (*Manager) List

func (m *Manager) List() ([]db.APIKey, error)

List returns the keys, oldest first.

func (*Manager) SetDisabled

func (m *Manager) SetDisabled(id string, disabled bool) error

SetDisabled disables or enables a key.

Jump to

Keyboard shortcuts

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