Skip to content
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

feat: add checksum validation to KCL packages #243

Merged
merged 7 commits into from
Nov 21, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Integrate-Checksum/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ func findKCLModFiles(root string) ([]string, error) {
if err != nil {
return nil, fmt.Errorf("error walking directory '%s': %w", root, err)
}

log.Printf("Selected paths: %v", modFilePaths)

return modFilePaths, nil
NishantBansal2003 marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down Expand Up @@ -85,6 +88,8 @@ func resolveDependency(kpmClient *client.KpmClient, packageDir string) (*pkg.Dep
if dependency.Sum, err = utils.HashDir(packageDir); err != nil {
NishantBansal2003 marked this conversation as resolved.
Show resolved Hide resolved
return nil, fmt.Errorf("failed to hash directory '%s': %w", packageDir, err)
}
log.Printf("Successfully hashed directory '%s': Sum = %s", packageDir, dependency.Sum)

dependency.FromKclPkg(kclPkg)

return dependency, nil
Expand Down Expand Up @@ -190,14 +195,16 @@ func processPackage(packageDir string, kpmClient *client.KpmClient, pkgName stri
}

if existingSum, ok := manifest.Annotations[constants.DEFAULT_KCL_OCI_MANIFEST_SUM]; ok && dependency.Sum == existingSum {
fmt.Println("Manifest already up to date with matching checksum.")
fmt.Printf("Manifest already up to date with matching checksum. ExistingSum: %s\n", existingSum)
NishantBansal2003 marked this conversation as resolved.
Show resolved Hide resolved
return nil
}

if err := updateChecksum(manifest, kpmClient, dependency); err != nil {
NishantBansal2003 marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Errorf("failed to update checksum in manifest: %w", err)
}

log.Printf("Successfully updated manifest with new checksum: %s\n", dependency.Sum)

return nil
}

Expand All @@ -221,6 +228,8 @@ func main() {
log.Fatal("Environment variables PKG_NAME or PKG_VERSION are not set")
}

log.Printf("Acquired package info - Name: %s, Version: %s", pkgName, pkgVersion)

kpmClient, err := client.NewKpmClient()
if err != nil {
log.Fatalf("failed to create KPM client: %v", err)
Expand Down
Loading