-
Notifications
You must be signed in to change notification settings - Fork 16
Move export to v2/codesigngroup #310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
973a8eb
48ce7ce
f00632d
43a5044
7879c3e
41284d1
9ece977
88af6a0
9179ae5
07faf32
e4670ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| package codesigngroup | ||
|
|
||
| import ( | ||
| "sort" | ||
|
|
||
| "github.com/bitrise-io/go-xcode/certificateutil" | ||
| "github.com/bitrise-io/go-xcode/profileutil" | ||
| "github.com/ryanuber/go-glob" | ||
| ) | ||
|
|
||
| // CodeSignGroup ... | ||
| type CodeSignGroup interface { | ||
| Certificate() certificateutil.CertificateInfoModel | ||
| InstallerCertificate() *certificateutil.CertificateInfoModel | ||
| BundleIDProfileMap() map[string]profileutil.ProvisioningProfileInfoModel | ||
| } | ||
|
|
||
| // SelectableCodeSignGroup ... | ||
| type SelectableCodeSignGroup struct { | ||
| Certificate certificateutil.CertificateInfoModel | ||
| BundleIDProfilesMap map[string][]profileutil.ProvisioningProfileInfoModel | ||
| } | ||
|
|
||
| func containsCertificate(installedCertificates []certificateutil.CertificateInfoModel, certificate certificateutil.CertificateInfoModel) bool { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: I suggest using a bit more generic param names, maybe utilising |
||
| for _, cert := range installedCertificates { | ||
| if cert.Serial == certificate.Serial { | ||
| return true | ||
| } | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| // BuildFilterableList ... | ||
| func BuildFilterableList(installedCertificates []certificateutil.CertificateInfoModel, profiles []profileutil.ProvisioningProfileInfoModel, bundleIDs []string) []SelectableCodeSignGroup { | ||
| groups := []SelectableCodeSignGroup{} | ||
|
|
||
| serialToProfiles := map[string][]profileutil.ProvisioningProfileInfoModel{} | ||
| serialToCertificate := map[string]certificateutil.CertificateInfoModel{} | ||
| for _, profile := range profiles { | ||
| for _, certificate := range profile.DeveloperCertificates { | ||
| if !containsCertificate(installedCertificates, certificate) { | ||
| continue | ||
| } | ||
|
|
||
| certificateProfiles, ok := serialToProfiles[certificate.Serial] | ||
| if !ok { | ||
| certificateProfiles = []profileutil.ProvisioningProfileInfoModel{} | ||
| } | ||
| certificateProfiles = append(certificateProfiles, profile) | ||
| serialToProfiles[certificate.Serial] = certificateProfiles | ||
| serialToCertificate[certificate.Serial] = certificate | ||
| } | ||
| } | ||
|
|
||
| for serial, profiles := range serialToProfiles { | ||
| certificate := serialToCertificate[serial] | ||
|
|
||
| bundleIDToProfiles := map[string][]profileutil.ProvisioningProfileInfoModel{} | ||
| for _, bundleID := range bundleIDs { | ||
|
|
||
| matchingProfiles := []profileutil.ProvisioningProfileInfoModel{} | ||
| for _, profile := range profiles { | ||
| if !glob.Glob(profile.BundleID, bundleID) { | ||
| continue | ||
| } | ||
|
|
||
| matchingProfiles = append(matchingProfiles, profile) | ||
| } | ||
|
|
||
| if len(matchingProfiles) > 0 { | ||
| sort.Sort(ByBundleIDLength(matchingProfiles)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: this slice sort also could be simpler (and without the additional sort helper structure The slices.SortFunc comparator returns:
Since we want to sort by descending length (longest first), we return len(b.BundleID) - len(a.BundleID). |
||
| bundleIDToProfiles[bundleID] = matchingProfiles | ||
| } | ||
| } | ||
|
|
||
| if len(bundleIDToProfiles) == len(bundleIDs) { | ||
| group := SelectableCodeSignGroup{ | ||
| Certificate: certificate, | ||
| BundleIDProfilesMap: bundleIDToProfiles, | ||
| } | ||
| groups = append(groups, group) | ||
| } | ||
| } | ||
|
|
||
| return groups | ||
| } | ||
|
|
||
| // ByBundleIDLength ... | ||
| type ByBundleIDLength []profileutil.ProvisioningProfileInfoModel | ||
|
|
||
| // Len .. | ||
| func (s ByBundleIDLength) Len() int { | ||
| return len(s) | ||
| } | ||
|
|
||
| // Swap ... | ||
| func (s ByBundleIDLength) Swap(i, j int) { | ||
| s[i], s[j] = s[j], s[i] | ||
| } | ||
|
|
||
| // Less ... | ||
| func (s ByBundleIDLength) Less(i, j int) bool { | ||
| return len(s[i].BundleID) > len(s[j].BundleID) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this interface used?