Skip to content

Commit 2064bbc

Browse files
authored
Merge pull request #13 from criteo/fix/checksum-accept-sha256-hex
fix(checksum): accept raw SHA256 hex and update docs/tests
2 parents b250cf9 + d1232f3 commit 2064bbc

13 files changed

Lines changed: 48 additions & 49 deletions

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export COLA_REGISTRY_SESSION_TOKEN=admin:admin
108108

109109
# Publish a version
110110
./bin/cola-regctl version create my-tools my-cli 1.0.0 \
111-
--checksum "sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" \
111+
--checksum "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" \
112112
--url "https://downloads.example.com/my-cli-1.0.0.zip" \
113113
--start-partition 0 \
114114
--end-partition 9
@@ -175,7 +175,7 @@ curl -X POST http://localhost:8080/api/v1/registry/build/package/hotfix/version
175175
-d '{
176176
"name":"hotfix",
177177
"version":"1.0.0",
178-
"checksum":"sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
178+
"checksum":"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
179179
"url":"https://example.com/hotfix-1.0.0.zip",
180180
"startPartition":0,
181181
"endPartition":9
@@ -540,7 +540,7 @@ cola-regctl package delete <registry> <package>
540540
```bash
541541
# Publish a version
542542
cola-regctl version create <registry> <package> <version> \
543-
--checksum "sha256:abc123..." \
543+
--checksum "abc123..." \
544544
--url "https://downloads.example.com/package-1.0.0.zip" \
545545
--start-partition 0 \
546546
--end-partition 9
@@ -589,14 +589,14 @@ cola-regctl package create build-tools deployer \
589589

590590
# Publish version 1.0.0 (for partitions 0-4 = 50% rollout)
591591
cola-regctl version create build-tools deployer 1.0.0 \
592-
--checksum "sha256:abc123..." \
592+
--checksum "abc123..." \
593593
--url "https://cdn.example.com/deployer-1.0.0.tar.gz" \
594594
--start-partition 0 \
595595
--end-partition 4
596596

597597
# Publish version 1.1.0 (for partitions 5-9 = 50% rollout)
598598
cola-regctl version create build-tools deployer 1.1.0 \
599-
--checksum "sha256:def456..." \
599+
--checksum "def456..." \
600600
--url "https://cdn.example.com/deployer-1.1.0.tar.gz" \
601601
--start-partition 5 \
602602
--end-partition 9

docs/openapi.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -610,9 +610,9 @@ components:
610610
example: '1.0.0'
611611
checksum:
612612
type: string
613-
description: SHA256 checksum with prefix
614-
pattern: '^sha256:[a-f0-9]{64}$'
615-
example: 'sha256:abc123def456...'
613+
description: SHA256 checksum (64 hex characters)
614+
pattern: '^[a-f0-9]{64}$'
615+
example: 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
616616
url:
617617
type: string
618618
format: uri
@@ -803,8 +803,8 @@ components:
803803
example: '1.0.0'
804804
checksum:
805805
type: string
806-
pattern: '^sha256:[a-f0-9]{64}$'
807-
example: 'sha256:abc123def456789...'
806+
pattern: '^[a-f0-9]{64}$'
807+
example: 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
808808
url:
809809
type: string
810810
format: uri
@@ -832,8 +832,8 @@ components:
832832
example: '1.0.0'
833833
checksum:
834834
type: string
835-
pattern: '^sha256:[a-f0-9]{64}$'
836-
example: 'sha256:abc123def456789...'
835+
pattern: '^[a-f0-9]{64}$'
836+
example: 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
837837
url:
838838
type: string
839839
format: uri

docs/presentation-registry-client.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ cola-regctl version push mypackage 1.2.0 \
325325
cola-regctl version push mypackage 1.2.0 \
326326
--platform darwin --arch arm64 \
327327
--artifact ./build/mypackage-darwin-arm64 \
328-
--checksum sha256:abc123...
328+
--checksum e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
329329
```
330330

331331
---

