apitoken

package
v1.24.2 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CLIComment = "rocketpool CLI"
)
View Source
const (
	Prefix = "rpsn_"
)

Variables

This section is empty.

Functions

func WriteFile

func WriteFile(path string, f File) error

WriteFile writes f to path with 0600 permissions.

Types

type File

type File struct {
	Tokens []Record `json:"tokens"`
}

File is the on-disk token list.

func EnsureFile

func EnsureFile(path string) (File, error)

EnsureFile returns the token file at path, creating a write-scoped CLI token if the file is missing or has no tokens. Creation uses O_EXCL so concurrent callers converge on a single file.

func ReadFile

func ReadFile(path string) (File, error)

ReadFile loads tokens from path. A missing file is an empty list.

func (File) CLIIndex

func (f File) CLIIndex() int

CLIIndex returns the index of the write-scoped CLI token, or -1.

func (File) Lookup

func (f File) Lookup(bearer string) (Record, bool)

Lookup returns the record whose token matches bearer, if any.

type Record

type Record struct {
	Token   Token  `json:"token"`
	Comment string `json:"comment"`
	Scope   Scope  `json:"scope"`
}

Record is one token in the sidecar JSON file.

type Scope

type Scope string

Scope is the privilege of a stored token.

const (
	ScopeRead  Scope = "read"
	ScopeWrite Scope = "write"
)

func (*Scope) UnmarshalText

func (s *Scope) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler for Scope.

type Token

type Token [rawBytes]byte

Token is a 32-byte API bearer secret. Text form is rpsn_ plus 64 hex chars.

func Generate

func Generate() (Token, error)

Generate returns a new high-entropy API token.

func Parse

func Parse(s string) (Token, error)

Parse decodes an rpsn_-prefixed hex token.

func (Token) Equal

func (t Token) Equal(other Token) bool

Equal compares two tokens in constant time.

func (Token) IsZero

func (t Token) IsZero() bool

IsZero reports whether t is the zero value.

func (Token) MarshalText

func (t Token) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Token) String

func (t Token) String() string

String returns the rpsn_-prefixed encoding.

func (*Token) UnmarshalText

func (t *Token) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (Token) Valid

func (t Token) Valid() bool

Valid reports whether t is a non-zero token.

Jump to

Keyboard shortcuts

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