func parseCodeSigningSettingsFromXcodeOutput(xcodeOutput string) (common.CodeSigningSettings, error) { logReader := bufio.NewReader(strings.NewReader(xcodeOutput)) identitiesMap := map[string]common.CodeSigningIdentityInfo{} provProfilesMap := map[string]provprofile.ProvisioningProfileInfo{} teamIDsMap := map[string]interface{}{} appIDsMap := map[string]interface{}{} // scan log line by line { line, readErr := readerutil.ReadLongLine(logReader) for ; readErr == nil; line, readErr = readerutil.ReadLongLine(logReader) { // Team ID if rexp := regexp.MustCompile(`^[[:space:]]*"com.apple.developer.team-identifier" = (?P<teamid>[a-zA-Z0-9]+);$`); rexp.MatchString(line) { results, isFound := regexputil.NamedFindStringSubmatch(rexp, line) if !isFound { log.Error("Failed to scan TeamID: not found in the logs") continue } teamIDsMap[results["teamid"]] = 1 } // App Bundle ID if rexp := regexp.MustCompile(`^[[:space:]]*"application-identifier" = "(?P<appbundleid>.+)";$`); rexp.MatchString(line) { results, isFound := regexputil.NamedFindStringSubmatch(rexp, line) if !isFound { log.Error("Failed to scan App Bundle ID: not found in the logs") continue } appIDsMap[results["appbundleid"]] = 1 } // Signing Identity if rexp := regexp.MustCompile(`^[[:space:]]*Signing Identity:[[:space:]]*"(?P<title>.+)"$`); rexp.MatchString(line) { results, isFound := regexputil.NamedFindStringSubmatch(rexp, line) if !isFound { log.Error("Failed to scan Signing Identity title: not found in the logs") continue } codeSigningID := common.CodeSigningIdentityInfo{Title: results["title"]} identitiesMap[codeSigningID.Title] = codeSigningID } // Prov. Profile - title line if rexp := regexp.MustCompile(`^[[:space:]]*Provisioning Profile:[[:space:]]*"(?P<title>.+)"$`); rexp.MatchString(line) { results, isFound := regexputil.NamedFindStringSubmatch(rexp, line) if !isFound { log.Error("Failed to scan Provisioning Profile title: not found in the logs") continue } tmpProvProfile := provprofile.ProvisioningProfileInfo{Title: results["title"]} // read next line line, readErr = readerutil.ReadLongLine(logReader) if readErr != nil { continue } if line == "" { log.Error("Failed to scan Provisioning Profile UUID: no more lines to scan") continue } provProfileUUIDLine := line rexp = regexp.MustCompile(`^[[:space:]]*\((?P<uuid>[a-zA-Z0-9-]{36})\)`) results, isFound = regexputil.NamedFindStringSubmatch(rexp, provProfileUUIDLine) if !isFound { log.Errorf("Failed to scan Provisioning Profile UUID: pattern not found | line was: %s", provProfileUUIDLine) continue } tmpProvProfile.UUID = results["uuid"] provProfilesMap[tmpProvProfile.Title] = tmpProvProfile } } if readErr != nil && readErr != io.EOF { return common.CodeSigningSettings{}, fmt.Errorf("Failed to scan log output, error: %s", readErr) } } identities := []common.CodeSigningIdentityInfo{} for _, v := range identitiesMap { identities = append(identities, v) } provProfiles := []provprofile.ProvisioningProfileInfo{} for _, v := range provProfilesMap { provProfiles = append(provProfiles, v) } teamIDs := maputil.KeysOfStringInterfaceMap(teamIDsMap) appIDs := maputil.KeysOfStringInterfaceMap(appIDsMap) return common.CodeSigningSettings{ Identities: identities, ProvProfiles: provProfiles, TeamIDs: teamIDs, AppIDs: appIDs, }, nil }
func parseCodeSigningSettingsFromOutput(logOutput string) (common.CodeSigningSettings, error) { logReader := bufio.NewReader(strings.NewReader(logOutput)) identitiesMap := map[string]common.CodeSigningIdentityInfo{} provProfilesMap := map[string]provprofile.ProvisioningProfileInfo{} teamIDsMap := map[string]interface{}{} appIDsMap := map[string]interface{}{} // scan log line by line { line, readErr := readerutil.ReadLongLine(logReader) for ; readErr == nil; line, readErr = readerutil.ReadLongLine(logReader) { // App ID if rexp := regexp.MustCompile(`^[[:space:]]*App Id: (?P<appid>.+)$`); rexp.MatchString(line) { results, isFound := regexputil.NamedFindStringSubmatch(rexp, line) if !isFound { log.Error("Failed to scan App Bundle ID: not found in the logs") continue } appID := results["appid"] comps := strings.Split(appID, ".") if len(comps) < 2 { log.Errorf("Invalid App ID, does not include '.': %s", appID) continue } teamID := comps[0] if teamID == "" { log.Errorf("Invalid App ID, Team ID was empty: %s", appID) continue } teamIDsMap[teamID] = 1 appIDsMap[appID] = 1 } // Signing Identity if rexp := regexp.MustCompile(`^[[:space:]]*Code Signing Key: "(?P<title>.+)" \((?P<identityid>[a-zA-Z0-9]+)\)$`); rexp.MatchString(line) { results, isFound := regexputil.NamedFindStringSubmatch(rexp, line) if !isFound { log.Error("Failed to scan Signing Identity title: not found in the logs") continue } codeSigningID := common.CodeSigningIdentityInfo{Title: results["title"]} identitiesMap[codeSigningID.Title] = codeSigningID } // Prov. Profile - title line if rexp := regexp.MustCompile(`^[[:space:]]*Provisioning Profile: "(?P<title>.+)" \((?P<uuid>[a-zA-Z0-9-]+)\)$`); rexp.MatchString(line) { results, isFound := regexputil.NamedFindStringSubmatch(rexp, line) if !isFound { log.Error("Failed to scan Provisioning Profile: not found in the logs") continue } tmpProvProfile := provprofile.ProvisioningProfileInfo{Title: results["title"]} tmpProvProfile.UUID = results["uuid"] provProfilesMap[tmpProvProfile.Title] = tmpProvProfile } } if readErr != nil && readErr != io.EOF { return common.CodeSigningSettings{}, fmt.Errorf("Failed to scan log output, error: %s", readErr) } } identities := []common.CodeSigningIdentityInfo{} for _, v := range identitiesMap { identities = append(identities, v) } provProfiles := []provprofile.ProvisioningProfileInfo{} for _, v := range provProfilesMap { provProfiles = append(provProfiles, v) } teamIDs := maputil.KeysOfStringInterfaceMap(teamIDsMap) appIDs := maputil.KeysOfStringInterfaceMap(appIDsMap) return common.CodeSigningSettings{ Identities: identities, ProvProfiles: provProfiles, TeamIDs: teamIDs, AppIDs: appIDs, }, nil }