naming

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 6 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 naming holds the rules for how servers and their keys are named: an alias template such as {code}-{env}-{role}-{nn}, from which an alias is checked, parsed into its parts or generated with the next free number, and a key-name template such as {profile}_{alias}-{algo}. It is pure: no file, no manifest, just templates and strings.

A template is literal text and parts in braces:

{code} {env} {role}   lowercase letters and digits
{nn} {nnn} ...        the number, as many digits as n's (00, 000), from Start
{env?}                optional: left out, with the separator before it (or
                      after it, for the first part), when it has no value

A key-name template may also name {profile}, {alias} and {algo}.

Index

Constants

View Source
const (
	DefaultAlias   = "{code}-{env}-{role}-{nn}"
	DefaultKeyName = "{profile}_{alias}-{algo}"
)

The defaults: the convention authama documents, and the key name every release before templates derived.

View Source
const (
	EnforceOff   = "off"
	EnforceWarn  = "warn"
	EnforceError = "error"
)

Enforcement levels for an alias that does not follow the rules when a host is added. Hosts already in the manifest are only ever reported.

View Source
const (
	// CodeNone: nothing; a template that needs {code} cannot name its
	// servers, and an optional {code?} is left out.
	CodeNone = "none"
	// CodeProfile: the profile's name, lowercased to letters and digits.
	CodeProfile = "profile"
)

What a profile with no code of its own uses for {code}.

Variables

View Source
var ErrNoParts = errors.New("the host lacks a part the key-name template needs")

ErrNoParts is a key-name template naming a part the host does not have: its alias does not follow the alias template, or a required {code} is unknown. The caller falls back to the default name.

Functions

func CheckAlias

func CheckAlias(tpl string) error

CheckAlias reports whether tpl can be an alias template: only {code}, {env}, {role} and a number, each at most once; a separator between parts so they can be told apart; literals that keep the alias a valid host name; and a number that is not optional, so a second server of the same kind can be named.

func CheckKeyName

func CheckKeyName(tpl string) error

CheckKeyName reports whether tpl can be a key-name template. A key name is read back in two places, so the template keeps their shape: it starts with {profile}_ (the profile is everything before the first underscore) and ends with -{algo} (the key type ssh-keygen is given).

func Required

func Required(tpl, part string) bool

Required reports whether tpl needs part, rather than naming it optionally or not at all.

func Tokens

func Tokens(tpl string) []string

Tokens lists the parts tpl names, sorted, the number as nn.

Types

type Rules

type Rules struct {
	Alias        string
	KeyName      string
	Envs         []string
	Roles        []string
	Enforce      string
	Start        int    // the first number: 0 (00) or 1 (01)
	CodeFallback string // CodeNone or CodeProfile
}

Rules are one manifest's (or one profile's) naming rules, with the defaults filled in by WithDefaults.

func (Rules) Check

func (r Rules) Check() error

Check reports whether r's templates, levels and lists are usable.

func (Rules) Code

func (r Rules) Code(profile, own string) string

Code is the {code} for a profile under r: its own code, else, with CodeFallback profile, its name lowercased to letters and digits.

func (Rules) Generate

func (r Rules) Generate(parts map[string]string, taken []string) (string, error)

Generate makes the next alias for parts (code, env, role) under r: the lowest number, from Start, that no name in taken already has with the same other parts. A required part with no value is an error; an optional one is left out.

func (Rules) Over

func (r Rules) Over(over Rules) Rules

Over is r with every field over sets replacing r's: a profile's own rules over the manifest's.

func (Rules) Parse

func (r Rules) Parse(alias string) (map[string]string, bool)

Parse reads alias's parts under r's alias template, or reports false when the alias does not follow it.

func (Rules) RenderKeyName

func (r Rules) RenderKeyName(profile, alias, code, algo string) (string, error)

RenderKeyName renders r's key-name template for a host. profile and alias arrive normalised, code is the profile's {code} ("" for none); the other parts come from parsing alias. A required part the host does not have is ErrNoParts.

func (Rules) Violation

func (r Rules) Violation(alias, code string) string

Violation says why alias does not follow r for a profile whose {code} is code, or "" when it does.

func (Rules) WithDefaults

func (r Rules) WithDefaults() Rules

WithDefaults fills what r leaves empty.

Jump to

Keyboard shortcuts

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