Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( LowercaseCharset = sortCharset("abcdefghijklmnopqrstuvwxyz") UppercaseCharset = sortCharset("ABCDEFGHIJKLMNOPQRSTUVWXYZ") NumericCharset = sortCharset("0123456789") FullSymbolCharset = sortCharset("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~") ShortSymbolCharset = sortCharset("-") AlphabeticCharset = sortCharset(UppercaseCharset + LowercaseCharset) AlphaNumericCharset = sortCharset(AlphabeticCharset + NumericCharset) AlphaNumericShortSymbolCharset = sortCharset(AlphaNumericCharset + ShortSymbolCharset) AlphaNumericFullSymbolCharset = sortCharset(AlphaNumericCharset + FullSymbolCharset) LowercaseRuneset = []rune(LowercaseCharset) UppercaseRuneset = []rune(UppercaseCharset) NumericRuneset = []rune(NumericCharset) FullSymbolRuneset = []rune(FullSymbolCharset) ShortSymbolRuneset = []rune(ShortSymbolCharset) AlphabeticRuneset = []rune(AlphabeticCharset) AlphaNumericRuneset = []rune(AlphaNumericCharset) AlphaNumericShortSymbolRuneset = []rune(AlphaNumericShortSymbolCharset) AlphaNumericFullSymbolRuneset = []rune(AlphaNumericFullSymbolCharset) // DefaultStringGenerator has reasonable default rules for generating strings DefaultStringGenerator = &StringGenerator{ Length: 20, Rules: []Rule{ CharsetRule{ Charset: LowercaseRuneset, MinChars: 1, }, CharsetRule{ Charset: UppercaseRuneset, MinChars: 1, }, CharsetRule{ Charset: NumericRuneset, MinChars: 1, }, CharsetRule{ Charset: ShortSymbolRuneset, MinChars: 1, }, }, } )
Functions ¶
This section is empty.
Types ¶
type CharsetRule ¶
type CharsetRule struct { // CharsetRule is the list of rules that candidate strings must contain a minimum number of. Charset runes `mapstructure:"charset" json:"charset"` // MinChars indicates the minimum (inclusive) number of characters from the charset that should appear in the string. MinChars int `mapstructure:"min-chars" json:"min-chars"` }
CharsetRule requires a certain number of characters from the specified charset.
func (CharsetRule) Chars ¶
func (c CharsetRule) Chars() []rune
Chars returns the charset that this rule is looking for.
func (CharsetRule) MinLength ¶
func (c CharsetRule) MinLength() int
func (CharsetRule) Pass ¶
func (c CharsetRule) Pass(value []rune) bool
Pass returns true if the provided candidate string has a minimum number of chars in it. This adheres to the Rule interface
func (CharsetRule) Type ¶
func (c CharsetRule) Type() string
type PolicyParser ¶
type PolicyParser struct { // RuleRegistry maps rule names in HCL to Rule constructors. RuleRegistry Registry }
PolicyParser parses string generator configuration from HCL.
func (PolicyParser) ParsePolicy ¶
func (p PolicyParser) ParsePolicy(raw string) (sg StringGenerator, err error)
ParsePolicy parses the provided HCL into a StringGenerator.
type Registry ¶
type Registry struct { // Rules maps names of rules to a constructor for the rule Rules map[string]ruleConstructor }
Registry of HCL rule names to rule constructors.
type Rule ¶
type Rule interface { // Pass should return true if the provided value passes any assertions this Rule is making. Pass(value []rune) bool // Type returns the name of the rule as associated in the registry Type() string }
Rule to assert on string values.
func ParseCharset ¶
ParseCharset from the provided data map. The data map is expected to be parsed from HCL.
type StringGenerator ¶
type StringGenerator struct { // Length of the string to generate. Length int `mapstructure:"length" json:"length"` // Rules the generated strings must adhere to. Rules serializableRules `mapstructure:"-" json:"rule"` // This is "rule" in JSON so it matches the HCL property type // contains filtered or unexported fields }
StringGenerator generats random strings from the provided charset & adhering to a set of rules. The set of rules are things like CharsetRule which requires a certain number of characters from a sub-charset.
func ParsePolicy ¶
func ParsePolicy(raw string) (gen StringGenerator, err error)
ParsePolicy is a convenience function for parsing HCL into a StringGenerator. See PolicyParser.ParsePolicy for details.
func ParsePolicyBytes ¶
func ParsePolicyBytes(raw []byte) (gen StringGenerator, err error)
ParsePolicyBytes is a convenience function for parsing HCL into a StringGenerator. See PolicyParser.ParsePolicy for details.