package asaModels import ( "regexp" "strconv" "github.rackspace.com/gorax/tools/util" ) type PasswordPolicy struct { MinLength int `json:"minimum_length,omitempty"` MinChange int `json:"minimum_changes,omitempty"` MinLower int `json:"minimum_lowercase,omitempty"` MinUpper int `json:"minimum_uppercase,omitempty"` MinNumeric int `json:"minimum_numeric,omitempty"` MinSpecial int `json:"minimum_special,omitempty"` MinLifetime int `json:"lifetime,omitempty"` AuthEnable bool `json:"authenticate-enable,omitempty"` } var ( minLength = regexp.MustCompile(`(?i)password-policy\s+minimum-length\s+(\d+)`) minChange = regexp.MustCompile(`(?i)password-policy\s+minimum-changes\s+(\d+)`) minLower = regexp.MustCompile(`(?i)password-policy\s+minimum-lowercase\s+(\d+)`) minUpper = regexp.MustCompile(`(?i)password-policy\s+minimum-uppercase\s+(\d+)`) minNumeric = regexp.MustCompile(`(?i)password-policy\s+minimum-numeric\s+(\d+)`) minSpecial = regexp.MustCompile(`(?i)password-policy\s+minimum-special\s+(\d+)`) minLifetime = regexp.MustCompile(`(?i)password-policy\s+lifetime\s+(\d+)`) authEnable = regexp.MustCompile(`(?i)password-policy\s+(authenticate-enable)`) ) func (p *PasswordPolicy) Parse(s string) error { p.MinLength = getValue(s, minLength) p.MinChange = getValue(s, minChange) p.MinLower = getValue(s, minLower) p.MinUpper = getValue(s, minUpper) p.MinNumeric = getValue(s, minNumeric) p.MinSpecial = getValue(s, minSpecial) p.MinLifetime = getValue(s, minLifetime) p.AuthEnable = false auth := util.RegexpString(authEnable, s) if auth != "" { p.AuthEnable = true } return nil } func getValue(s string, re *regexp.Regexp) int { match := util.RegexpString(re, s) if match == "" { return 0 } r, err := strconv.Atoi(match) if err != nil { return 0 } return r }