package pkg import ( "regexp" "strings" "github.rackspace.com/gorax/tools/util" ) var ( moduleSerialRegex = regexp.MustCompile(`(?i)(.*?)\s+\((\S+-\S+)\)`) ) type ( SysLicense struct { LicVersion string `json:"licensed_version"` RegKey string `json:"registration_key"` LicOn string `json:"licensed_on"` SrvcChkDate string `json:"service_check_date"` PlatformId string `json:"platform_id"` AppSerialNum string `json:"appliance_serial_number"` ActiveModules []*LicModule `json:"active_modules"` InactiveModules []*LicModule } LicModule struct { Name string `json:"module_name"` Serial string `json:"module_serial"` } ) func ParseSysLicense(raw string) *SysLicense { s := new(SysLicense) s.LicVersion = util.RegexpString(regexp.MustCompile(`(?i)licensed\s+version\s+(\S+)`), raw) s.RegKey = util.RegexpString(regexp.MustCompile(`(?i)registration\s+key\s+(\S+)`), raw) s.LicOn = util.RegexpString(regexp.MustCompile(`(?i)licensed\s+on\s+(\S+)`), raw) s.SrvcChkDate = util.RegexpString(regexp.MustCompile(`(?i)service\s+check\s+date\s+(\S+)`), raw) s.PlatformId = util.RegexpString(regexp.MustCompile(`(?i)platform\s+id\s+(\S+)`), raw) s.AppSerialNum = util.RegexpString(regexp.MustCompile(`(?i)appliance\s+serial\s+number\s+(\S+)`), raw) modules := util.RegexpString(regexp.MustCompile(`(?i)active\s+modules((.|\n)*?)(\n\S|$)`), raw) for _, am := range moduleSerialRegex.FindAllStringSubmatch(modules, -1) { s.ActiveModules = append(s.ActiveModules, &LicModule{ Name: strings.Trim(am[1], " "), Serial: am[2], }) } modules = util.RegexpString(regexp.MustCompile(`(?i)inactive\s+modules((.|\n)*?)(\n\S|$)`), raw) for _, am := range moduleSerialRegex.FindAllStringSubmatch(modules, -1) { s.InactiveModules = append(s.InactiveModules, &LicModule{ Name: am[1], Serial: am[2], }) } return s }