auth

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 11 Imported by: 0 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 auth stores the management token, binds it to one server and resolves the credential for each run.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotSignedIn = errors.New("not signed in")

ErrNotSignedIn means no credential is available for the server.

Functions

func CheckTokenShape

func CheckTokenShape(token string) error

CheckTokenShape rejects text that cannot be a management token.

func DisplayName

func DisplayName(id Identity) string

DisplayName is how cchp names a signed-in identity to people.

func NormalizeServer

func NormalizeServer(raw string) (string, error)

NormalizeServer checks a server address and returns its canonical form: scheme, host, optional port and optional path prefix, without a trailing slash. Plain http is allowed only for this machine, so tokens never cross a network unencrypted.

func Origin

func Origin(server string) string

Origin returns scheme://host[:port] of a server address from NormalizeServer.

func TokenPrefix

func TokenPrefix(token string) string

TokenPrefix returns the public part of a management token, cch_auth_live_<prefix>.

Types

type Config

type Config struct {
	Current  string              `json:"current,omitempty"`
	Profiles map[string]*Profile `json:"profiles,omitempty"`
}

Config is cchp's config.json.

type Credential

type Credential struct {
	Server   string
	Token    string
	Source   string // env, token-file, keychain or file
	Identity *Identity
}

Credential is the token cchp uses for one run.

type Dirs

type Dirs struct {
	Config string
	Cache  string
}

Dirs locates cchp's files.

func DefaultDirs

func DefaultDirs() (Dirs, error)

DefaultDirs honours CCHP_CONFIG_DIR and CCHP_CACHE_DIR.

type Identity

type Identity struct {
	UserID           string `json:"user_id,omitempty"`
	Email            string `json:"email,omitempty"`
	Name             string `json:"name,omitempty"`
	OrganizationID   string `json:"organization_id,omitempty"`
	OrganizationName string `json:"organization_name,omitempty"`
	OrgRole          string `json:"org_role,omitempty"`
	TokenKind        string `json:"token_kind,omitempty"`
	IsPlatformAdmin  bool   `json:"is_platform_admin"`
}

Identity is what the server said about the token at sign-in.

type Profile

type Profile struct {
	Server      string    `json:"server"`
	TokenPrefix string    `json:"token_prefix"`
	Store       string    `json:"store"`
	Identity    Identity  `json:"identity"`
	SignedInAt  time.Time `json:"signed_in_at"`
}

Profile is the non-secret record of a sign-in, kept in config.json.

type Store

type Store struct {
	Dirs Dirs
	// Backend is "keychain" or "file".
	Backend string
}

Store reads and writes credentials and config.json.

func OpenStore

func OpenStore(d Dirs) (*Store, error)

OpenStore picks the credential backend: the OS keychain when one is reachable, otherwise a mode-600 file. CCHP_CREDENTIAL_STORE=keychain|file chooses explicitly.

func (*Store) Current

func (s *Store) Current() (*Profile, error)

Current returns the current profile, if any.

func (*Store) Delete

func (s *Store) Delete(server string) error

Delete removes the stored token and profile for server.

func (*Store) Load

func (s *Store) Load() (*Config, error)

Load reads config.json; a missing file is an empty config.

func (*Store) Resolve

func (s *Store) Resolve() (*Credential, error)

Resolve finds the credential for this run. Environment variables come first (CCHP_TOKEN or CCHP_TOKEN_FILE, always with CCHP_BASE_URL), then the stored credential of CCHP_BASE_URL or of the current server.

func (*Store) Save

func (s *Store) Save(server, token string, id Identity) (*Profile, error)

Save stores the token for server and makes it the current server.

func (*Store) Server

func (s *Store) Server() (string, error)

Server returns the server cchp would talk to without needing a token: CCHP_BASE_URL or the current server.

Jump to

Keyboard shortcuts

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