Skip to content

Commit cdc7776

Browse files
committed
Upgrades internal from constellation to 5b0073ffe87a3bfb5592e1686ac4a16d3ba553ca
1 parent 1a28167 commit cdc7776

File tree

178 files changed

+570
-11655
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

178 files changed

+570
-11655
lines changed

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ require (
179179
github.com/josharian/intern v1.0.0 // indirect
180180
github.com/json-iterator/go v1.1.12 // indirect
181181
github.com/klauspost/compress v1.17.9 // indirect
182+
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
182183
github.com/kylelemons/godebug v1.1.0 // indirect
183184
github.com/leodido/go-urn v1.4.0 // indirect
184185
github.com/letsencrypt/boulder v0.0.0-20240620165639-de9c06129bec // indirect
@@ -225,7 +226,7 @@ require (
225226
golang.org/x/net v0.33.0 // indirect
226227
golang.org/x/oauth2 v0.21.0 // indirect
227228
golang.org/x/sync v0.10.0 // indirect
228-
golang.org/x/sys v0.28.0 // indirect
229+
golang.org/x/sys v0.30.0 // indirect
229230
golang.org/x/term v0.27.0 // indirect
230231
golang.org/x/text v0.21.0 // indirect
231232
golang.org/x/time v0.5.0 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI
345345
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
346346
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
347347
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
348+
github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
349+
github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
348350
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
349351
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
350352
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
@@ -584,6 +586,8 @@ golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
584586
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
585587
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
586588
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
589+
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
590+
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
587591
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
588592
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
589593
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=

internal/api/attestationconfigapi/fetcher_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package attestationconfigapi
77

88
import (
99
"bytes"
10-
"context"
1110
"encoding/json"
1211
"errors"
1312
"fmt"
@@ -18,7 +17,6 @@ import (
1817

1918
"github.com/flashbots/cvm-reverse-proxy/internal/attestation/variant"
2019
"github.com/flashbots/cvm-reverse-proxy/internal/constants"
21-
2220
"github.com/stretchr/testify/assert"
2321
)
2422

@@ -104,7 +102,7 @@ func TestFetchLatestSEVSNPVersion(t *testing.T) {
104102
},
105103
}
106104
fetcher := newFetcherWithClientAndVerifier(client, stubVerifier{}, constants.CDNRepositoryURL)
107-
res, err := fetcher.FetchLatestVersion(context.Background(), tc.attestation)
105+
res, err := fetcher.FetchLatestVersion(t.Context(), tc.attestation)
108106
assert := assert.New(t)
109107
if tc.wantErr {
110108
assert.Error(err)

internal/api/attestationconfigapi/version.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ func (i *List) SortReverse() {
111111
}
112112

113113
// AddVersion adds new to i's list and sorts the element in descending order.
114-
func (i *List) AddVersion(new string) {
115-
i.List = append(i.List, new)
114+
func (i *List) AddVersion(ver string) {
115+
i.List = append(i.List, ver)
116116
i.List = variant.RemoveDuplicate(i.List)
117117

118118
i.SortReverse()

internal/api/versionsapi/cli/add.go

Lines changed: 25 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ import (
1515
apiclient "github.com/flashbots/cvm-reverse-proxy/internal/api/client"
1616
"github.com/flashbots/cvm-reverse-proxy/internal/api/versionsapi"
1717
"github.com/flashbots/cvm-reverse-proxy/internal/logger"
18-
1918
"github.com/spf13/cobra"
20-
"golang.org/x/mod/semver"
2119
)
2220

2321
func newAddCmd() *cobra.Command {
@@ -54,19 +52,8 @@ func runAdd(cmd *cobra.Command, _ []string) (retErr error) {
5452
return err
5553
}
5654
log := logger.NewTextLogger(flags.logLevel)
57-
log.Debug("Using flags", "dryRun", flags.dryRun, "kind", flags.kind, "latest", flags.latest, "ref", flags.ref,
58-
"release", flags.release, "stream", flags.stream, "version", flags.version)
59-
60-
log.Debug("Validating flags")
61-
if err := flags.validate(log); err != nil {
62-
return err
63-
}
64-
65-
log.Debug("Creating version struct")
66-
ver, err := versionsapi.NewVersion(flags.ref, flags.stream, flags.version, flags.kind)
67-
if err != nil {
68-
return fmt.Errorf("creating version: %w", err)
69-
}
55+
log.Debug("Using flags", "dryRun", flags.dryRun, "kind", flags.version.Kind(), "latest", flags.latest, "ref", flags.version.Ref(),
56+
"stream", flags.version.Stream(), "version", flags.version.Version())
7057

7158
log.Debug("Creating versions API client")
7259
client, clientClose, err := versionsapi.NewClient(cmd.Context(), flags.region, flags.bucket, flags.distributionID, flags.dryRun, log)
@@ -81,35 +68,35 @@ func runAdd(cmd *cobra.Command, _ []string) (retErr error) {
8168
}()
8269

8370
log.Info("Adding version")
84-
if err := ensureVersion(cmd.Context(), client, flags.kind, ver, versionsapi.GranularityMajor, log); err != nil {
71+
if err := ensureVersion(cmd.Context(), client, flags.version, versionsapi.GranularityMajor, log); err != nil {
8572
return err
8673
}
8774

88-
if err := ensureVersion(cmd.Context(), client, flags.kind, ver, versionsapi.GranularityMinor, log); err != nil {
75+
if err := ensureVersion(cmd.Context(), client, flags.version, versionsapi.GranularityMinor, log); err != nil {
8976
return err
9077
}
9178

9279
if flags.latest {
93-
if err := updateLatest(cmd.Context(), client, flags.kind, ver, log); err != nil {
80+
if err := updateLatest(cmd.Context(), client, flags.version, log); err != nil {
9481
return fmt.Errorf("setting latest version: %w", err)
9582
}
9683
}
9784

98-
log.Info(fmt.Sprintf("List major->minor URL: %s", ver.ListURL(versionsapi.GranularityMajor)))
99-
log.Info(fmt.Sprintf("List minor->patch URL: %s", ver.ListURL(versionsapi.GranularityMinor)))
85+
log.Info(fmt.Sprintf("List major->minor URL: %s", flags.version.ListURL(versionsapi.GranularityMajor)))
86+
log.Info(fmt.Sprintf("List minor->patch URL: %s", flags.version.ListURL(versionsapi.GranularityMinor)))
10087

10188
return nil
10289
}
10390

104-
func ensureVersion(ctx context.Context, client *versionsapi.Client, kind versionsapi.VersionKind, ver versionsapi.Version, gran versionsapi.Granularity,
91+
func ensureVersion(ctx context.Context, client *versionsapi.Client, ver versionsapi.Version, gran versionsapi.Granularity,
10592
log *slog.Logger,
10693
) error {
10794
verListReq := versionsapi.List{
10895
Ref: ver.Ref(),
10996
Stream: ver.Stream(),
11097
Granularity: gran,
11198
Base: ver.WithGranularity(gran),
112-
Kind: kind,
99+
Kind: ver.Kind(),
113100
}
114101
verList, err := client.FetchVersionList(ctx, verListReq)
115102
var notFoundErr *apiclient.NotFoundError
@@ -141,11 +128,11 @@ func ensureVersion(ctx context.Context, client *versionsapi.Client, kind version
141128
return nil
142129
}
143130

144-
func updateLatest(ctx context.Context, client *versionsapi.Client, kind versionsapi.VersionKind, ver versionsapi.Version, log *slog.Logger) error {
131+
func updateLatest(ctx context.Context, client *versionsapi.Client, ver versionsapi.Version, log *slog.Logger) error {
145132
latest := versionsapi.Latest{
146133
Ref: ver.Ref(),
147134
Stream: ver.Stream(),
148-
Kind: kind,
135+
Kind: ver.Kind(),
149136
}
150137
latest, err := client.FetchVersionLatest(ctx, latest)
151138
var notFoundErr *apiclient.NotFoundError
@@ -165,7 +152,7 @@ func updateLatest(ctx context.Context, client *versionsapi.Client, kind versions
165152
Ref: ver.Ref(),
166153
Stream: ver.Stream(),
167154
Version: ver.Version(),
168-
Kind: kind,
155+
Kind: ver.Kind(),
169156
}
170157
if err := client.UpdateVersionLatest(ctx, latest); err != nil {
171158
return fmt.Errorf("updating latest version: %w", err)
@@ -175,60 +162,20 @@ func updateLatest(ctx context.Context, client *versionsapi.Client, kind versions
175162
}
176163

177164
type addFlags struct {
178-
version string
179-
stream string
180-
ref string
181-
release bool
165+
version versionsapi.Version
182166
latest bool
183167
dryRun bool
184168
region string
185169
bucket string
186170
distributionID string
187-
kind versionsapi.VersionKind
188171
logLevel slog.Level
189172
}
190173

191-
func (f *addFlags) validate(log *slog.Logger) error {
192-
if !semver.IsValid(f.version) {
193-
return fmt.Errorf("version %q is not a valid semantic version", f.version)
194-
}
195-
if semver.Canonical(f.version) != f.version {
196-
return fmt.Errorf("version %q is not a canonical semantic version", f.version)
197-
}
198-
199-
if f.ref == "" && !f.release {
200-
return fmt.Errorf("either --ref or --release must be set")
201-
}
202-
203-
if f.kind == versionsapi.VersionKindUnknown {
204-
return fmt.Errorf("unknown version kind %q", f.kind)
205-
}
206-
207-
if f.release {
208-
log.Debug(fmt.Sprintf("Setting ref to %q, as release flag is set", versionsapi.ReleaseRef))
209-
f.ref = versionsapi.ReleaseRef
210-
} else {
211-
log.Debug("Setting latest to true, as release flag is not set")
212-
f.latest = true // always set latest for non-release versions
213-
}
214-
215-
if err := versionsapi.ValidateRef(f.ref); err != nil {
216-
return fmt.Errorf("invalid ref %w", err)
217-
}
218-
219-
if err := versionsapi.ValidateStream(f.ref, f.stream); err != nil {
220-
return fmt.Errorf("invalid stream %w", err)
221-
}
222-
223-
return nil
224-
}
225-
226174
func parseAddFlags(cmd *cobra.Command) (addFlags, error) {
227175
ref, err := cmd.Flags().GetString("ref")
228176
if err != nil {
229177
return addFlags{}, err
230178
}
231-
ref = versionsapi.CanonicalizeRef(ref)
232179
stream, err := cmd.Flags().GetString("stream")
233180
if err != nil {
234181
return addFlags{}, err
@@ -275,17 +222,24 @@ func parseAddFlags(cmd *cobra.Command) (addFlags, error) {
275222
return addFlags{}, err
276223
}
277224

225+
if release {
226+
ref = versionsapi.ReleaseRef
227+
} else {
228+
latest = true // always set latest for non-release versions
229+
}
230+
231+
ver, err := versionsapi.NewVersion(ref, stream, version, kind)
232+
if err != nil {
233+
return addFlags{}, fmt.Errorf("creating version: %w", err)
234+
}
235+
278236
return addFlags{
279-
version: version,
280-
stream: stream,
281-
ref: versionsapi.CanonicalizeRef(ref),
282-
release: release,
237+
version: ver,
283238
latest: latest,
284239
dryRun: dryRun,
285240
region: region,
286241
bucket: bucket,
287242
distributionID: distributionID,
288243
logLevel: logLevel,
289-
kind: kind,
290244
}, nil
291245
}

internal/api/versionsapi/fetcher_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ package versionsapi
88

99
import (
1010
"bytes"
11-
"context"
1211
"encoding/json"
1312
"io"
1413
"net/http"
1514
"testing"
1615

1716
"github.com/flashbots/cvm-reverse-proxy/internal/constants"
18-
1917
"github.com/stretchr/testify/assert"
2018
"github.com/stretchr/testify/require"
2119
"go.uber.org/goleak"
@@ -193,7 +191,7 @@ func TestFetchVersionList(t *testing.T) {
193191

194192
fetcher := Fetcher{client, constants.CDNRepositoryURL}
195193

196-
list, err := fetcher.FetchVersionList(context.Background(), tc.list)
194+
list, err := fetcher.FetchVersionList(t.Context(), tc.list)
197195

198196
if tc.wantErr {
199197
assert.Error(err)

internal/api/versionsapi/version.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type Version struct {
4141
// NewVersion creates a new Version object and validates it.
4242
func NewVersion(ref, stream, version string, kind VersionKind) (Version, error) {
4343
ver := Version{
44-
ref: ref,
44+
ref: CanonicalizeRef(ref),
4545
stream: stream,
4646
version: version,
4747
kind: kind,
@@ -62,7 +62,7 @@ func NewVersionFromShortPath(shortPath string, kind VersionKind) (Version, error
6262
}
6363

6464
ver := Version{
65-
ref: ref,
65+
ref: ref, // Canonicalized by parseShortPath.
6666
stream: stream,
6767
version: version,
6868
kind: kind,
@@ -331,7 +331,7 @@ func CanonicalizeRef(ref string) string {
331331
canRef := notAZ09Regexp.ReplaceAllString(ref, "-")
332332

333333
if canRef == ReleaseRef {
334-
return "" // No ref should be cannonicalized to the release ref.
334+
return "" // No ref should be canonicalized to the release ref.
335335
}
336336

337337
return canRef
@@ -401,7 +401,7 @@ func MeasurementURL(version Version) (measurementURL, signatureURL *url.URL, err
401401
}
402402

403403
var (
404-
shortPathRegex = regexp.MustCompile(`^ref/([a-zA-Z0-9-]+)/stream/([a-zA-Z0-9-]+)/([a-zA-Z0-9.-]+)$`)
404+
shortPathRegex = regexp.MustCompile(`^ref/([^/]+)/stream/([a-zA-Z0-9-]+)/([a-zA-Z0-9.-]+)$`)
405405
shortPathReleaseRegex = regexp.MustCompile(`^stream/([a-zA-Z0-9-]+)/([a-zA-Z0-9.-]+)$`)
406406
)
407407

@@ -422,6 +422,7 @@ func parseShortPath(shortPath string) (ref, stream, version string, err error) {
422422
if shortPathRegex.MatchString(shortPath) {
423423
matches := shortPathRegex.FindStringSubmatch(shortPath)
424424
ref := matches[1]
425+
ref = CanonicalizeRef(ref)
425426
if err := ValidateRef(ref); err != nil {
426427
return "", "", "", err
427428
}

0 commit comments

Comments
 (0)