package pkg import ( "errors" "strconv" "strings" ) type CertificateAuthorityProfile struct { ProfileCommon AuthenticationDepth int `json:"authenticate_depth"` CAFile string `json:"ca_file"` CRLFile string `json:"crl_file"` LocationSpecific string `json:"location_specific"` UpdateCRL string `json:"update_crl"` } func ParseCertificateAuthorityProfile(raw string) (*CertificateAuthorityProfile, error) { p := new(CertificateAuthorityProfile) split := strings.Split(raw, "\n") if !strings.Contains(split[0], "ltm profile certificate-authority") { return nil, errors.New("not a certificate-authority profile") } p.ProfileCommon = parseCommon(raw) for _, line := range split { f := strings.Fields(line) switch strings.ToLower(f[0]) { case "authenticate-depth": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.AuthenticationDepth = i case "ca-file": p.CAFile = strings.Join(f[1:], " ") case "crl-file": p.CRLFile = strings.Join(f[1:], " ") case "location-specific": p.LocationSpecific = strings.Join(f[1:], " ") case "update-crl": p.UpdateCRL = strings.Join(f[1:], " ") } } return p, nil }