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
- Variables
- func CheckAlias(tpl string) error
- func CheckKeyName(tpl string) error
- func Required(tpl, part string) bool
- func Tokens(tpl string) []string
- type Rules
- func (r Rules) Check() error
- func (r Rules) Code(profile, own string) string
- func (r Rules) Generate(parts map[string]string, taken []string) (string, error)
- func (r Rules) Over(over Rules) Rules
- func (r Rules) Parse(alias string) (map[string]string, bool)
- func (r Rules) RenderKeyName(profile, alias, code, algo string) (string, error)
- func (r Rules) Violation(alias, code string) string
- func (r Rules) WithDefaults() Rules
Constants ¶
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.
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.
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 ¶
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 ¶
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 ¶
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).
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) Code ¶
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 ¶
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 ¶
Over is r with every field over sets replacing r's: a profile's own rules over the manifest's.
func (Rules) Parse ¶
Parse reads alias's parts under r's alias template, or reports false when the alias does not follow it.
func (Rules) RenderKeyName ¶
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 ¶
Violation says why alias does not follow r for a profile whose {code} is code, or "" when it does.
func (Rules) WithDefaults ¶
WithDefaults fills what r leaves empty.