53007a9257
Compile a host's catalog in a base and a test environment over the puppetserver API, then diff the two. - add catalog-diff CLI with cobra flags, config precedence and exit codes - add puppetserver mTLS client for POST /puppet/v4/catalog - add pdbmux fact client - add catalog normalisation, diff engine and text/JSON renderers - add Makefile, nfpm RPM packaging and woodpecker pipelines
24 lines
910 B
Go
24 lines
910 B
Go
package catalog
|
|
|
|
import "regexp"
|
|
|
|
// reInvalidCharacters mirrors g10k's branch sanitisation (\W -> "_").
|
|
var reInvalidCharacters = regexp.MustCompile(`\W`)
|
|
|
|
// reValidEnvironment is Puppet's own environment name rule.
|
|
var reValidEnvironment = regexp.MustCompile(`^[a-z0-9_]+$`)
|
|
|
|
// BranchToEnvironment converts a git branch name into the environment
|
|
// directory name g10k deploys it as: every character outside [0-9A-Za-z_]
|
|
// becomes "_". Case is preserved, because g10k preserves it.
|
|
func BranchToEnvironment(branch string) string {
|
|
return reInvalidCharacters.ReplaceAllString(branch, "_")
|
|
}
|
|
|
|
// ValidEnvironmentName reports whether name is a legal Puppet environment
|
|
// name. g10k can produce names Puppet rejects (it keeps uppercase), so
|
|
// callers must check the result of BranchToEnvironment before using it.
|
|
func ValidEnvironmentName(name string) bool {
|
|
return reValidEnvironment.MatchString(name)
|
|
}
|