package parsers import ( "regexp" "github.rackspace.com/gorax/tools/util" ) var ( sslProfilesRE = regexp.MustCompile(`(?i)(sl|ssl)\s+profile\s+(\S+)((.|\n)*?)(\ns|\n!)`) keyPairRE = regexp.MustCompile(`(?i)keypair-file\s+(\S+)`) certFileRE = regexp.MustCompile(`(?i)certificate-file\s+(\S+)`) cipherSuiteRE = regexp.MustCompile(`(?i)cipher-suite\s+(\S+)`) sessionCacheRE = regexp.MustCompile(`(?i)session-cache\s+(\S+)`) tcpProfileRE = regexp.MustCompile(`(?i)tcp-profile\s+(\S+)`) allowSelfSignedRE = regexp.MustCompile(`(?i)(allow-self-signed-cert)`) enableCertChainingRE = regexp.MustCompile(`(?i)(enable-certificate-chaining)`) caCertFile = regexp.MustCompile(`(?i)ca-cert-file\s+(\S+)`) ) type ( // AdxSslProfiles is the parent type defining a listing of all // ssl-profiles in the ADX configuration. AdxSslProfiles struct { SslProfiles []AdxSslProfile `json:"ssl_profiles"` } // AdxSslProfile type defines all the parsable attributes for the SSL profile configruation AdxSslProfile struct { Name string `json:"name"` KeyPair string `json:"keypair-file"` CertFile string `json:"certificate-file"` CipherSuite []string `json:"cipher-suite"` SessionCache string `json:"session-cache"` TcpProfile string `json:"tcp-profile"` AllowSelfSigned bool `json:"allow-self-signed-cert"` EnableCertChaining bool `json:"enable-certificate-chaining"` CaCertFile string `json:"ca-cert-file"` } ) // Parse method is used to implement type population of a given string // using parsers to populate the method receiver. func (a *AdxSslProfiles) Parse(s *string) { for _, i := range sslProfilesRE.FindAllStringSubmatch(*s, -1) { a.SslProfiles = append(a.SslProfiles, AdxSslProfile{ Name: i[2], KeyPair: util.RegexpFindString(keyPairRE, i[3]), CertFile: util.RegexpFindString(certFileRE, i[3]), CipherSuite: func(x string) []string { var l []string for _, k := range cipherSuiteRE.FindAllStringSubmatch(x, -1) { l = append(l, k[1]) } return l }(i[3]), SessionCache: util.RegexpFindString(sessionCacheRE, i[3]), TcpProfile: util.RegexpFindString(tcpProfileRE, i[3]), AllowSelfSigned: allowSelfSignedRE.MatchString(i[3]), EnableCertChaining: enableCertChainingRE.MatchString(i[3]), CaCertFile: util.RegexpFindString(caCertFile, i[3]), }) } }