apitoken

package
v1.543.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package apitoken provides shared helpers for generating opaque, random API token IDs and secrets, and computing safe display prefixes.

Index

Constants

View Source
const (
	// TokenIDPrefix is the prefix for the public, opaque token ID.
	TokenIDPrefix = "tok_"
	// SecretPrefix is the prefix for the plaintext token secret. New tokens
	// use "apt_"; migrated legacy tokens keep their original value (e.g.
	// "ap_") so they continue to authenticate after migration.
	SecretPrefix = "apt_"
)

Variables

This section is empty.

Functions

func DisplayPrefix

func DisplayPrefix(secret string) string

DisplayPrefix returns a safe, short prefix of the secret for display.

func GenerateSecret

func GenerateSecret() (string, error)

GenerateSecret returns a new plaintext token secret: "apt_" + 32 random bytes hex.

func GenerateTokenID

func GenerateTokenID() (string, error)

GenerateTokenID returns a new opaque token ID: "tok_" + 16 random bytes hex.

func MigrationTokenID

func MigrationTokenID(source string) string

MigrationTokenID returns a deterministic token ID derived from a migration source identifier. Migration IDs are stable so the migration is idempotent across restarts: re-running migration against the same legacy source resolves to the same new token ID and Create returns ErrAPITokenAlreadyExists, which the migration treats as "already migrated".

The returned ID is sanitized to be a valid Kubernetes resource-name suffix (lowercase, alphanumerics and dashes only).

Types

This section is empty.

Jump to

Keyboard shortcuts

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