-
Notifications
You must be signed in to change notification settings - Fork 17
Migrate packages #287
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?
Migrate packages #287
Conversation
SummaryThis PR migrates the codebase from v1 to v2 module structure, updating import paths and API calls. The migration includes moving packages like certificateutil, profileutil, export, exportoptions, and plistutil to the v2 module, replacing third-party dependencies with internal ones, and modernizing APIs with new patterns like ProfileProvider. Walkthrough
|
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.
This is an AI-generated review. Please review it carefully.
Actionable comments posted: 5
for _, certificate := range certificates { | ||
if certificate != nil { | ||
infos = append(infos, NewCertificateInfo(*certificate, nil)) | ||
} | ||
} |
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.
🐛 Bug
Potential nil pointer dereference: The code checks if certificate != nil but then immediately dereferences it with *certificate. If the certificate pointer becomes nil between the check and dereference due to concurrent access, this could cause a panic.
🔄 Suggestion:
for _, certificate := range certificates { | |
if certificate != nil { | |
infos = append(infos, NewCertificateInfo(*certificate, nil)) | |
} | |
} | |
for _, certificate := range certificates { | |
if certificate != nil { | |
cert := *certificate | |
infos = append(infos, NewCertificateInfo(cert, nil)) | |
} | |
} |
for _, certificate := range certificates { | ||
if certificate != nil { | ||
infos = append(infos, NewCertificateInfo(*certificate, nil)) | ||
} | ||
} |
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.
🐛 Bug
Potential nil pointer dereference: The code checks if certificate != nil but then immediately dereferences it with *certificate. If the certificate pointer becomes nil between the check and dereference due to concurrent access, this could cause a panic.
🔄 Suggestion:
for _, certificate := range certificates { | |
if certificate != nil { | |
infos = append(infos, NewCertificateInfo(*certificate, nil)) | |
} | |
} | |
for _, certificate := range certificates { | |
if certificate != nil { | |
cert := *certificate | |
infos = append(infos, NewCertificateInfo(cert, nil)) | |
} | |
} |
if len(certificates) != len(privateKeys) { | ||
return nil, errors.New("pkcs12: different number of certificates and private keys found") | ||
} |
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.
🐛 Bug
Inconsistent error handling: The function checks the length of certificates and privateKeys slices without first validating that both slices are non-nil, which could cause a panic if either slice is nil.
🔄 Suggestion:
if len(certificates) != len(privateKeys) { | |
return nil, errors.New("pkcs12: different number of certificates and private keys found") | |
} | |
if certificates == nil || privateKeys == nil { | |
return nil, errors.New("pkcs12: certificates or private keys slice is nil") | |
} | |
if len(certificates) != len(privateKeys) { | |
return nil, errors.New("pkcs12: different number of certificates and private keys found") | |
} |
pattern := `(?s)(-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----)` | ||
matches := regexp.MustCompile(pattern).FindAllString(out, -1) |
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.
🐛 Bug
Regex compilation inefficiency: The regex pattern is compiled inside the function on every call. For better performance and to avoid potential regex compilation errors at runtime, this should be compiled once as a package-level variable.
🔄 Suggestion:
pattern := `(?s)(-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----)` | |
matches := regexp.MustCompile(pattern).FindAllString(out, -1) | |
var certificatePattern = regexp.MustCompile(`(?s)(-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----)`) | |
func normalizeFindCertificateOut(out string) ([]string, error) { | |
certificateContents := []string{} | |
matches := certificatePattern.FindAllString(out, -1) |
missingEntitlements := []string{} | ||
|
||
for key := range targetEntitlements { | ||
_, known := profileutil.KnownProfileCapabilitiesMap[profileType][key] |
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.
🐛 Bug
Potential nil pointer dereference: The code accesses profileutil.KnownProfileCapabilitiesMap[profileType][key] without checking if profileutil.KnownProfileCapabilitiesMap[profileType] exists first. This will cause a panic if an unsupported profileType (like ProfileTypeTvOs) is passed.
🔄 Suggestion:
_, known := profileutil.KnownProfileCapabilitiesMap[profileType][key] | |
profileCapabilities, exists := profileutil.KnownProfileCapabilitiesMap[profileType] | |
if !exists { | |
continue | |
} | |
_, known := profileCapabilities[key] |
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.
This is an AI-generated review. Please review it carefully.
Actionable comments posted: 3
} | ||
|
||
func installedCodesigningCertificateNamesFromOutput(out string) ([]string, error) { | ||
pettern := `^[0-9]+\) (?P<hash>.*) "(?P<name>.*)"` |
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.
🐛 Bug
Variable name typo: 'pettern' should be 'pattern'. This will cause a compilation error as the variable is used on the next line but never declared correctly.
🔄 Suggestion:
pettern := `^[0-9]+\) (?P<hash>.*) "(?P<name>.*)"` | |
pattern := `^[0-9]+\) (?P<hash>.*) "(?P<name>.*)"` |
missingEntitlements := []string{} | ||
|
||
for key := range targetEntitlements { | ||
_, known := profileutil.KnownProfileCapabilitiesMap[profileType][key] |
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.
🐛 Bug
Potential map access panic when profileType doesn't exist as a key in KnownProfileCapabilitiesMap. If an unsupported profile type (like ProfileTypeTvOs) is passed, this will cause a runtime panic when trying to access the nested map.
🔄 Suggestion:
_, known := profileutil.KnownProfileCapabilitiesMap[profileType][key] | |
capabilitiesMap, exists := profileutil.KnownProfileCapabilitiesMap[profileType] | |
if !exists { | |
continue | |
} | |
_, known := capabilitiesMap[key] |
profileutil/util.go
Outdated
return nil, err | ||
} | ||
|
||
pattern := filepath.Join(pathutil.EscapeGlobPath(absProvProfileDirPath), "*"+ext) |
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.
🐛 Bug
Function pathutil.EscapeGlobPath does not exist in the github.com/bitrise-io/go-utils/pathutil package. This will cause a compilation error when the code is built.
🔄 Suggestion:
pattern := filepath.Join(pathutil.EscapeGlobPath(absProvProfileDirPath), "*"+ext) | |
pattern := filepath.Join(absProvProfileDirPath, "*"+ext) |
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.
This is an AI-generated review. Please review it carefully.
Actionable comments posted: 4
return nil, err | ||
} | ||
} | ||
content, err := os.ReadFile(pth) |
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.
🐛 Bug
Potential nil pointer dereference when pth is empty string. If both iOS and tvOS profile lookups fail to find a profile (both return empty path), pth will be empty and os.ReadFile will fail with a misleading error.
🔄 Suggestion:
content, err := os.ReadFile(pth) | |
if pth == "" { | |
return nil, fmt.Errorf("provisioning profile with UUID %s not found", info.UUID) | |
} | |
content, err := os.ReadFile(pth) |
casted, ok := value.(uint64) | ||
if !ok { | ||
return 0, false | ||
} |
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.
🐛 Bug
Potential type casting issue: plist library may unmarshal integers as different numeric types (int, int64, float64) depending on the source format and value range, but this method only accepts uint64.
🔄 Suggestion:
casted, ok := value.(uint64) | |
if !ok { | |
return 0, false | |
} | |
// Try direct uint64 cast first | |
if casted, ok := value.(uint64); ok { | |
return casted, true | |
} | |
// Handle other numeric types that plist might unmarshal to | |
switch v := value.(type) { | |
case int: | |
if v >= 0 { | |
return uint64(v), true | |
} | |
case int64: | |
if v >= 0 { | |
return uint64(v), true | |
} | |
case float64: | |
if v >= 0 && v == float64(uint64(v)) { | |
return uint64(v), true | |
} | |
} | |
return 0, false |
casted, ok := v.(uint64) | ||
if !ok { | ||
return nil, false | ||
} |
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.
🐛 Bug
Potential type casting issue: similar to GetUInt64, this array method may fail when plist library unmarshals integers as different numeric types (int, int64, float64).
🔄 Suggestion:
casted, ok := v.(uint64) | |
if !ok { | |
return nil, false | |
} | |
// Try direct uint64 cast first | |
if casted, ok := v.(uint64); ok { | |
array = append(array, casted) | |
continue | |
} | |
// Handle other numeric types that plist might unmarshal to | |
switch val := v.(type) { | |
case int: | |
if val >= 0 { | |
array = append(array, uint64(val)) | |
continue | |
} | |
case int64: | |
if val >= 0 { | |
array = append(array, uint64(val)) | |
continue | |
} | |
case float64: | |
if val >= 0 && val == float64(uint64(val)) { | |
array = append(array, uint64(val)) | |
continue | |
} | |
} | |
return nil, false |
func (profile PlistData) GetName() string { | ||
data := plistutil.PlistData(profile) | ||
uuid, _ := data.GetString("Name") | ||
return uuid |
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.
🐛 Bug
Returning wrong variable: should return 'name' instead of 'uuid'
🔄 Suggestion:
return uuid | |
return name |
No description provided.