docs/presentation-registry-server.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Registry (Organization/Team Level)
119119
120120
└── Version (Release Level)
121121
├── version: "1.2.0"
122-
├── checksum: "sha256:abc..."
122+
├── checksum: "e3b0c44298fc..."
123123
├── url: "https://cdn/deployer-1.2.0.tar.gz"
124124
├── startPartition: 0
125125
└── endPartition: 9
@@ -366,7 +366,7 @@ curl -X POST http://localhost:8080/api/v1/registry -u admin:password \
366366
curl http://localhost:8080/api/v1/registry/devops-tools/index.json
367367
```
368368
```json
369-
[{"name": "deployer", "version": "1.0.0", "checksum": "sha256:...",
369+
[{"name": "deployer", "version": "1.0.0", "checksum": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
370370
"url": "https://cdn/deployer-1.0.0.tar.gz", "startPartition": 0, "endPartition": 9}]
371371
```
372372

@@ -388,7 +388,7 @@ curl -X POST http://localhost:8080/api/v1/registry/devops-tools/package -u admin
388388
curl -X POST http://localhost:8080/api/v1/registry/devops-tools/package/deployer/version \
389389
-u admin:password -H "Content-Type: application/json" \
390390
-d '{"name": "deployer", "version": "1.2.0",
391-
"checksum": "sha256:e3b0c44298fc1c149afbf4c8996fb924...",
391+
"checksum": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
392392
"url": "https://cdn.company.com/deployer-1.2.0-linux-amd64.tar.gz",
393393
"startPartition": 0, "endPartition": 9}'
394394
```
@@ -524,8 +524,8 @@ Valid: 1.0.0, 2.1.3-alpha, 3.0.0-beta.1+build.123
524524

525525
### Checksum Format
526526
```go
527-
Pattern: sha256:[64 hex characters]
528-
Example: sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
527+
Pattern: [64 hex characters]
528+
Example: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
529529
```
530530

531531
### Custom Values

docs/quickstart.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export COLA_REGISTRY_SESSION_TOKEN=admin:admin # If auth enabled
267267

268268
```bash
269269
./bin/cola-regctl version create my-tools deployment-cli 1.0.0 \
270-
--checksum "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" \
270+
--checksum "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" \
271271
--url "https://releases.example.com/deployment-cli-1.0.0.tar.gz" \
272272
--start-partition 0 \
273273
--end-partition 9
@@ -285,7 +285,7 @@ Output:
285285
{
286286
"name": "deployment-cli",
287287
"version": "1.0.0",
288-
"checksum": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
288+
"checksum": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
289289
"url": "https://releases.example.com/deployment-cli-1.0.0.tar.gz",
290290
"startPartition": 0,
291291
"endPartition": 9

internal/client/commands/version.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"io"
77
"net/http"
8-
"strings"
98

109
"github.com/criteo/command-launcher-registry/internal/client/errors"
1110
"github.com/criteo/command-launcher-registry/internal/client/output"
@@ -65,7 +64,7 @@ func init() {
6564
versionCmd.AddCommand(versionDeleteCmd)
6665

6766
// Create flags
68-
versionCreateCmd.Flags().StringVar(&versionChecksum, "checksum", "", "Checksum in format 'sha256:hash' (required)")
67+
versionCreateCmd.Flags().StringVar(&versionChecksum, "checksum", "", "SHA256 checksum (64 hex characters) (required)")
6968
versionCreateCmd.Flags().StringVar(&versionURL, "url", "", "Download URL (required)")
7069
versionCreateCmd.Flags().IntVar(&versionStartPart, "start-partition", 0, "Start partition (0-9)")
7170
versionCreateCmd.Flags().IntVar(&versionEndPart, "end-partition", 9, "End partition (0-9)")
@@ -78,18 +77,13 @@ func init() {
7877
}
7978

8079
func validateChecksum(checksum string) error {
81-
if !strings.HasPrefix(checksum, "sha256:") {
82-
return fmt.Errorf("checksum must start with 'sha256:'")
80+
if len(checksum) != 64 {
81+
return fmt.Errorf("checksum must be exactly 64 hexadecimal characters")
8382
}
8483

85-
hash := strings.TrimPrefix(checksum, "sha256:")
86-
if len(hash) != 64 {
87-
return fmt.Errorf("sha256 hash must be exactly 64 hexadecimal characters")
88-
}
89-
90-
for _, c := range hash {
84+
for _, c := range checksum {
9185
if !((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) {
92-
return fmt.Errorf("sha256 hash must contain only hexadecimal characters")
86+
return fmt.Errorf("checksum must contain only hexadecimal characters")
9387
}
9488
}
9589

internal/client/validation/validators.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ import (
55
"strings"
66
)
77

8-
// ValidateChecksum validates checksum format (must start with "sha256:")
8+
// ValidateChecksum validates checksum format (must be 64 hex characters)
99
func ValidateChecksum(checksum string) error {
10-
if !strings.HasPrefix(checksum, "sha256:") {
11-
return fmt.Errorf("invalid checksum format. Expected 'sha256:hash', got: '%s'", checksum)
10+
if len(checksum) != 64 {
11+
return fmt.Errorf("invalid checksum format. Expected 64 hexadecimal characters (SHA256), got: '%s'", checksum)
12+
}
13+
for _, c := range checksum {
14+
if !((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) {
15+
return fmt.Errorf("checksum must contain only hexadecimal characters, got: '%s'", checksum)
16+
}
1217
}
1318
return nil
1419
}

internal/models/models.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type Package struct {
2222
type Version struct {
2323
Name string `json:"name"` // Package name (denormalized for index.json)
2424
Version string `json:"version"`
25-
Checksum string `json:"checksum"` // SHA256 with "sha256:" prefix
25+
Checksum string `json:"checksum"` // SHA256 hash (64 hex characters)
2626
URL string `json:"url"` // Download URL
2727
StartPartition int `json:"startPartition"` // 0-9
2828
EndPartition int `json:"endPartition"` // 0-9

internal/models/validation.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ var (
1414
// Semantic version pattern (simplified - supports major.minor.patch with optional pre-release and build metadata)
1515
versionPattern = regexp.MustCompile(`^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$`)
1616

17-
// Checksum pattern: sha256: followed by 64 hex characters
18-
checksumPattern = regexp.MustCompile(`^sha256:[a-f0-9]{64}$`)
17+
// Checksum pattern: 64 hex characters (SHA256)
18+
checksumPattern = regexp.MustCompile(`^[a-f0-9]{64}$`)
1919

2020
// Custom values key pattern
2121
customKeyPattern = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_-]{0,63}$`)
@@ -70,7 +70,7 @@ func ValidateChecksum(checksum string) error {
7070
return &ValidationError{Field: "checksum", Message: "checksum is required"}
7171
}
7272
if !checksumPattern.MatchString(checksum) {
73-
return &ValidationError{Field: "checksum", Message: "checksum must match format sha256:[64 hex characters]"}
73+
return &ValidationError{Field: "checksum", Message: "checksum must be 64 hexadecimal characters (SHA256)"}
7474
}
7575
return nil
7676
}

