Skip to content

Commit 4434f07

Browse files
committed
yoke: infer checksum from path before first dot or extensions
1 parent 8015617 commit 4434f07

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

internal/checksum.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ func ChecksumFromPath(value string) string {
4848
}
4949
return ""
5050
default:
51-
base := path.Base(uri.Path)
51+
base, _, _ := strings.Cut(path.Base(uri.Path), ".")
52+
5253
if sha, ok := strings.CutPrefix(base, "sha256_"); ok {
5354
return sha
5455
}

internal/checksum_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ func TestChecksumFromPath(t *testing.T) {
1313
"oci://registry/module:sha256_" + checksum,
1414
"file://path/to/module_sha256_" + checksum,
1515
"file://path/to/sha256_" + checksum,
16+
"file://path/to/sha256_" + checksum + ".wasm",
17+
"file://path/to/sha256_" + checksum + ".wasm.gz",
1618
"./path/to/sha256_" + checksum,
1719
"https://domain.com/some/module_sha256_" + checksum,
1820
"https://domain.com/some/sha256_" + checksum,
21+
"https://domain.com/some/sha256_" + checksum + ".wasm.gz",
1922
} {
2023
require.Equal(t, checksum, ChecksumFromPath(path))
2124
}
@@ -24,6 +27,8 @@ func TestChecksumFromPath(t *testing.T) {
2427
"oci://registry/module:v1.2.3",
2528
"https://domain.com/sha256/checksum",
2629
"./local/fs/sha1_sha1",
30+
"./local/fs/sha1_sha1.wasm",
31+
"./local/fs/sha1_sha1.wasm.gz",
2732
} {
2833
require.Empty(t, ChecksumFromPath(path))
2934
}

pkg/yoke/yoke.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import (
1111
"strings"
1212
"time"
1313

14+
"gopkg.in/yaml.v3"
15+
1416
"github.com/davidmdm/x/xcontainer"
1517
"github.com/davidmdm/x/xerr"
16-
"gopkg.in/yaml.v3"
1718

1819
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1920
"k8s.io/cli-runtime/pkg/genericclioptions"

0 commit comments

Comments
 (0)