Skip to content

Commit

Permalink
chore: add additional debug info on OCI source validation (#789)
Browse files Browse the repository at this point in the history
  • Loading branch information
decleaver committed Jul 18, 2024
1 parent a2bffc5 commit c62c576
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/pkg/bundle/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ func (b *Bundle) CalculateBuildInfo() error {
// ValidateBundleSignature validates the bundle signature
func ValidateBundleSignature(bundleYAMLPath, signaturePath, publicKeyPath string) error {
if helpers.InvalidPath(bundleYAMLPath) {
if bundleYAMLPath == "" {
return fmt.Errorf("path for %s is empty", config.BundleYAML)
}
return fmt.Errorf("path for %s at %s does not exist", config.BundleYAML, bundleYAMLPath)
}
// The package is not signed, and no public key was provided
Expand Down
25 changes: 20 additions & 5 deletions src/pkg/bundle/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ func (op *ociProvider) LoadBundleMetadata() (types.PathMap, error) {
}
filepaths[rel] = absSha
}

if len(filepaths) == 0 {
errMsg := fmt.Sprintf("failed to load bundle metadata from %s", op.src)
return nil, errors.New(errMsg)
}

return filepaths, nil
}

Expand Down Expand Up @@ -249,9 +255,14 @@ func getOCIValidatedSource(source string) (string, error) {
// Check provided repository path
sourceWithOCI := boci.EnsureOCIPrefix(source)
remote, err := zoci.NewRemote(sourceWithOCI, platform)
var originalErr error
if err == nil {
source = sourceWithOCI
_, err = remote.ResolveRoot(ctx)
if err != nil {
originalErr = err
message.Debugf(err.Error())
}
}
// if root didn't resolve, expand the path
if err != nil {
Expand All @@ -262,25 +273,29 @@ func getOCIValidatedSource(source string) (string, error) {
_, err = remote.ResolveRoot(ctx)
}
if err != nil {
message.Debugf("%s: not found", source)
message.Debugf(err.Error())
// Check in delivery bundle path
source = GHCRDeliveryBundlePath + originalSource
remote, err = zoci.NewRemote(source, platform)
if err == nil {
_, err = remote.ResolveRoot(ctx)
}
if err != nil {
message.Debugf("%s: not found", source)
message.Debugf(err.Error())
// Check in packages bundle path
source = GHCRPackagesPath + originalSource
remote, err = zoci.NewRemote(source, platform)
if err == nil {
_, err = remote.ResolveRoot(ctx)
}
// All checks failed, return error
if err != nil {
errMsg := fmt.Sprintf("%s: not found", originalSource)
message.Debug(errMsg)
return "", errors.New(errMsg)
message.Debugf(err.Error())
if originalErr == nil {
errMsg := fmt.Sprintf("%s: not found", originalSource)
return "", errors.New(errMsg)
}
return "", originalErr
}
}
}
Expand Down

0 comments on commit c62c576

Please sign in to comment.