createapitoken

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 9 Imported by: 1 module, 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 createapitoken makes an API token, for a script or an agent: shown once, the base keeps its hash.

Index

Constants

View Source
const DefaultLifetime = "90d"

DefaultLifetime is the duration of a token when none is asked.

View Source
const MaxName = 100

MaxName is the most characters of a token's name.

View Source
const Prefix = "callback_"

Prefix starts every API token: a leaked one is recognizable.

Variables

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

func Process

func Process(ctx context.Context, db bun.IDB, input Input) *run

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"`
}

type Result

type Result struct {
	Token    string       `json:"token"`
	APIToken domain.Token `json:"api_token"`
}

Result is the new token: Token is shown once.

Jump to

Keyboard shortcuts

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