Documentation
¶
Overview ¶
Package createapitoken makes an API token, for a script or an agent: shown once, the base keeps its hash.
Index ¶
Constants ¶
const DefaultLifetime = "90d"
DefaultLifetime is the duration of a token when none is asked.
const MaxName = 100
MaxName is the most characters of a token's name.
const Prefix = "callback_"
Prefix starts every API token: a leaked one is recognizable.
Variables ¶
var ( ErrNoName = domain.Invalid("the token needs a name") ErrLongName = domain.Invalid("the name of the token has at most 100 characters") ErrInvalidLifetime = domain.Invalid("expires_in must be one of 7d, 30d, 90d, 1y, never") )
var Lifetimes = map[string]time.Duration{ "7d": 7 * 24 * time.Hour, "30d": 30 * 24 * time.Hour, "90d": 90 * 24 * time.Hour, "1y": 365 * 24 * time.Hour, "never": 0, }
Lifetimes are the durations a token can be given; 0 is no limit.
Functions ¶
Types ¶
type Input ¶
type Input struct {
Name string `json:"name"`
// ExpiresIn is how long the token works, 90d when left out.
ExpiresIn string `json:"expires_in,omitempty" binding:"optional" enums:"7d,30d,90d,1y,never"`
// ReadOnly makes a token that reads and changes nothing.
ReadOnly bool `json:"read_only,omitempty" binding:"optional"`
}