scripts/populate-test-data-cli.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ echo
7676
# Create version 1.0.0 for deployment-cli
7777
echo "Creating version 1.0.0 for deployment-cli..."
7878
${CLI} version create company-tools deployment-cli 1.0.0 \
79-
--checksum "sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" \
79+
--checksum "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" \
8080
--url "https://downloads.example.com/deployment-cli/1.0.0/deployment-cli.zip" \
8181
--start-partition 0 \
8282
--end-partition 4
@@ -85,7 +85,7 @@ echo
8585
# Create version 1.1.0 for deployment-cli
8686
echo "Creating version 1.1.0 for deployment-cli..."
8787
${CLI} version create company-tools deployment-cli 1.1.0 \
88-
--checksum "sha256:fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210" \
88+
--checksum "fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210" \
8989
--url "https://downloads.example.com/deployment-cli/1.1.0/deployment-cli.zip" \
9090
--start-partition 5 \
9191
--end-partition 9
@@ -103,7 +103,7 @@ echo
103103
# Create version 2.0.0 for data-sync
104104
echo "Creating version 2.0.0 for data-sync..."
105105
${CLI} version create company-tools data-sync 2.0.0 \
106-
--checksum "sha256:abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789" \
106+
--checksum "abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789" \
107107
--url "https://downloads.example.com/data-sync/2.0.0/data-sync.pkg" \
108108
--start-partition 0 \
109109
--end-partition 9
@@ -119,7 +119,7 @@ echo
119119
# Create version 3.5.2 for monitoring-agent
120120
echo "Creating version 3.5.2 for monitoring-agent..."
121121
${CLI} version create company-tools monitoring-agent 3.5.2 \
122-
--checksum "sha256:9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba" \
122+
--checksum "9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba" \
123123
--url "https://downloads.example.com/monitoring-agent/3.5.2/monitoring-agent.pkg" \
124124
--start-partition 0 \
125125
--end-partition 9

0 commit comments

Comments
 (0)