diff --git a/.golangci.yml b/.golangci.yml index 96fd92c8..b25c08c1 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -101,10 +101,6 @@ linters: linters: - forbidigo text: stdout is a command's output - - path: internal/tfstate/apiproxy/ - linters: - - forbidigo - text: one HTTP client # The fake clock is a test's; production code waits on the real one. - path-except: _test\.go linters: @@ -243,7 +239,15 @@ linters: - $all deny: - pkg: encoding/json$ - desc: Use encoding/json/v2 and internal/json instead + desc: Use internal/json instead + + json-v2: + files: + - $all + - "!**/internal/json/*.go" + deny: + - pkg: encoding/json/v2 + desc: Use internal/json instead # cobra is used in cmd/ and nowhere else. cmd: @@ -267,8 +271,8 @@ linters: - log/slog # a listing yields raw items, and reads a field out of one - encoding/json/jsontext - - encoding/json/v2 - # no direct access to internal/ + - github.com/meshcloud/meshstack-cli/internal/json + # no direct access to internal/, apart from the JSON codec above - github.com/meshcloud/meshstack-cli/pkg # a parent command calls its children's New, the same way cmd/meshstack calls its own - github.com/meshcloud/meshstack-cli/cmd @@ -305,7 +309,7 @@ linters: - log/slog # a request body is checked as JSON, and api-docs writes a part of the OpenAPI document - encoding/json/jsontext - - encoding/json/v2 + - github.com/meshcloud/meshstack-cli/internal/json - github.com/meshcloud/meshstack-cli/cmd/internal - github.com/meshcloud/meshstack-cli/client # the API docs choose the version of a request @@ -407,7 +411,7 @@ linters: - log/slog # a listing writes raw items, and a command that shows one object marshals it - encoding/json/jsontext - - encoding/json/v2 + - github.com/meshcloud/meshstack-cli/internal/json - github.com/meshcloud/meshstack-cli/cmd/internal/markdown - github.com/meshcloud/meshstack-cli/cmd/internal/color - github.com/meshcloud/meshstack-cli/pkg @@ -441,7 +445,6 @@ linters: desc: Use log/slog instead allow: - $gostd - - encoding/json/v2 - encoding/json/jsontext - log/slog - github.com/meshcloud/meshstack-cli/client @@ -492,13 +495,13 @@ linters: - "!**/cmd/**/*.go" # ...except cmd, whose internal packages the cmd rules cover - "!$test" - "!**/internal/testutil/**/*.go" + - "!**/internal/json/*.go" # client-http covers it list-mode: strict deny: - pkg: log desc: Use log/slog instead allow: - $gostd - - encoding/json/v2 - encoding/json/jsontext - log/slog - github.com/meshcloud/meshstack-cli/internal @@ -513,7 +516,6 @@ linters: list-mode: strict allow: - $gostd - - encoding/json/v2 - encoding/json/jsontext - github.com/meshcloud/meshstack-cli - github.com/stretchr/testify @@ -538,6 +540,7 @@ linters: list-mode: strict allow: - $gostd + - github.com/meshcloud/meshstack-cli/internal/json - github.com/meshcloud/meshstack-cli/internal/testutil/fakemeshstack # A test may use every direct dependency in go.mod: the rules above already confine where @@ -545,10 +548,10 @@ linters: tests: files: - "$test" + - "!**/client/http/*_test.go" list-mode: strict allow: - $gostd - - encoding/json/v2 - encoding/json/jsontext - github.com/meshcloud/meshstack-cli - charm.land/bubbles/v2 @@ -563,3 +566,17 @@ linters: - github.com/spf13/cobra - github.com/spf13/pflag - github.com/stretchr/testify + + # client/http breaks connections on purpose, which toxiproxy does in process. + tests-client-http: + files: + - "**/client/http/*_test.go" + list-mode: strict + allow: + - $gostd + - encoding/json/jsontext + - github.com/meshcloud/meshstack-cli + - github.com/stretchr/testify + - github.com/Shopify/toxiproxy/v2 + # toxiproxy.NewServer takes a zerolog.Logger, and zerolog.Nop() is the only use + - github.com/rs/zerolog diff --git a/client/building_block_definition_version.go b/client/building_block_definition_version.go index dfac2ab2..e684a09c 100644 --- a/client/building_block_definition_version.go +++ b/client/building_block_definition_version.go @@ -3,7 +3,6 @@ package client import ( "context" "encoding/json/jsontext" - "encoding/json/v2" "errors" "fmt" "uuid" @@ -12,6 +11,7 @@ import ( "github.com/meshcloud/meshstack-cli/client/internal" "github.com/meshcloud/meshstack-cli/client/types" "github.com/meshcloud/meshstack-cli/client/types/enum" + "github.com/meshcloud/meshstack-cli/internal/json" ) type MeshBuildingBlockDefinitionVersionState string diff --git a/client/building_block_definition_version_implementation.go b/client/building_block_definition_version_implementation.go index edc65eee..2700d179 100644 --- a/client/building_block_definition_version_implementation.go +++ b/client/building_block_definition_version_implementation.go @@ -2,12 +2,12 @@ package client import ( "encoding/json/jsontext" - "encoding/json/v2" "fmt" "github.com/meshcloud/meshstack-cli/client/types" "github.com/meshcloud/meshstack-cli/client/types/enum" "github.com/meshcloud/meshstack-cli/client/types/variant" + "github.com/meshcloud/meshstack-cli/internal/json" ) type MeshBuildingBlockImplementationType string diff --git a/client/building_block_definition_version_test.go b/client/building_block_definition_version_test.go index ea0c46b9..8d70aa4b 100644 --- a/client/building_block_definition_version_test.go +++ b/client/building_block_definition_version_test.go @@ -2,7 +2,6 @@ package client import ( "embed" - "encoding/json/v2" "path" "testing" @@ -10,6 +9,7 @@ import ( "github.com/stretchr/testify/require" "github.com/meshcloud/meshstack-cli/client/types" + "github.com/meshcloud/meshstack-cli/internal/json" ) //go:embed testdata/building_block_definition_version_input diff --git a/client/building_block_run_action.go b/client/building_block_run_action.go index 5be77174..4f11899d 100644 --- a/client/building_block_run_action.go +++ b/client/building_block_run_action.go @@ -3,7 +3,6 @@ package client import ( "context" "fmt" - gohttp "net/http" "net/url" "github.com/meshcloud/meshstack-cli/client/http" @@ -49,7 +48,7 @@ func (c *MeshBuildingBlockRunActionClient) ReadLogs(ctx context.Context, link Li // ApproveRun takes the predecessor because meshStack replaces the plan of a run that waits for // approval when the run is planned again. The predecessor names the plan that is approved. func (c *MeshBuildingBlockRunActionClient) ApproveRun(ctx context.Context, approve Link, predecessorRunUuid string) error { - _, err := c.doAtLink[[]byte](ctx, http.MethodPost, approve, http.WithJsonPayload(struct { + _, err := c.doAtLink[struct{}](ctx, http.MethodPost, approve, http.WithJsonRequest(struct { PredecessorRunUuid string `json:"predecessorRunUuid"` }{predecessorRunUuid}, c.run.MeshObjectMimeType())) return err @@ -64,8 +63,7 @@ func (c *MeshBuildingBlockRunActionClient) AbortRun(ctx context.Context, abort L } func (c *MeshBuildingBlockRunActionClient) postWithoutBody(ctx context.Context, link Link) error { - _, err := c.doAtLink[[]byte](ctx, http.MethodPost, link, - http.WithHeaders(gohttp.Header{"Content-Type": {c.run.MeshObjectMimeType()}})) + _, err := c.doAtLink[struct{}](ctx, http.MethodPost, link, http.WithContentType(c.run.MeshObjectMimeType())) return err } @@ -84,5 +82,5 @@ func (c *MeshBuildingBlockRunActionClient) doAtLink[R any](ctx context.Context, } below := c.httpClient.EndpointUrl.JoinPath(path) below.RawQuery = target.RawQuery - return c.httpClient.DoRequest[R](ctx, method, below, append(options, http.WithAccept(c.run.MeshObjectMimeType()))...) + return http.UnmarshalJsonBody[R](c.httpClient.DoRequest(ctx, method, below, append(options, http.WithHeader("Accept", c.run.MeshObjectMimeType()))...)) } diff --git a/client/building_block_v2.go b/client/building_block_v2.go index 1aa6a11e..77283335 100644 --- a/client/building_block_v2.go +++ b/client/building_block_v2.go @@ -3,7 +3,6 @@ package client import ( "context" "encoding/json/jsontext" - "encoding/json/v2" "errors" "fmt" "slices" @@ -12,6 +11,7 @@ import ( "github.com/meshcloud/meshstack-cli/client/internal" "github.com/meshcloud/meshstack-cli/client/types" "github.com/meshcloud/meshstack-cli/client/types/enum" + "github.com/meshcloud/meshstack-cli/internal/json" ) type BuildingBlockLifecycleState string diff --git a/client/http/auth.go b/client/http/auth.go index d0a6cea8..1d13d28b 100644 --- a/client/http/auth.go +++ b/client/http/auth.go @@ -4,9 +4,11 @@ import ( "context" "errors" "fmt" + "io" "log/slog" gohttp "net/http" "net/url" + "strings" ) // Authorization produces the bearer token for each request. An implementation renews the token @@ -19,62 +21,65 @@ type Authorization interface { // rejected token unchanged tells the caller that there is nothing new to try. RefreshBearerToken(ctx context.Context, rejected BearerToken) (BearerToken, error) - // Scope names what meshStack grants access by, so that a 403 says it. Empty names nothing. - Scope() string -} - -func (c Client) WithAuthorization(auth Authorization) AuthorizedClient { - return AuthorizedClient{c, auth} + fmt.Stringer } type AuthorizedClient struct { - Client - - Authorization Authorization + client Client + auth Authorization } -func (c AuthorizedClient) DoRequest[R any](ctx context.Context, method string, url *url.URL, options ...RequestOption) (R, error) { - result, err := withBearerToken(ctx, c.Authorization, method, url, func(token RequestOption) (R, error) { - return c.Client.DoRequest[R](ctx, method, url, append(options, token)...) - }) - if httpErr, ok := errors.AsType[Error](err); ok && httpErr.IsForbidden() && c.Authorization.Scope() != "" { - err = fmt.Errorf("auth scope %s: %w", c.Authorization.Scope(), err) - } - return result, err +func (c Client) WithAuthorization(auth Authorization) AuthorizedClient { + return AuthorizedClient{c, auth} } -// Authorize is for a request that this client does not send itself, such as one a reverse proxy -// passes on. Such a request gets no second try after a 401. -func (c AuthorizedClient) Authorize(r *gohttp.Request) error { - token, err := c.Authorization.GetBearerToken(r.Context()) +func (c AuthorizedClient) DoRequest(ctx context.Context, method string, url *url.URL, options ...RequestOption) (io.ReadCloser, error) { + token, err := c.auth.GetBearerToken(ctx) if err != nil { - return err - } - r.Header.Set("Authorization", "Bearer "+string(token)) - return nil -} - -func withBearerToken[R any](ctx context.Context, auth Authorization, method string, url *url.URL, send func(token RequestOption) (R, error)) (result R, err error) { - token, tokenErr := auth.GetBearerToken(ctx) - if tokenErr != nil { - return result, tokenErr + return nil, err } - result, err = send(token.asRequestOption()) - + body, err := c.client.DoRequest(ctx, method, url, append(options, token.asRequestOption())...) if httpErr, ok := errors.AsType[Error](err); ok && httpErr.IsUnauthorized() { // Clock skew between this machine and the server can make a token look valid here and // expired there, so one 401 earns one retry with a freshly minted token. - refreshedToken, refreshErr := auth.RefreshBearerToken(ctx, token) + refreshedToken, refreshErr := c.auth.RefreshBearerToken(ctx, token) switch { case refreshErr != nil: - return result, errors.Join(err, fmt.Errorf("cannot renew the rejected token: %w", refreshErr)) - case refreshedToken == token: - return result, err + err = errors.Join(err, fmt.Errorf("cannot renew the rejected token: %w", refreshErr)) + case refreshedToken != token: + slog.DebugContext(ctx, "retrying after 401 with a freshly minted token", "url", url.String(), "method", method) + body, err = c.client.DoRequest(ctx, method, url, append(options, refreshedToken.asRequestOption())...) } - slog.DebugContext(ctx, "retrying after 401 with a freshly minted token", "url", url.String(), "method", method) - return send(refreshedToken.asRequestOption()) } - return result, err + if httpErr, ok := errors.AsType[Error](err); ok && httpErr.IsForbidden() { + err = fmt.Errorf("auth %s: %w", c.auth, err) + } + return body, err +} + +func (c AuthorizedClient) String() string { + return "authorized client " + c.client.userAgent.String() +} + +func (c AuthorizedClient) ProxyTransport() gohttp.RoundTripper { + return proxyTransport{c} +} + +type proxyTransport struct { + AuthorizedClient +} + +func (t proxyTransport) RoundTrip(in *gohttp.Request) (*gohttp.Response, error) { + out := in.Clone(in.Context()) + out.Header.Set("User-Agent", strings.TrimSpace(in.Header.Get("User-Agent")+" "+t.client.userAgent.String())) + if in.Header.Get("Authorization") != "" { + token, err := t.auth.GetBearerToken(in.Context()) + if err != nil { + return nil, err + } + out.Header.Set("Authorization", "Bearer "+string(token)) + } + return goClient.Transport.RoundTrip(out) } // BearerToken is both the token Authorization produces and an Authorization of its own, for a @@ -89,10 +94,14 @@ func (token BearerToken) RefreshBearerToken(_ context.Context, _ BearerToken) (B return "", fmt.Errorf("cannot renew %T", token) } -func (token BearerToken) Scope() string { - return "" +// String shows only the start of a long token, so that formatting one never leaks it. +func (token BearerToken) String() string { + if len(token) < 32 { + return "BearerToken [REDACTED]" + } + return "BearerToken " + string(token[:6]) + "...[REDACTED]" } func (token BearerToken) asRequestOption() RequestOption { - return withHeader("Authorization", fmt.Sprintf("Bearer %s", token)) + return WithHeader("Authorization", "Bearer "+string(token)) } diff --git a/client/http/download.go b/client/http/download.go deleted file mode 100644 index b403a0ae..00000000 --- a/client/http/download.go +++ /dev/null @@ -1,171 +0,0 @@ -package http - -import ( - "context" - "errors" - "fmt" - "io" - "io/fs" - "log/slog" - gohttp "net/http" - "net/url" - "os" - "path/filepath" - "strings" - "time" - - "github.com/meshcloud/meshstack-cli/internal/json" -) - -const ( - // A command starts without an open connection, and DNS, TCP, TLS and a 304 from CloudFront took - // 55 to 100ms, so a shorter wait would give up on a fast network as well. - waitForNewerDownload = 200 * time.Millisecond - downloadTimeout = 2 * time.Minute - downloadCheckInterval = 24 * time.Hour -) - -type ( - DownloadOption func(opts *downloadOptions) - - downloadOptions struct { - conditionalGet bool - } -) - -// WithConditionalGet asks for a newer document on every download. Without it, Download asks -// once per downloadCheckInterval, to save the round trip. -func WithConditionalGet(conditionalGet bool) DownloadOption { - return func(opts *downloadOptions) { - opts.conditionalGet = conditionalGet - } -} - -// Download waits at most waitForNewerDownload for a newer document where path holds one already. -// After that, the caller reads the stored document, and wait lets the download finish for the next -// command. -func (c Client) Download(ctx context.Context, url *url.URL, path string, options ...DownloadOption) (wait func(), err error) { - var opts downloadOptions - for _, option := range options { - option(&opts) - } - noWait := func() {} - stored, statErr := os.Stat(path) - if statErr != nil { - downloadCtx, cancel := context.WithTimeout(ctx, downloadTimeout) - defer cancel() - if err := c.download(downloadCtx, url, path, nil); err != nil { - return noWait, err - } - return noWait, opts.recordCheck(ctx, path) - } - if due, err := opts.checkDue(ctx, path); err != nil || !due { - return noWait, err - } - - done := make(chan error, 1) - go func() { - // Derived from ctx, so that Ctrl-C ends the wait: until the command returns, main's - // signal.NotifyContext swallows every further Ctrl-C. - downloadCtx, cancel := context.WithTimeout(ctx, downloadTimeout) - defer cancel() - err := c.download(downloadCtx, url, path, []RequestOption{ - withHeader("If-Modified-Since", stored.ModTime().UTC().Format(gohttp.TimeFormat)), - }) - // A cancelled download leaves the check due, so that the next command tries again. - if ctx.Err() != nil { - done <- nil - return - } - done <- errors.Join(err, opts.recordCheck(ctx, path)) - }() - warnIfFailed := func(err error) { - if err != nil { - slog.WarnContext(ctx, fmt.Sprintf("Cannot update %s, which is from %s: %s", path, stored.ModTime().Format(time.DateTime), err)) - } - } - select { - case err := <-done: - warnIfFailed(err) - return noWait, nil - case <-time.After(waitForNewerDownload): - slog.WarnContext(ctx, fmt.Sprintf("Cannot update %s within %s, so this command reads the one from %s. "+ - "The command ends once the download has finished.", path, waitForNewerDownload, stored.ModTime().Format(time.DateTime))) - return func() { warnIfFailed(<-done) }, nil - } -} - -type downloadCheck struct { - LastCheck time.Time `json:"lastCheck"` -} - -func lastCheckJson(path string) string { - return strings.TrimSuffix(path, filepath.Ext(path)) + ".lastcheck.json" -} - -func (opts downloadOptions) checkDue(ctx context.Context, path string) (bool, error) { - if opts.conditionalGet { - return true, nil - } - var check downloadCheck - if err := json.UnmarshalFrom(ctx, lastCheckJson(path), &check); errors.Is(err, fs.ErrNotExist) { - return true, nil - } else if err != nil { - return false, err - } - if untilNext := downloadCheckInterval - time.Since(check.LastCheck); untilNext > 0 { - slog.DebugContext(ctx, fmt.Sprintf("Not checking %s for a newer one, the next check is due in %s", path, untilNext.Round(time.Minute))) - return false, nil - } - return true, nil -} - -func (opts downloadOptions) recordCheck(ctx context.Context, path string) error { - if opts.conditionalGet { - return nil - } - return json.MarshalTo(ctx, lastCheckJson(path), downloadCheck{time.Now()}) -} - -func (c Client) download(ctx context.Context, url *url.URL, path string, options []RequestOption) (err error) { - // No option sets an Accept-Encoding, so that net/http asks for gzip and decompresses the answer: - // the API docs then come as 0.5MB rather than 4.7MB. CloudFront serves brotli as well, but it - // saves only 4 to 8% over gzip, too little for a dependency. - res, err := c.send(ctx, gohttp.MethodGet, url, options) - if err != nil { - return err - } - defer func() { - _ = res.Body.Close() - }() - if res.StatusCode == gohttp.StatusNotModified { - slog.DebugContext(ctx, path+" is up to date") - return nil - } - if !isSuccess(res.StatusCode) { - _, err = c.readBodyAndCheckSuccess(ctx, res) - return err - } - - // The document is renamed into place, so that no reader sees half of it. - tmp, err := os.CreateTemp(filepath.Dir(path), filepath.Base(path)+".*.tmp") - if err != nil { - return err - } - defer func() { - if removeErr := os.Remove(tmp.Name()); !errors.Is(removeErr, os.ErrNotExist) { - err = errors.Join(err, removeErr) - } - }() - _, copyErr := io.Copy(tmp, res.Body) - if err = errors.Join(copyErr, tmp.Close()); err != nil { - return fmt.Errorf("cannot download %s: %w", url, err) - } - if lastModified, parseErr := gohttp.ParseTime(res.Header.Get("Last-Modified")); parseErr == nil { - if err = os.Chtimes(tmp.Name(), time.Time{}, lastModified); err != nil { - return err - } - } - slog.DebugContext(ctx, fmt.Sprintf("downloaded %s to %s", url, path)) - return os.Rename(tmp.Name(), path) -} diff --git a/client/http/download_test.go b/client/http/download_test.go deleted file mode 100644 index f1714b0d..00000000 --- a/client/http/download_test.go +++ /dev/null @@ -1,137 +0,0 @@ -package http_test - -import ( - "compress/gzip" - "log/slog" - gohttp "net/http" - "os" - "path/filepath" - "strings" - "testing" - "testing/synctest" - "time" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - - "github.com/meshcloud/meshstack-cli/client/http" - "github.com/meshcloud/meshstack-cli/internal/logs" -) - -type fakeDocument struct { - body string - modified time.Time - missing bool - release chan struct{} - answers []int - // contentEncodings has one entry per document sent, and none per 304 or 404. - contentEncodings []string -} - -func (d *fakeDocument) serve(resp gohttp.ResponseWriter, req *gohttp.Request) { - if d.release != nil { - <-d.release - } - since, sinceErr := gohttp.ParseTime(req.Header.Get("If-Modified-Since")) - switch { - case d.missing: - d.answers = append(d.answers, gohttp.StatusNotFound) - resp.WriteHeader(gohttp.StatusNotFound) - case sinceErr == nil && !since.Before(d.modified): - d.answers = append(d.answers, gohttp.StatusNotModified) - resp.WriteHeader(gohttp.StatusNotModified) - default: - d.answers = append(d.answers, gohttp.StatusOK) - resp.Header().Set("Last-Modified", d.modified.Format(gohttp.TimeFormat)) - if !strings.Contains(req.Header.Get("Accept-Encoding"), "gzip") { - d.contentEncodings = append(d.contentEncodings, "identity") - _, _ = resp.Write([]byte(d.body)) - return - } - d.contentEncodings = append(d.contentEncodings, "gzip") - resp.Header().Set("Content-Encoding", "gzip") - compressed := gzip.NewWriter(resp) - _, _ = compressed.Write([]byte(d.body)) - _ = compressed.Close() - } -} - -func TestDownload(t *testing.T) { - path := filepath.Join(t.TempDir(), "doc.json") - document := &fakeDocument{body: `{"version": 1}`, modified: time.Date(2026, 9, 30, 13, 49, 36, 0, time.UTC)} - download := func(t *testing.T, options ...http.DownloadOption) (wait func()) { - t.Helper() - client := newTestClientWithServer(t, document.serve) - wait, err := client.Download(t.Context(), client.ServerUrl, path, options...) - require.NoError(t, err) - return wait - } - - t.Run("stores the document, and checks once a day for a newer one, even after a failed check", func(t *testing.T) { - synctest.Test(t, func(t *testing.T) { - captured := logs.Capture(t) - - download(t)() - assert.Equal(t, []string{"gzip"}, document.contentEncodings, "the 4.7MB of the API docs come as 0.5MB") - assert.JSONEq(t, `{"version": 1}`, readDocument(t, path), "the stored document is decompressed") - stat, err := os.Stat(path) - require.NoError(t, err) - assert.True(t, document.modified.Equal(stat.ModTime()), "the mtime is the Last-Modified") - - synctest.Sleep(23 * time.Hour) - download(t)() - assert.Equal(t, []int{gohttp.StatusOK}, document.answers, "a check within a day is not due") - - synctest.Sleep(time.Hour) - download(t)() - assert.Equal(t, []int{gohttp.StatusOK, gohttp.StatusNotModified}, document.answers) - assert.Empty(t, captured.Records(slog.LevelWarn)) - - synctest.Sleep(24 * time.Hour) - document.missing = true - download(t)() - download(t)() - assert.Equal(t, []int{gohttp.StatusOK, gohttp.StatusNotModified, gohttp.StatusNotFound}, document.answers) - require.Len(t, captured.Records(slog.LevelWarn), 1) - assert.Contains(t, captured.Lines(slog.LevelWarn)[0], "Cannot update "+path) - assert.JSONEq(t, `{"version": 1}`, readDocument(t, path)) - }) - }) - - t.Run("goes on with the stored document while a slow download finishes", func(t *testing.T) { - synctest.Test(t, func(t *testing.T) { - captured := logs.Capture(t) - document.missing = false - document.body, document.modified = `{"version": 2}`, document.modified.Add(time.Hour) - document.release = make(chan struct{}) - - wait := download(t, http.WithConditionalGet(true)) - assert.JSONEq(t, `{"version": 1}`, readDocument(t, path), "the caller reads the stored document") - require.Len(t, captured.Records(slog.LevelWarn), 1) - assert.Contains(t, captured.Lines(slog.LevelWarn)[0], "The command ends once the download has finished.") - - close(document.release) - wait() - assert.JSONEq(t, `{"version": 2}`, readDocument(t, path), "the next command reads the new document") - }) - }) - - t.Run("fails without a stored document to fall back to, and leaves nothing behind", func(t *testing.T) { - client := newTestClientWithServer(t, (&fakeDocument{missing: true}).serve) - dir := t.TempDir() - - _, err := client.Download(t.Context(), client.ServerUrl, filepath.Join(dir, "doc.json")) - - require.ErrorContains(t, err, "404") - entries, err := os.ReadDir(dir) - require.NoError(t, err) - assert.Empty(t, entries) - }) -} - -func readDocument(t *testing.T, path string) string { - t.Helper() - content, err := os.ReadFile(filepath.Clean(path)) - require.NoError(t, err) - return string(content) -} diff --git a/client/http/http_client.go b/client/http/http_client.go index 4a893532..a32c9fa5 100644 --- a/client/http/http_client.go +++ b/client/http/http_client.go @@ -1,141 +1,122 @@ package http import ( - "bytes" "context" + "errors" "fmt" "io" "log/slog" gohttp "net/http" "net/url" - "reflect" "slices" - "time" "github.com/meshcloud/meshstack-cli/internal/json" ) -var sharedClient = func() (client *gohttp.Client) { - client = &gohttp.Client{Transport: newTransport(1 * time.Minute)} - RetryOptions{ - // Sized to ride out a full meshStack backend restart, which can leave the gateway - // returning 503 for two to three minutes. This backoff sequence sums to about four - // minutes: 1+2+4+8+16+30*7 seconds. - MaxRetries: 12, - Backoff: ExponentialBackoff{MinWait: 1 * time.Second, MaxWait: 30 * time.Second}, - }.ApplyTo(client) - return -}() - -func newTransport(silenceTimeout time.Duration) gohttp.RoundTripper { - transport := gohttp.DefaultTransport.(*gohttp.Transport).Clone() //nolint:forcetypeassert // net/http declares it a *Transport - transport.ResponseHeaderTimeout = silenceTimeout - return stallGuard{Next: transport, Timeout: silenceTimeout} +type Client struct { + userAgent UserAgent } -type Client struct { - *gohttp.Client +var goClient = newGoClient() - UserAgent UserAgent +func newGoClient() *gohttp.Client { + transport := gohttp.DefaultTransport.(*gohttp.Transport).Clone() //nolint:forcetypeassert // net/http declares it a *Transport + transport.ResponseHeaderTimeout = stallTimeout + return &gohttp.Client{ + Transport: retryRoundTripper{transport}, + CheckRedirect: func(req *gohttp.Request, _ []*gohttp.Request) error { + if requestOptionsFrom(req).noRedirects { + return gohttp.ErrUseLastResponse + } + return nil + }, + } } -// NewClient panics on a UserAgent that does not validate, as a request has to name its front end. func NewClient(userAgent UserAgent) Client { - if err := userAgent.Validate(); err != nil { + if err := userAgent.validate(); err != nil { panic(err) } - return Client{sharedClient, userAgent} + return Client{userAgent} } -// DoRequest sends one request and parses the answer as JSON, or returns it as it came, empty -// included, for an R of []byte. A non-2xx status is an Error that carries the response body, -// because an OIDC endpoint answers a refusal with an error document and that document is the only -// thing saying which refusal it was. -func (c Client) DoRequest[R any](ctx context.Context, method string, url *url.URL, options ...RequestOption) (result R, err error) { - var body []byte - body, err = c.doRequest(ctx, method, url, options) - if err != nil { - return - } - if raw, ok := any(&result).(*[]byte); ok { - *raw = body - return +func (c Client) String() string { + return "unauthorized client " + c.userAgent.String() +} + +// UnmarshalJsonBody closes the body. +func UnmarshalJsonBody[T any](body io.ReadCloser, err error, unmarshalers ...*json.Unmarshalers) (result T, _ error) { + if _, ignored := any(result).(struct{}); ignored { + return result, IgnoreResponse(body, err) } - if len(body) == 0 { - // Only a call typed DoRequest[any], such as a delete, expects no content. Any other call - // fails here, because its caller would dereference a nil result or read it as "not found". - if t := reflect.TypeFor[R](); t.Kind() == reflect.Interface && t.NumMethod() == 0 { - return - } - err = fmt.Errorf("unexpected empty response body from %s %s", method, url) - return + if err != nil { + return result, err } - if err = json.Unmarshal(body, &result); err != nil { + err = json.UnmarshalRead(body, &result, json.WithUnmarshalers(unmarshalers...)) + if err != nil { err = fmt.Errorf("parsing response body as JSON failed: %w", err) } - return + return result, errors.Join(err, body.Close()) } -func (c Client) doRequest(ctx context.Context, method string, url *url.URL, options []RequestOption) ([]byte, error) { - res, err := c.send(ctx, method, url, options) +func ReadAllBody(body io.ReadCloser, err error) ([]byte, error) { if err != nil { return nil, err } - defer func() { - _ = res.Body.Close() - }() - return c.readBodyAndCheckSuccess(ctx, res) + data, err := io.ReadAll(body) + return data, errors.Join(err, body.Close()) } -func (c Client) send(ctx context.Context, method string, url *url.URL, options []RequestOption) (*gohttp.Response, error) { - options = slices.Insert(options, 0, withHeader("User-Agent", c.UserAgent.String())) - opts := requestOptions{} - for _, option := range options { - option(&opts) - } - req, err := c.buildRequest(ctx, method, url, opts) +func IgnoreResponse(body io.ReadCloser, err error) error { if err != nil { - return nil, err + return err } - return c.Do(req) -} - -func isSuccess(statusCode int) bool { - return statusCode >= 200 && statusCode <= 299 + if _, err = io.CopyN(io.Discard, body, maxDrainBytes); errors.Is(err, io.EOF) { + err = nil + } + return errors.Join(err, body.Close()) } -func (c Client) readBodyAndCheckSuccess(ctx context.Context, res *gohttp.Response) ([]byte, error) { - responseBody, err := io.ReadAll(res.Body) +// DoRequest leaves the body to the caller. A non-2xx status is an Error that carries the response body, +// because an OIDC endpoint answers a refusal with an error document and that document is the only +// thing saying which refusal it was. +func (c Client) DoRequest(ctx context.Context, method string, url *url.URL, options ...RequestOption) (io.ReadCloser, error) { + opts := newRequestOptions(slices.Insert(options, 0, WithHeader("User-Agent", c.userAgent.String()))) + ctx, cancel := context.WithCancelCause(ctx) + req, err := opts.newRequest(ctx, method, url) if err != nil { - return nil, fmt.Errorf("cannot read response body, status code %d: %w", res.StatusCode, err) + cancel(nil) + return nil, err } - slog.DebugContext(ctx, "response", "status", res.StatusCode, "body", loggedBody{bytes.NewBuffer(responseBody)}) - + res, err := goClient.Do(req) //nolint:bodyclose // the returned body closes it, or the error path below + if err != nil { + cancel(nil) + return nil, err + } + slog.DebugContext(ctx, "response", "status", res.StatusCode, "headers", loggedHeaders(res.Header)) + if opts.responseHeader != nil { + *opts.responseHeader = res.Header + } + body := newLoggedBody(ctx, "response body", newStallGuardedBody(res.Body, cancel)) if isSuccess(res.StatusCode) { - return responseBody, nil + return body, nil } - - return responseBody, Error{ + responseBody, err := io.ReadAll(body) + _ = body.Close() + if err != nil { + return nil, fmt.Errorf("cannot read response body, status code %d: %w", res.StatusCode, err) + } + return nil, Error{ + Method: res.Request.Method, + Url: res.Request.URL.Redacted(), StatusCode: res.StatusCode, ResponseBody: responseBody, } } -func (c Client) buildRequest(ctx context.Context, method string, url *url.URL, opts requestOptions) (*gohttp.Request, error) { - var requestBody io.ReadWriter - if opts.requestPayload != nil { - requestBodyData, err := opts.requestPayload() - if err != nil { - return nil, fmt.Errorf("cannot build request body data: %w", err) - } - requestBody = bytes.NewBuffer(requestBodyData) - } - - if opts.retryable { - ctx = context.WithValue(ctx, retryableKey{}, true) - } - - req, err := gohttp.NewRequestWithContext(ctx, method, url.String(), requestBody) +// newRequest opens the body after every modifier, so that a modifier's error leaves none open. +func (opts requestOptions) newRequest(ctx context.Context, method string, url *url.URL) (*gohttp.Request, error) { + req, err := gohttp.NewRequestWithContext(opts.requestContext(ctx), method, url.String(), nil) if err != nil { return nil, fmt.Errorf("failed to create request: %w", err) } @@ -144,6 +125,16 @@ func (c Client) buildRequest(ctx context.Context, method string, url *url.URL, o return nil, err } } - slog.DebugContext(ctx, "request", "url", req.URL.String(), "method", req.Method, "headers", loggedHeaders(req.Header), "body", loggedBody{requestBody}) + if opts.setBody != nil { + if err := opts.setBody(req); err != nil { + return nil, fmt.Errorf("cannot build request body: %w", err) + } + } + req.Body = newLoggedBody(ctx, "request body", req.Body) + slog.DebugContext(ctx, "request", "url", req.URL.String(), "method", req.Method, "headers", loggedHeaders(req.Header)) return req, nil } + +func isSuccess(statusCode int) bool { + return statusCode >= 200 && statusCode <= 299 +} diff --git a/client/http/http_client_test.go b/client/http/http_client_test.go index 3823545a..4431902b 100644 --- a/client/http/http_client_test.go +++ b/client/http/http_client_test.go @@ -1,10 +1,8 @@ -// Package http_test drives the client from the outside, so that it can parse answers into the -// types real callers declare. client/http may not import any of them. -package http_test +package http import ( + "bytes" "context" - "encoding/base64" "errors" "fmt" "io" @@ -12,425 +10,397 @@ import ( gohttp "net/http" "net/http/httptest" "net/url" + "os" + "path/filepath" + "strings" + "sync/atomic" + "syscall" "testing" - "testing/synctest" "time" + "github.com/Shopify/toxiproxy/v2" + "github.com/rs/zerolog" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/meshcloud/meshstack-cli/client/http" "github.com/meshcloud/meshstack-cli/client/types/xurl" + "github.com/meshcloud/meshstack-cli/internal/json" "github.com/meshcloud/meshstack-cli/internal/logs" - "github.com/meshcloud/meshstack-cli/internal/oidc/jwt" - "github.com/meshcloud/meshstack-cli/internal/testutil/fakemeshstack" ) -func TestHttpClient(t *testing.T) { - t.Run("DoRequest success", func(t *testing.T) { - captured := logs.Capture(t) - client := newTestClientWithServer(t, func(resp gohttp.ResponseWriter, req *gohttp.Request) { - resp.WriteHeader(gohttp.StatusOK) - _, _ = resp.Write([]byte(`"some-answer"`)) - assert.Equal(t, "/get", req.URL.Path) - assert.Equal(t, gohttp.MethodGet, req.Method) - assert.Equal(t, "fakemeshstack/test", req.Header.Get("User-Agent")) - }) - resp, err := client.DoRequest[string](t.Context(), gohttp.MethodGet, client.ServerUrl.JoinPath("get")) +var testUserAgent = UserAgent{GitHubRepo: "meshcloud/meshstack-cli", Version: "test"} + +func TestMain(m *testing.M) { + stallTimeout = 5 * time.Second + goClient = newGoClient() + m.Run() +} + +func TestDoRequest(t *testing.T) { + var answer struct { + status int + body string + } + var received []string + server := newTestServer(t, func(w gohttp.ResponseWriter, r *gohttp.Request) { + body, _ := io.ReadAll(r.Body) + received = append(received, r.Method+" "+r.Header.Get("User-Agent")+" "+string(body)) + w.Header()["Date"] = nil + w.WriteHeader(answer.status) + _, _ = io.WriteString(w, answer.body) + }) + client := NewClient(testUserAgent) + + t.Run("sends the user agent and parses the answer", func(t *testing.T) { + answer.status, answer.body = gohttp.StatusOK, `{"name":"answered"}` + + got, err := UnmarshalJsonBody[map[string]string](client.DoRequest(t.Context(), MethodPost, server.Url, + WithJsonRequest(map[string]string{"name": "sent"}, ""))) + require.NoError(t, err) - assert.Equal(t, "some-answer", resp) - assert.Equal(t, []string{ - fmt.Sprintf(`level=DEBUG msg=request url=%s/get method=GET headers="User-Agent=fakemeshstack/test" body=`, client.ServerUrl), - `level=DEBUG msg=response status=200 body="\"some-answer\""`, - }, captured.Lines(slog.LevelDebug)) + assert.Equal(t, map[string]string{"name": "answered"}, got) + assert.Equal(t, []string{`POST meshstack-cli/test {"name":"sent"}`}, received) }) - t.Run("DoRequest object call with empty 2xx body errors", func(t *testing.T) { - client := newTestClientWithServer(t, func(resp gohttp.ResponseWriter, _ *gohttp.Request) { - resp.WriteHeader(gohttp.StatusOK) - }) - _, err := client.DoRequest[*string](t.Context(), gohttp.MethodGet, client.ServerUrl.JoinPath("get")) - require.Error(t, err) - assert.ErrorContains(t, err, "unexpected empty response body") + t.Run("a non-2xx is an Error with the whole body", func(t *testing.T) { + answer.status, answer.body = gohttp.StatusNotFound, strings.Repeat("x", 2*loggedBodyLimit) + + err := IgnoreResponse(client.DoRequest(t.Context(), MethodGet, server.Url)) + + httpErr, ok := errors.AsType[Error](err) + require.True(t, ok, "%v", err) + assert.Equal(t, Error{Method: MethodGet, Url: server.Url.String(), StatusCode: gohttp.StatusNotFound, ResponseBody: []byte(answer.body)}, httpErr) }) - t.Run("DoRequest no-content call (any) tolerates an empty 2xx body", func(t *testing.T) { - client := newTestClientWithServer(t, func(resp gohttp.ResponseWriter, _ *gohttp.Request) { - resp.WriteHeader(gohttp.StatusAccepted) - }) - _, err := client.DoRequest[any](t.Context(), gohttp.MethodPost, client.ServerUrl.JoinPath("trigger-run")) - require.NoError(t, err) + t.Run("WithoutRedirects answers with the 3xx", func(t *testing.T) { + answer.status, answer.body = gohttp.StatusFound, "" + + err := IgnoreResponse(client.DoRequest(t.Context(), MethodGet, server.Url, WithoutRedirects())) + + httpErr, ok := errors.AsType[Error](err) + require.True(t, ok, "%v", err) + assert.Equal(t, gohttp.StatusFound, httpErr.StatusCode) }) +} - t.Run("DoRequest with successful retry", func(t *testing.T) { - for _, retryableStatusCode := range []int{429, 502, 503, 504} { - t.Run(fmt.Sprintf("after code %d", retryableStatusCode), func(t *testing.T) { - synctest.Test(t, func(t *testing.T) { - captured := logs.Capture(t) - retryTestBackoff := retryTestBackoff{WaitTime: 1 * time.Second} - retried := false - client := withTestRetry(newTestClientWithServer(t, func(resp gohttp.ResponseWriter, _ *gohttp.Request) { - if !retried { - if retryableStatusCode == 429 { - // Delay-seconds form. The HTTP-date form needs a mocked clock, which - // only a test inside the package can install, so TestRetryAfterBackoff - // covers it. - resp.Header().Set("Retry-After", "1") - } - resp.WriteHeader(retryableStatusCode) - retried = true - return - } - resp.WriteHeader(gohttp.StatusOK) - _, _ = resp.Write([]byte(`{}`)) - }), http.RetryOptions{MaxRetries: 3, Backoff: &retryTestBackoff}) - start := time.Now() - - _, err := client.DoRequest[any](t.Context(), gohttp.MethodGet, client.ServerUrl.JoinPath("get")) - - require.NoError(t, err) - assert.Equal(t, time.Second, time.Since(start), "the retry waited as long as it logged") - if retryableStatusCode == 429 { - assert.Equal(t, 0, retryTestBackoff.Called) - } else { - assert.Equal(t, 1, retryTestBackoff.Called) - } - assert.Equal(t, []string{ - fmt.Sprintf(`level=WARN msg="retrying request" status=%d method=GET path=/get attempt=1/3 waitTime=1s`, retryableStatusCode), - }, captured.Lines(slog.LevelWarn)) - }) - }) - } +func TestRetry(t *testing.T) { + var attempts atomic.Int32 + var answers []int + var bodies []string + server := newTestServer(t, func(w gohttp.ResponseWriter, r *gohttp.Request) { + body, _ := io.ReadAll(r.Body) + bodies = append(bodies, string(body)) + status := answers[min(int(attempts.Add(1))-1, len(answers)-1)] + w.WriteHeader(status) }) + reset := func(statuses ...int) *testBackoff { + attempts.Store(0) + answers, bodies = statuses, nil + return &testBackoff{} + } + client := NewClient(testUserAgent) - t.Run("DoRequest with 2 retries exhausted", func(t *testing.T) { - captured := logs.Capture(t) - backoff := retryTestBackoff{} - client := withTestRetry(newTestClientWithServer(t, func(resp gohttp.ResponseWriter, _ *gohttp.Request) { - resp.WriteHeader(gohttp.StatusBadGateway) - }), http.RetryOptions{MaxRetries: 2, Backoff: &backoff}) - _, err := client.DoRequest[any](t.Context(), gohttp.MethodGet, client.ServerUrl.JoinPath("get")) - var httpErr http.Error - require.ErrorAs(t, err, &httpErr) - assert.Equal(t, 502, httpErr.StatusCode) - assert.Equal(t, 2, backoff.Called) - assert.Equal(t, []string{ - fmt.Sprintf(`level=DEBUG msg=request url=%s/get method=GET headers="User-Agent=fakemeshstack/test" body=`, client.ServerUrl), - `level=WARN msg="retrying request" status=502 method=GET path=/get attempt=1/2 waitTime=0s`, - `level=WARN msg="retrying request" status=502 method=GET path=/get attempt=2/2 waitTime=0s`, - `level=DEBUG msg=response status=502 body=`, - }, captured.Lines(slog.LevelDebug)) + t.Run("a GET outlasts a busy or failing gateway", func(t *testing.T) { + for _, status := range []int{429, 502, 503, 504} { + captured := logs.Capture(t) + backoff := reset(status, gohttp.StatusOK) + + err := IgnoreResponse(client.DoRequest(t.Context(), MethodGet, server.Url, backoff.option())) + + require.NoError(t, err, status) + assert.Equal(t, int32(2), attempts.Load(), status) + assert.Equal(t, []string{ + fmt.Sprintf(`level=WARN msg="retrying request" status=%d method=GET path=/ attempt=1/2 waitTime=0s`, status), + }, captured.Lines(slog.LevelWarn)) + } }) - t.Run("DoRequest with context cancelled during backoff", func(t *testing.T) { - synctest.Test(t, func(t *testing.T) { - const cancelAfter = 1 * time.Second - backoff := retryTestBackoff{WaitTime: 10 * time.Second} - client := withTestRetry(newTestClientWithServer(t, func(resp gohttp.ResponseWriter, _ *gohttp.Request) { - resp.WriteHeader(gohttp.StatusBadGateway) - }), http.RetryOptions{MaxRetries: 3, Backoff: &backoff}) - // The bubble's clock only moves once the 502 has arrived and the backoff waits, so this - // cancels inside the wait. Cancelling from the handler raced the 502 back to the client. - ctx, cancel := context.WithCancel(t.Context()) - time.AfterFunc(cancelAfter, cancel) - start := time.Now() - - _, err := client.DoRequest[any](ctx, gohttp.MethodGet, client.ServerUrl.JoinPath("get")) - - require.ErrorIs(t, err, context.Canceled) - assert.Equal(t, 1, backoff.Called) - assert.Equal(t, cancelAfter, time.Since(start), "the cancellation ended the backoff rather than waiting it out") - }) + t.Run("gives up after the last retry with the last answer", func(t *testing.T) { + backoff := reset(gohttp.StatusBadGateway) + + err := IgnoreResponse(client.DoRequest(t.Context(), MethodGet, server.Url, backoff.option())) + + httpErr, ok := errors.AsType[Error](err) + require.True(t, ok, "%v", err) + assert.Equal(t, gohttp.StatusBadGateway, httpErr.StatusCode) + assert.Equal(t, int32(3), attempts.Load()) }) - // GET is the only method the client replays unasked, so MeshObjectClient marks its - // idempotent PUT and DELETE with Retryable. - t.Run("DoRequest replays another method than GET only when the caller marked it Retryable, body included", func(t *testing.T) { - var bodies []string - client := withTestRetry(newTestClientWithServer(t, func(resp gohttp.ResponseWriter, req *gohttp.Request) { - body, _ := io.ReadAll(req.Body) - bodies = append(bodies, string(body)) - if len(bodies) == 1 { - resp.WriteHeader(gohttp.StatusServiceUnavailable) - return - } - resp.WriteHeader(gohttp.StatusNoContent) - }), http.RetryOptions{MaxRetries: 3, Backoff: &retryTestBackoff{}}) - payload := http.WithJsonPayload(map[string]string{"key": "value"}, "application/json") - - for _, method := range []string{gohttp.MethodPatch, gohttp.MethodPost, gohttp.MethodPut, gohttp.MethodDelete} { - bodies = nil - _, err := client.DoRequest[any](t.Context(), method, client.ServerUrl, payload) - require.Error(t, err, method) - assert.Len(t, bodies, 1, "%s may change something, so replaying it needs the caller's word", method) - - bodies = nil - _, err = client.DoRequest[any](t.Context(), method, client.ServerUrl, payload, http.Retryable()) - require.NoError(t, err, method) - assert.Equal(t, []string{`{"key":"value"}`, `{"key":"value"}`}, bodies, method) + t.Run("another method than GET is replayed after a gateway error only when Retryable, body included", func(t *testing.T) { + path := filepath.Join(t.TempDir(), "plan") + require.NoError(t, os.WriteFile(path, []byte("a plan"), 0o600)) + for name, payload := range map[string]RequestOption{ + `{"key":"value"}`: WithJsonRequest(map[string]string{"key": "value"}, ""), + "a plan": WithFileRequest(path, ""), + } { + backoff := reset(gohttp.StatusBadGateway, gohttp.StatusNoContent) + err := IgnoreResponse(client.DoRequest(t.Context(), MethodPut, server.Url, payload, backoff.option())) + require.Error(t, err) + assert.Equal(t, []string{name}, bodies, "the server may have acted on a PUT it answered with 502, so replaying it needs the caller's word") + + backoff = reset(gohttp.StatusBadGateway, gohttp.StatusNoContent) + err = IgnoreResponse(client.DoRequest(t.Context(), MethodPut, server.Url, payload, backoff.option(), Retryable(RetryOnTransient))) + require.NoError(t, err) + assert.Equal(t, []string{name, name}, bodies) } }) - t.Run("DoRequest re-mints once on 401", func(t *testing.T) { - t.Run("retries with the freshly minted token", func(t *testing.T) { - auth := &refreshableAuthorization{token: "stale"} - var seen []string - client := newTestClientWithServer(t, func(resp gohttp.ResponseWriter, req *gohttp.Request) { - seen = append(seen, req.Header.Get("Authorization")) - if req.Header.Get("Authorization") == "Bearer stale" { - resp.WriteHeader(gohttp.StatusUnauthorized) - return - } - resp.WriteHeader(gohttp.StatusAccepted) - }) - _, err := client.WithAuthorization(auth).DoRequest[any](t.Context(), gohttp.MethodPut, client.ServerUrl.JoinPath("edit")) + t.Run("another method than GET is replayed by default after a status that says the server did not act", func(t *testing.T) { + for _, status := range []int{gohttp.StatusServiceUnavailable, gohttp.StatusLocked} { + backoff := reset(status, gohttp.StatusNoContent) + err := IgnoreResponse(client.DoRequest(t.Context(), MethodPatch, server.Url, WithJsonRequest(map[string]string{"key": "value"}, ""), backoff.option())) require.NoError(t, err) - assert.Equal(t, []string{"Bearer stale", "Bearer fresh"}, seen) - assert.Equal(t, []http.BearerToken{"stale"}, auth.rejected, "the token that was refused is what the refresh is told about") - }) + assert.Len(t, bodies, 2) + } + }) - t.Run("reports the 401 when the re-mint changes nothing", func(t *testing.T) { - auth := &refreshableAuthorization{token: "stale", keepToken: true} - attempts := 0 - client := newTestClientWithServer(t, func(resp gohttp.ResponseWriter, _ *gohttp.Request) { - attempts++ - resp.WriteHeader(gohttp.StatusUnauthorized) - }) - _, err := client.WithAuthorization(auth).DoRequest[any](t.Context(), gohttp.MethodPut, client.ServerUrl.JoinPath("edit")) - var httpErr http.Error - require.ErrorAs(t, err, &httpErr) - assert.Equal(t, gohttp.StatusUnauthorized, httpErr.StatusCode) - assert.Equal(t, 1, attempts, "a re-mint that produced the same token has nothing new to try") - }) + t.Run("a reset connection is retried", func(t *testing.T) { + backoff := reset(gohttp.StatusOK) + server.addToxic(t, "reset_peer", "downstream", map[string]any{"timeout": 0}) + backoff.onRetry = func() { server.removeToxics(t) } - t.Run("reports both errors when the re-mint fails", func(t *testing.T) { - auth := &refreshableAuthorization{token: "stale", refreshErr: errors.New("the login expired")} - attempts := 0 - client := newTestClientWithServer(t, func(resp gohttp.ResponseWriter, _ *gohttp.Request) { - attempts++ - resp.WriteHeader(gohttp.StatusUnauthorized) - }) - _, err := client.WithAuthorization(auth).DoRequest[any](t.Context(), gohttp.MethodPut, client.ServerUrl.JoinPath("edit")) - var httpErr http.Error - require.ErrorAs(t, err, &httpErr, "the 401 the request ran into must stay reachable") - assert.Equal(t, gohttp.StatusUnauthorized, httpErr.StatusCode) - require.ErrorIs(t, err, auth.refreshErr, "and so must the reason nothing better could be tried") - assert.Equal(t, 1, attempts) - }) + err := IgnoreResponse(client.DoRequest(t.Context(), MethodGet, server.Url, backoff.option())) - t.Run("leaves an authorization that cannot re-mint alone", func(t *testing.T) { - attempts := 0 - client := newTestClientWithServer(t, func(resp gohttp.ResponseWriter, _ *gohttp.Request) { - attempts++ - resp.WriteHeader(gohttp.StatusUnauthorized) - }) - _, err := client.WithAuthorization(http.BearerToken("static")).DoRequest[any](t.Context(), gohttp.MethodPut, client.ServerUrl.JoinPath("edit")) - var httpErr http.Error - require.ErrorAs(t, err, &httpErr) - assert.Equal(t, gohttp.StatusUnauthorized, httpErr.StatusCode) - assert.Equal(t, 1, attempts) - }) + require.NoError(t, err) + assert.Equal(t, int32(1), backoff.calls.Load()) }) - t.Run("DoRequest of []byte returns the retried answer as it came, empty included", func(t *testing.T) { - auth := &refreshableAuthorization{token: "stale"} - answer := "plain text" - client := newTestClientWithServer(t, func(resp gohttp.ResponseWriter, req *gohttp.Request) { - if req.Header.Get("Authorization") == "Bearer stale" { - resp.WriteHeader(gohttp.StatusUnauthorized) - _, _ = io.WriteString(resp, "expired") - return - } - _, _ = io.WriteString(resp, answer) - }) - body, err := client.WithAuthorization(auth).DoRequest[[]byte](t.Context(), gohttp.MethodGet, client.ServerUrl.JoinPath("get")) - require.NoError(t, err) - assert.Equal(t, "plain text", string(body)) + t.Run("a refused connection is not retried", func(t *testing.T) { + backoff := reset(gohttp.StatusOK) + server.proxy.Stop() + t.Cleanup(func() { require.NoError(t, server.proxy.Start()) }) - answer = "" - body, err = client.DoRequest[[]byte](t.Context(), gohttp.MethodDelete, client.ServerUrl.JoinPath("delete")) - require.NoError(t, err) - assert.Empty(t, body) + err := IgnoreResponse(client.DoRequest(t.Context(), MethodGet, server.Url, backoff.option())) + + require.ErrorIs(t, err, syscall.ECONNREFUSED) + assert.Zero(t, backoff.calls.Load()) }) -} -type refreshableAuthorization struct { - token http.BearerToken - keepToken bool - refreshErr error - rejected []http.BearerToken -} + t.Run("a server that does not answer is given up after stallTimeout, and not retried", func(t *testing.T) { + backoff := reset(gohttp.StatusOK) + server.addToxic(t, "timeout", "upstream", map[string]any{"timeout": 0}) + t.Cleanup(func() { server.removeToxics(t) }) + start := time.Now() -func (a *refreshableAuthorization) GetBearerToken(context.Context) (http.BearerToken, error) { - return a.token, nil -} + err := IgnoreResponse(client.DoRequest(t.Context(), MethodGet, server.Url, backoff.option())) -func (a *refreshableAuthorization) Scope() string { - return "" -} + require.ErrorContains(t, err, "timeout awaiting response headers") + assert.GreaterOrEqual(t, time.Since(start), stallTimeout) + assert.Zero(t, backoff.calls.Load()) + }) -func (a *refreshableAuthorization) RefreshBearerToken(_ context.Context, rejected http.BearerToken) (http.BearerToken, error) { - a.rejected = append(a.rejected, rejected) - if a.refreshErr != nil { - return "", a.refreshErr - } - if !a.keepToken { - a.token = "fresh" - } - return a.token, nil -} + t.Run("stops once the context is done", func(t *testing.T) { + backoff := reset(gohttp.StatusBadGateway) + ctx, cancel := context.WithCancel(t.Context()) + backoff.onRetry = cancel + + err := IgnoreResponse(client.DoRequest(ctx, MethodGet, server.Url, backoff.option())) -func TestUrlQueryOptions(t *testing.T) { - var got url.Values - client := newTestClientWithServer(t, func(resp gohttp.ResponseWriter, req *gohttp.Request) { - got = req.URL.Query() - _, _ = resp.Write([]byte(`"ok"`)) + require.ErrorIs(t, err, context.Canceled) + assert.Equal(t, int32(1), backoff.calls.Load()) }) - queryFrom := func(t *testing.T, queries ...any) url.Values { +} + +func TestStallGuard(t *testing.T) { + readBody := func(t *testing.T, server testServer) (string, time.Duration, error) { t.Helper() - var options []http.RequestOption - for _, query := range queries { - options = append(options, http.WithUrlQuery(query)) - } - _, err := client.DoRequest[string](t.Context(), gohttp.MethodGet, client.ServerUrl.JoinPath("list"), options...) + start := time.Now() + response, err := NewClient(testUserAgent).DoRequest(t.Context(), MethodGet, server.Url) require.NoError(t, err) - return got + body, err := io.ReadAll(response) + _ = response.Close() + return string(body), time.Since(start), err } - t.Run("a map or url.Values goes as given, a zero value and a repeated parameter included", func(t *testing.T) { - query := url.Values{"dry": {"true"}, "tag": {"a", "b"}, "empty": {""}} - assert.Equal(t, query, queryFrom(t, query)) - assert.Equal(t, url.Values{"page": {"0"}, "status": {"SUCCEEDED"}}, queryFrom(t, map[string]any{"page": 0, "status": "SUCCEEDED"})) - }) + t.Run("a body that stops arriving ends after stallTimeout", func(t *testing.T) { + server := newTestServer(t, func(w gohttp.ResponseWriter, r *gohttp.Request) { + _, _ = io.WriteString(w, "partial") + _ = gohttp.NewResponseController(w).Flush() + <-r.Context().Done() + }) + + body, took, err := readBody(t, server) - t.Run("a second query adds to the first", func(t *testing.T) { - assert.Equal(t, url.Values{"buildingBlockDefinitionUuid": {"abc"}, "page": {"2"}}, - queryFrom(t, map[string]string{"buildingBlockDefinitionUuid": "abc"}, map[string]any{"page": 2})) + require.ErrorContains(t, err, "response body stalled: nothing received for 5s") + assert.Equal(t, "partial", body) + assert.GreaterOrEqual(t, took, stallTimeout) }) - t.Run("a struct names its fields by json tag and drops the zero ones", func(t *testing.T) { - type filter struct { - Identifier *string `json:"identifier"` - Name string `json:"name"` - Restricted *bool `json:"restricted"` - ExcludeTitle []string `json:"excludeTitle"` - Other []string `json:"other"` - } - assert.Equal(t, url.Values{"identifier": {"abc"}, "excludeTitle": {"Workspace Created", "Tenant Deleted"}}, - queryFrom(t, filter{Identifier: new("abc"), ExcludeTitle: []string{"Workspace Created", "", "Tenant Deleted"}}), - "a slice is the parameter repeated, and drops an empty string like a zero field") - assert.Empty(t, queryFrom(t, &struct { - Identifier *string `json:"identifier"` - }{}), "a pointer to a struct drops its nil fields") + t.Run("a body that takes longer than stallTimeout but keeps arriving is read to the end", func(t *testing.T) { + answer := strings.Repeat(".", 8*1000) + server := newTestServer(t, func(w gohttp.ResponseWriter, _ *gohttp.Request) { + _, _ = io.WriteString(w, answer) + }) + server.addToxic(t, "bandwidth", "downstream", map[string]any{"rate": 1}) + + body, took, err := readBody(t, server) + + require.NoError(t, err) + assert.Equal(t, answer, body) + assert.Greater(t, took, stallTimeout) }) } -func TestFormPayloadOption(t *testing.T) { - var header gohttp.Header - var form url.Values - var answer string - client := newTestClientWithServer(t, func(resp gohttp.ResponseWriter, req *gohttp.Request) { - assert.NoError(t, req.ParseForm()) - header, form = req.Header, req.PostForm - _, _ = io.WriteString(resp, answer) +func TestAuthorizedClient(t *testing.T) { + var seen []string + server := newTestServer(t, func(w gohttp.ResponseWriter, r *gohttp.Request) { + seen = append(seen, r.Header.Get("Authorization")) + if r.Header.Get("Authorization") != "Bearer fresh" { + w.WriteHeader(gohttp.StatusUnauthorized) + _, _ = io.WriteString(w, "expired") + return + } + _, _ = io.WriteString(w, `"answer"`) }) - postForm := func(t *testing.T, payload any) { + doRequest := func(t *testing.T, auth Authorization) (string, error) { t.Helper() - answer = `"ok"` - _, err := client.DoRequest[string](t.Context(), gohttp.MethodPost, client.ServerUrl.JoinPath("token"), http.WithFormPayload(payload)) - require.NoError(t, err) + seen = nil + client := NewClient(testUserAgent).WithAuthorization(auth) + return UnmarshalJsonBody[string](client.DoRequest(t.Context(), MethodPut, server.Url)) } - t.Run("a struct becomes a form named by its json tags", func(t *testing.T) { - type refreshGrant struct { - GrantType string `json:"grant_type"` - RefreshToken string `json:"refresh_token"` - ClientId string `json:"client_id"` - CodeVerifier string `json:"code_verifier"` - } - postForm(t, refreshGrant{GrantType: "refresh_token", RefreshToken: "the-rotating-one", ClientId: "meshstack-cli"}) - assert.Equal(t, "application/x-www-form-urlencoded", header.Get("Content-Type")) - assert.Equal(t, "application/json", header.Get("Accept")) - assert.Equal(t, url.Values{"grant_type": {"refresh_token"}, "refresh_token": {"the-rotating-one"}, "client_id": {"meshstack-cli"}}, form, - "a field the grant does not use must not be sent empty") + t.Run("a 401 is retried once with the freshly minted token", func(t *testing.T) { + auth := &refreshableAuthorization{token: "stale"} + got, err := doRequest(t, auth) + require.NoError(t, err) + assert.Equal(t, "answer", got) + assert.Equal(t, []string{"Bearer stale", "Bearer fresh"}, seen) + assert.Equal(t, []BearerToken{"stale"}, auth.rejected, "the token that was refused is what the refresh is told about") }) - t.Run("no payload sends no body", func(t *testing.T) { - postForm(t, nil) - assert.Empty(t, form) - assert.Empty(t, header.Get("Content-Type")) + t.Run("a re-mint that changes nothing reports the 401", func(t *testing.T) { + _, err := doRequest(t, &refreshableAuthorization{token: "stale", keepToken: true}) + httpErr, ok := errors.AsType[Error](err) + require.True(t, ok, "%v", err) + assert.Equal(t, gohttp.StatusUnauthorized, httpErr.StatusCode) + assert.Len(t, seen, 1) }) - t.Run("a form sends a URL and a JWT as the text they came from", func(t *testing.T) { - type logoutRequest struct { - RedirectUri xurl.URL `json:"post_logout_redirect_uri"` - IdToken jwt.JWT `json:"id_token_hint"` - Unset *xurl.URL `json:"unset_uri"` - } - var idToken jwt.JWT - require.NoError(t, idToken.UnmarshalText([]byte(unsignedJwt(`{"sub":"someone"}`)))) + t.Run("a failing re-mint reports both errors", func(t *testing.T) { + auth := &refreshableAuthorization{token: "stale", refreshErr: errors.New("the login expired")} + _, err := doRequest(t, auth) + _, ok := errors.AsType[Error](err) + assert.True(t, ok, "the 401 the request ran into must stay reachable: %v", err) + require.ErrorIs(t, err, auth.refreshErr, "and so must the reason nothing better could be tried") + assert.Len(t, seen, 1) + }) - postForm(t, logoutRequest{RedirectUri: xurl.MustParsef("http://127.0.0.1:31234/callback"), IdToken: idToken}) - assert.Equal(t, url.Values{"post_logout_redirect_uri": {"http://127.0.0.1:31234/callback"}, "id_token_hint": {idToken.String()}}, form, - "a URL nobody set is dropped like any other zero value") + t.Run("a static token is not re-minted", func(t *testing.T) { + _, err := doRequest(t, BearerToken("static")) + require.Error(t, err) + assert.Len(t, seen, 1) }) +} - type tokenResponse struct { - Issuer xurl.URL `json:"issuer"` - AccessToken jwt.JWT `json:"access_token"` +func TestConvertStructOrMapToUrlValues(t *testing.T) { + convert := func(t *testing.T, structOrMap any) url.Values { + t.Helper() + values, err := convertStructOrMapToUrlValues(structOrMap) + require.NoError(t, err) + return values } - t.Run("the answer parses into the types the caller declared", func(t *testing.T) { - accessToken := unsignedJwt(`{"MC_CUSTOMER":"my-workspace"}`) - answer = fmt.Sprintf(`{"issuer":"https://sso.example.com/realms/meshfed","access_token":%q}`, accessToken) - got, err := client.DoRequest[tokenResponse](t.Context(), gohttp.MethodPost, client.ServerUrl.JoinPath("token")) - require.NoError(t, err) - assert.Equal(t, "sso.example.com", got.Issuer.Host, "the field is a parsed URL, not the text it came from") - assert.Equal(t, accessToken, got.AccessToken.String()) + t.Run("a map goes as given, a zero value and a repeated parameter included", func(t *testing.T) { + query := url.Values{"dry": {"true"}, "tag": {"a", "b"}, "empty": {""}} + assert.Equal(t, query, convert(t, query)) + assert.Equal(t, url.Values{"page": {"0"}, "at": {"1234567890123456789"}}, convert(t, map[string]any{"page": 0, "at": 1234567890123456789}), + "a large number stays the literal it marshalled to") }) - // Which texts jwt.JWT refuses is pinned in the jwt package, against its own testdata. - t.Run("an answer that is not what those types accept fails the call", func(t *testing.T) { - answer = `{"access_token":"an-opaque-token"}` - - _, err := client.DoRequest[tokenResponse](t.Context(), gohttp.MethodPost, client.ServerUrl.JoinPath("token")) - assert.ErrorContains(t, err, "not a JWT") + t.Run("a struct names its fields by json tag and drops the zero ones", func(t *testing.T) { + type filter struct { + Identifier *string `json:"identifier"` + Name string `json:"name"` + Restricted *bool `json:"restricted"` + ExcludeTitle []string `json:"excludeTitle"` + RedirectUri xurl.URL `json:"redirect_uri"` + Unset *xurl.URL `json:"unset_uri"` + } + assert.Equal(t, url.Values{ + "identifier": {"abc"}, + "excludeTitle": {"Workspace Created", "Tenant Deleted"}, + "redirect_uri": {"http://127.0.0.1:31234/callback"}, + }, convert(t, filter{ + Identifier: new("abc"), + ExcludeTitle: []string{"Workspace Created", "", "Tenant Deleted"}, + RedirectUri: xurl.MustParsef("http://127.0.0.1:31234/callback"), + })) + assert.Empty(t, convert(t, &struct { + Identifier *string `json:"identifier"` + }{}), "a pointer to a struct drops its nil fields") }) } -func unsignedJwt(claims string) string { - return "e30." + base64.RawURLEncoding.EncodeToString([]byte(claims)) + ".not-a-signature" +type testServer struct { + Url *url.URL + proxy *toxiproxy.Proxy } -type TestClient struct { - http.Client - - ServerUrl *url.URL +func newTestServer(t *testing.T, handler gohttp.HandlerFunc) testServer { + t.Helper() + upstream := httptest.NewServer(handler) + t.Cleanup(upstream.Close) + proxy := toxiproxy.NewProxy(toxiproxy.NewServer(toxiproxy.NewMetricsContainer(nil), zerolog.Nop()), t.Name(), "127.0.0.1:0", upstream.Listener.Addr().String()) + require.NoError(t, proxy.Start()) + t.Cleanup(proxy.Stop) + return testServer{Url: &url.URL{Scheme: "http", Host: proxy.Listen, Path: "/"}, proxy: proxy} } -func newTestClientWithServer(t *testing.T, handlerFunc gohttp.HandlerFunc) TestClient { +func (s testServer) addToxic(t *testing.T, toxicType, stream string, attributes map[string]any) { t.Helper() - // In memory, so that a test can run inside a synctest bubble. - server := httptest.NewTestServer(t, handlerFunc) - client := server.Client() - serverUrl, err := url.Parse(server.URL) + toxic, err := json.Marshal(map[string]any{"type": toxicType, "stream": stream, "attributes": attributes}) require.NoError(t, err) - return TestClient{http.Client{Client: client, UserAgent: fakemeshstack.UserAgent}, serverUrl} + _, err = s.proxy.Toxics.AddToxicJson(bytes.NewReader(toxic)) + require.NoError(t, err) +} + +func (s testServer) removeToxics(t *testing.T) { + t.Helper() + s.proxy.Toxics.ResetToxics(t.Context()) +} + +type testBackoff struct { + calls atomic.Int32 + onRetry func() +} + +func (b *testBackoff) Calculate(int) time.Duration { + b.calls.Add(1) + if b.onRetry != nil { + b.onRetry() + } + return 0 +} + +func (b *testBackoff) option() RequestOption { + return func(opts *requestOptions) { + opts.retry.maxRetries = 2 + opts.retry.backoff = b + } +} + +type refreshableAuthorization struct { + token BearerToken + keepToken bool + refreshErr error + rejected []BearerToken } -// withTestRetry gives one test client its own retry policy. The shipped client is the one shared -// one and takes no configuration, so a test that needs a backoff it can count builds its own. -func withTestRetry(c TestClient, options http.RetryOptions) TestClient { - options.ApplyTo(c.Client.Client) - return c +func (a *refreshableAuthorization) GetBearerToken(context.Context) (BearerToken, error) { + return a.token, nil } -type retryTestBackoff struct { - WaitTime time.Duration - Called int +func (a *refreshableAuthorization) String() string { + return "refreshableAuthorization" } -func (b *retryTestBackoff) Calculate(int) time.Duration { - b.Called++ - return b.WaitTime +func (a *refreshableAuthorization) RefreshBearerToken(_ context.Context, rejected BearerToken) (BearerToken, error) { + a.rejected = append(a.rejected, rejected) + if a.refreshErr != nil { + return "", a.refreshErr + } + if !a.keepToken { + a.token = "fresh" + } + return a.token, nil } diff --git a/client/http/http_error.go b/client/http/http_error.go index e20c3a89..754d4a99 100644 --- a/client/http/http_error.go +++ b/client/http/http_error.go @@ -1,13 +1,15 @@ package http import ( - "encoding/json/v2" "fmt" gohttp "net/http" "strings" + + "github.com/meshcloud/meshstack-cli/internal/json" ) type Error struct { + Method, Url string StatusCode int ResponseBody []byte } @@ -15,14 +17,18 @@ type Error struct { // Error describes the response from its fields, with the clientVersionHint on a line of its own. A // response of another format is shown as it came. func (e Error) Error() string { + message := e.Summary() body, ok := e.body() - if !ok { - return fmt.Sprintf("%s, but the response is not in the expected error format: '%s'", e.Summary(), string(e.ResponseBody)) + switch { + case !ok: + message = fmt.Sprintf("%s, but the response is not in the expected error format: '%s'", message, string(e.ResponseBody)) + case body.ClientVersionHint != "": + message += "\n" + body.ClientVersionHint } - if body.ClientVersionHint != "" { - return e.Summary() + "\n" + body.ClientVersionHint + if e.Method == "" { + return message } - return e.Summary() + return e.Method + " " + e.Url + ": " + message } // Summary is Error without the clientVersionHint and without a body of an unexpected format. diff --git a/client/http/logging.go b/client/http/logging.go index d6bfadb4..467b7b52 100644 --- a/client/http/logging.go +++ b/client/http/logging.go @@ -2,29 +2,19 @@ package http import ( "bytes" + "context" "encoding" - "encoding/json/jsontext" "errors" "fmt" "io" + "log/slog" "maps" gohttp "net/http" - "regexp" "slices" "strings" + "unicode/utf8" ) -// This package logs through slog's default logger, and each front end installs its handler on it -// late: the Terraform provider does so in Configure. Two rules follow. -// -// - Reach the logger through the slog package functions at the point of use, and pass the -// request's context — DebugContext, not Debug. The provider's handler reads terraform's -// logger out of the context and drops a record that arrives without one. -// - Render an expensive attribute with fmt.Stringer and encoding.TextMarshaler, never with -// slog.LogValuer. The provider's handler resolves a LogValuer for every record, because its -// Enabled says yes to all of them and terraform owns the level, so a LogValuer would -// pretty-print every request body of every run including the ones TF_LOG then drops. - // loggedHeaders is the request's headers with the bearer token taken out. Both methods produce // that redacted form, because both are reached: the CLI's sink formats with %v and calls String, // while terraform's sink encodes the fields as JSON and would otherwise walk this map itself and @@ -53,102 +43,88 @@ func (l loggedHeaders) String() string { return strings.Join(lines, "\n") } -// loggedBody is a request or response body, pretty-printed when a sink writes it. Without -// MarshalText terraform's JSON log would show it as {"Reader":{}}. -type loggedBody struct { - io.Reader +const loggedBodyLimit = 1024 + +var errClosedEarly = errors.New("closed before its end") + +// A goroutine owns the logged bytes, because the transport may close a body while it reads it. +func newLoggedBody(ctx context.Context, message string, body io.ReadCloser) io.ReadCloser { + if body == nil || body == gohttp.NoBody || !slog.Default().Enabled(ctx, slog.LevelDebug) { + return body + } + tap, tapped := io.Pipe() + logged := make(chan struct{}) + go func() { + defer close(logged) + head, err := io.ReadAll(io.LimitReader(tap, loggedBodyLimit+1)) + _ = tap.Close() + slog.DebugContext(ctx, message, "body", loggedBody{head, err}) + }() + return tappedBody{body, tapped, logged} } -var ( - _ fmt.Stringer = loggedBody{} - _ encoding.TextMarshaler = loggedBody{} -) +type tappedBody struct { + io.ReadCloser -func (l loggedBody) MarshalText() ([]byte, error) { - return []byte(l.String()), nil + tap *io.PipeWriter + logged <-chan struct{} } -func (l loggedBody) String() string { - switch body := l.Reader.(type) { - case nil: - return "" - case *bytes.Buffer: - return bytesToPrettyJson(body.Bytes()) - default: - return fmt.Sprintf(" %v", body) +func (b tappedBody) Read(p []byte) (int, error) { + n, err := b.ReadCloser.Read(p) + if n > 0 { + _, _ = b.tap.Write(p[:n]) } + if err != nil { + _ = b.tap.CloseWithError(err) + } + return n, err } -// secretNamePattern matches the name of a JSON member or of a url-encoded field whose value is a -// credential: /api/login sends clientSecret, an OIDC grant sends and returns refresh_token and -// access_token, and a meshObject carries an API key secret or a secret input. Redacting a name -// such as token_type along with them costs a debug log nothing, while missing one writes a -// reusable credential into it. -const secretNamePattern = `(?i:secret|token|password|plaintext)` +func (b tappedBody) Close() error { + _ = b.tap.CloseWithError(errClosedEarly) + <-b.logged + return b.ReadCloser.Close() +} -const redactedValue = "[REDACTED]" +// Without MarshalText terraform's JSON log would show a loggedBody as {}. +type loggedBody struct { + // head holds one byte more than loggedBodyLimit when the body was longer. + head []byte + err error +} var ( - secretName = regexp.MustCompile(secretNamePattern) - secretField = regexp.MustCompile(`([^&=\s]*` + secretNamePattern + `[^&=\s]*)=[^&\s]*`) + _ fmt.Stringer = loggedBody{} + _ encoding.TextMarshaler = loggedBody{} ) -func bytesToPrettyJson(data []byte) string { - if len(data) == 0 { +func (b loggedBody) MarshalText() ([]byte, error) { + return []byte(b.String()), nil +} + +func (b loggedBody) String() string { + text := b.head[:min(len(b.head), loggedBodyLimit)] + switch { + case len(text) == 0 && b.err == nil: return "" + case isBinary(text): + return "" + case len(b.head) > loggedBodyLimit: + return string(text) + " [TRUNCATED]" + case b.err != nil: + return fmt.Sprintf("%s\n", text, b.err) } - if redacted, err := redactSecrets(data); err == nil { - return redacted.String() - } - // Not JSON: an OIDC grant sends a url-encoded form, and a gateway answers with plain text. - return fmt.Sprintf(" %s", len(data), secretField.ReplaceAllString(string(data), "${1}="+redactedValue)) + return string(text) } -// redactSecrets indents the body and replaces the value of every member secretName matches. It -// rewrites the token stream rather than a decoded value, so every number keeps the text it -// arrived with: decoded into float64, a large integer came back out with lost precision. -func redactSecrets(data []byte) (jsontext.Value, error) { - decoder := jsontext.NewDecoder(bytes.NewReader(data)) - var indented bytes.Buffer - encoder := jsontext.NewEncoder(&indented, jsontext.WithIndent(" ")) - secret := false - for { - if secret { - secret = false - if err := decoder.SkipValue(); err != nil { - return nil, err - } - if err := encoder.WriteToken(jsontext.String(redactedValue)); err != nil { - return nil, err - } - continue - } - switch decoder.PeekKind() { - case 0: - if _, err := decoder.ReadToken(); !errors.Is(err, io.EOF) { - return nil, fmt.Errorf("cannot read the body as JSON: %w", err) - } - // An indenting encoder terminates the top-level value with a newline, which would - // end the log line early. - return bytes.TrimSuffix(indented.Bytes(), []byte("\n")), nil - case '{', '}', '[', ']': - token, err := decoder.ReadToken() - if err != nil { - return nil, err - } - if err := encoder.WriteToken(token); err != nil { - return nil, err - } - default: - container, read := decoder.StackIndex(decoder.StackDepth()) - value, err := decoder.ReadValue() - if err != nil { - return nil, err - } - secret = container == '{' && read%2 == 0 && secretName.Match(value) - if err := encoder.WriteValue(value); err != nil { - return nil, err - } +// isBinary ignores an incomplete rune at the end, which the cap can cut. +func isBinary(data []byte) bool { + for range utf8.UTFMax - 1 { + if r, size := utf8.DecodeLastRune(data); r != utf8.RuneError || size != 1 { + break } + data = data[:len(data)-1] } + return !utf8.Valid(data) || bytes.IndexByte(data, 0) >= 0 } diff --git a/client/http/logging_internal_test.go b/client/http/logging_internal_test.go deleted file mode 100644 index ae7accb0..00000000 --- a/client/http/logging_internal_test.go +++ /dev/null @@ -1,58 +0,0 @@ -package http - -import ( - "bytes" - "log/slog" - "testing" - - "github.com/stretchr/testify/assert" -) - -// TestLogRenderingWaitsForTheSink stays in package http because it builds a loggedBody directly: -// the client only ever wraps a bytes.Buffer, so counting the renders needs a reader of its own. -func TestLogRenderingWaitsForTheSink(t *testing.T) { - previous := slog.Default() - slog.SetDefault(slog.New(slog.NewJSONHandler(&bytes.Buffer{}, &slog.HandlerOptions{Level: slog.LevelInfo}))) - t.Cleanup(func() { slog.SetDefault(previous) }) - - rendered := 0 - body := loggedBody{&countingReader{counted: &rendered}} - slog.DebugContext(t.Context(), "request", "body", body) - assert.Zero(t, rendered, "the dropped record still rendered its body") - - slog.InfoContext(t.Context(), "request", "body", body) - assert.Equal(t, 1, rendered, "the written record did not render its body") -} - -func TestLoggedBodyRedactsCredentialsAndKeepsTheRest(t *testing.T) { - const secret = "s3cr3t" - tests := map[string]string{ - "api key login": `{"clientId":"an-id","clientSecret":"` + secret + `","at":1234567890123456789}`, - "login answer": `{"access_token":"` + secret + `"}`, - "nested secret": `{"spec":{"config":{"clientSecret":{"plaintext":"` + secret + `"}}}}`, - "oidc grant form": `grant_type=refresh_token&refresh_token=` + secret + `&client_id=an-id`, - "oidc answer": `{"access_token":"` + secret + `","refresh_token":"` + secret + `","scope":"openid"}`, - } - for name, body := range tests { - t.Run(name, func(t *testing.T) { - rendered := loggedBody{bytes.NewBufferString(body)}.String() - assert.NotContains(t, rendered, secret) - assert.Contains(t, rendered, redactedValue) - }) - } - - rendered := loggedBody{bytes.NewBufferString(tests["api key login"])}.String() - assert.Contains(t, rendered, "an-id", "what is no credential stays") - assert.Contains(t, rendered, "1234567890123456789", "a large integer stays exact") -} - -type countingReader struct { - counted *int -} - -func (c *countingReader) Read([]byte) (int, error) { return 0, nil } - -func (c *countingReader) String() string { - *c.counted++ - return "counted" -} diff --git a/client/http/logging_test.go b/client/http/logging_test.go index b9533d66..4cb316d0 100644 --- a/client/http/logging_test.go +++ b/client/http/logging_test.go @@ -1,38 +1,90 @@ -package http_test +package http import ( "bytes" + "errors" + "fmt" + "io" "log/slog" gohttp "net/http" + "strings" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/meshcloud/meshstack-cli/client/http" + "github.com/meshcloud/meshstack-cli/internal/logs" ) -// TestJsonLogRedactsTheToken uses a handler that encodes attributes as JSON rather than -// formatting them with %v, which is what the Terraform provider's sink does. Without MarshalText -// that sink walks loggedHeaders as the map it is and writes the bearer token out in full. -func TestJsonLogRedactsTheToken(t *testing.T) { - var written bytes.Buffer - previous := slog.Default() - slog.SetDefault(slog.New(slog.NewJSONHandler(&written, &slog.HandlerOptions{Level: slog.LevelDebug}))) - t.Cleanup(func() { slog.SetDefault(previous) }) - - client := newTestClientWithServer(t, func(resp gohttp.ResponseWriter, _ *gohttp.Request) { - resp.WriteHeader(gohttp.StatusOK) - _, _ = resp.Write([]byte(`{"answer":"served"}`)) +func TestLoggedBody(t *testing.T) { + render := func(body string) string { + head := []byte(body) + return loggedBody{head: head[:min(len(head), loggedBodyLimit+1)]}.String() + } + + assert.Equal(t, "Bad Gateway", render("Bad Gateway")) + assert.Equal(t, "", render(strings.Repeat("\x00\xff", 1500))) + assert.Equal(t, "", render("")) + assert.True(t, strings.HasSuffix(render(strings.Repeat("ä", loggedBodyLimit)), "[TRUNCATED]"), + "a rune the cap cut in half does not make the text binary") + assert.Equal(t, "partial\n", + loggedBody{head: []byte("partial"), err: errors.New("connection lost")}.String()) +} + +func TestLoggedRequest(t *testing.T) { + var answer struct { + status int + body string + } + server := newTestServer(t, func(w gohttp.ResponseWriter, _ *gohttp.Request) { + w.Header()["Date"] = nil + w.WriteHeader(answer.status) + _, _ = io.WriteString(w, answer.body) }) const secret = "supersecret" - _, err := client.WithAuthorization(http.BearerToken(secret)).DoRequest[map[string]string](t.Context(), http.MethodPost, client.ServerUrl, - http.WithJsonPayload(map[string]string{"asked": "for"}, "application/json")) - require.NoError(t, err) - - logged := written.String() - assert.NotContains(t, logged, secret) - assert.Contains(t, logged, "[REDACTED]") - assert.Contains(t, logged, `asked`, "the request body") - assert.Contains(t, logged, `served`, "the response body") + client := NewClient(testUserAgent).WithAuthorization(BearerToken(secret)) + + t.Run("both bodies are logged, and the bearer token is not", func(t *testing.T) { + captured := logs.Capture(t) + answer.status, answer.body = gohttp.StatusOK, `{"name":"answered"}` + + _, err := UnmarshalJsonBody[map[string]string](client.DoRequest(t.Context(), MethodPost, server.Url, + WithJsonRequest(map[string]string{"name": "asked"}, ""))) + + require.NoError(t, err) + assert.Equal(t, []string{ + fmt.Sprintf(`level=DEBUG msg=request url=%s method=POST headers="Accept=application/json\nAuthorization=[REDACTED]\nContent-Type=application/json\nUser-Agent=meshstack-cli/test"`, server.Url), + `level=DEBUG msg="request body" body="{\"name\":\"asked\"}"`, + `level=DEBUG msg=response status=200 headers="Content-Length=19\nContent-Type=text/plain; charset=utf-8"`, + `level=DEBUG msg="response body" body="{\"name\":\"answered\"}"`, + }, captured.Lines(slog.LevelDebug)) + }) + + t.Run("a long body is logged truncated", func(t *testing.T) { + captured := logs.Capture(t) + answer.status, answer.body = gohttp.StatusNotFound, strings.Repeat("x", 2*loggedBodyLimit) + + _ = IgnoreResponse(client.DoRequest(t.Context(), MethodGet, server.Url)) + + assert.Contains(t, captured.String(), answer.body[:loggedBodyLimit]+" [TRUNCATED]") + }) + + // The Terraform provider's sink encodes attributes as JSON. + t.Run("a JSON handler gets the redacted text", func(t *testing.T) { + var written bytes.Buffer + previous := slog.Default() + slog.SetDefault(slog.New(slog.NewJSONHandler(&written, &slog.HandlerOptions{Level: slog.LevelDebug}))) + t.Cleanup(func() { slog.SetDefault(previous) }) + answer.status, answer.body = gohttp.StatusOK, `{"answer":"served"}` + + _, err := UnmarshalJsonBody[map[string]string](client.DoRequest(t.Context(), MethodPost, server.Url, + WithJsonRequest(map[string]string{"asked": "for"}, ""))) + + require.NoError(t, err) + logged := written.String() + assert.NotContains(t, logged, secret) + assert.Contains(t, logged, "Authorization=[REDACTED]") + assert.Contains(t, logged, `\"asked\":\"for\"`, "the request body") + assert.Contains(t, logged, `\"answer\":\"served\"`, "the response body") + }) } diff --git a/client/http/method.go b/client/http/method.go index e98d85f2..d2c2fefd 100644 --- a/client/http/method.go +++ b/client/http/method.go @@ -8,5 +8,6 @@ const ( MethodGet = gohttp.MethodGet MethodPost = gohttp.MethodPost MethodPut = gohttp.MethodPut + MethodPatch = gohttp.MethodPatch MethodDelete = gohttp.MethodDelete ) diff --git a/client/http/options.go b/client/http/options.go index d53b09a3..e1a56563 100644 --- a/client/http/options.go +++ b/client/http/options.go @@ -1,13 +1,17 @@ package http import ( + "bytes" "context" "encoding/json/jsontext" "fmt" + "io" "maps" gohttp "net/http" "net/url" + "os" "reflect" + "time" "github.com/meshcloud/meshstack-cli/internal/json" ) @@ -16,33 +20,74 @@ type ( RequestOption func(opts *requestOptions) requestOptions struct { - retryable bool - requestPayload func() ([]byte, error) requestModifiers []requestModifier + retry retryOptions + noRedirects bool + setBody requestModifier + responseHeader *gohttp.Header } requestModifier func(req *gohttp.Request) error ) -// Retryable declares that replaying this request cannot do harm, which is the only way a method -// other than GET is ever retried. meshStack's /api/login is the case it exists for: it mints a -// token and invalidates nothing, so a replay after a gateway 503 costs one token. -// -// Never put it on an OIDC refresh grant: that grant rotates the refresh token, and keycloak ends -// the whole session when a rotated token is used twice. -func Retryable() RequestOption { +func newRequestOptions(options []RequestOption) requestOptions { + opts := requestOptions{ + retry: retryOptions{ + policy: func(method string) RetryOn { + if method == MethodGet || method == MethodDelete { + return RetryOnTransient + } + // The server did not act on a request it answered with one of these. + return RetryOnBusy | RetryOnLocked + }, + // Outlasts a meshStack backend restart, whose gateway can answer 503 for three minutes: + // 1+2+4+8+16+30*11 seconds is about six minutes. + maxRetries: 16, + backoff: exponentialBackoff{MinWait: 1 * time.Second, MaxWait: 30 * time.Second}, + }, + } + for _, option := range options { + option(&opts) + } + return opts +} + +type requestOptionsKey struct{} + +func (opts requestOptions) requestContext(ctx context.Context) context.Context { + return context.WithValue(ctx, requestOptionsKey{}, opts) +} + +func requestOptionsFrom(req *gohttp.Request) requestOptions { + if opts, ok := req.Context().Value(requestOptionsKey{}).(requestOptions); ok { + return opts + } + return newRequestOptions(nil) +} + +func appendRequestModifier(modifier requestModifier) RequestOption { return func(opts *requestOptions) { - opts.retryable = true + opts.requestModifiers = append(opts.requestModifiers, modifier) } } -// retryableKey marks a request its caller declared safe to replay. It travels in the request -// context rather than in a list on the client, because one client serves every caller and -// because gohttp.Client passes the context on to the request it issues for a redirect. -type retryableKey struct{} +func Retryable(retryOn RetryOn) RequestOption { + return func(opts *requestOptions) { + opts.retry.policy = func(string) RetryOn { + return retryOn + } + } +} -func isRetryable(ctx context.Context) bool { - retryable, _ := ctx.Value(retryableKey{}).(bool) - return retryable +func WithoutRedirects() RequestOption { + return func(opts *requestOptions) { + opts.noRedirects = true + } +} + +func WithCapturedResponseHeader(header *gohttp.Header) RequestOption { + return func(opts *requestOptions) { + opts.responseHeader = header + } } // WithUrlQuery sends each field of query as a query parameter named by its `json` tag. A struct @@ -67,36 +112,36 @@ func WithUrlQuery(query any) RequestOption { } func convertStructOrMapToUrlValues(structOrMap any) (url.Values, error) { - data, err := json.Marshal(structOrMap) + encoded, err := json.Marshal(structOrMap) if err != nil { return nil, fmt.Errorf("cannot marshal type %T: %w", structOrMap, err) } var converted map[string]jsontext.Value - if err := json.Unmarshal(data, &converted); err != nil { + if err := json.Unmarshal(encoded, &converted); err != nil { return nil, fmt.Errorf("cannot decode type %T into a flat map: %w", structOrMap, err) } skipZero := reflect.ValueOf(structOrMap).Kind() == reflect.Struct result := url.Values{} for key, value := range converted { values := []jsontext.Value{value} - if value.Kind() == '[' { - if err := json.Unmarshal(value, &values); err != nil { + if value.Kind() == jsontext.KindBeginArray { + if err := json.UnmarshalRead(bytes.NewReader(value), &values); err != nil { return nil, fmt.Errorf("cannot read %s of type %T as an array: %w", key, structOrMap, err) } } for _, value := range values { - if value.Kind() == 'n' { + if value.Kind() == jsontext.KindNull { continue } // A number goes in as the literal it marshalled to, never through a Go value: decoded into // float64 and printed again, a millisecond timestamp would arrive as 1.2345678901234568e+18. param := value.String() - if value.Kind() == '"' { - if err := json.Unmarshal(value, ¶m); err != nil { + if value.Kind() == jsontext.KindString { + if err := json.UnmarshalRead(bytes.NewReader(value), ¶m); err != nil { return nil, fmt.Errorf("cannot read %s of type %T as a string: %w", key, structOrMap, err) } } - if skipZero && (param == "" || value.Kind() == 'f') { + if skipZero && (param == "" || value.Kind() == jsontext.KindFalse) { continue } result[key] = append(result[key], param) @@ -105,78 +150,106 @@ func convertStructOrMapToUrlValues(structOrMap any) (url.Values, error) { return result, nil } -func appendRequestModifier(modifier requestModifier) RequestOption { - return func(opts *requestOptions) { - opts.requestModifiers = append(opts.requestModifiers, modifier) - } -} - -func WithAccept(accept string) RequestOption { - return withHeader("Accept", accept) -} - -func WithHeaders(header gohttp.Header) RequestOption { +func WithHeader(key string, values ...string) RequestOption { return appendRequestModifier(func(req *gohttp.Request) error { - for key, values := range header { - req.Header.Del(key) - for _, value := range values { - req.Header.Add(key, value) - } + req.Header.Del(key) + for _, value := range values { + req.Header.Add(key, value) } return nil }) } -// WithBody sends the bytes as they are, so the caller names their type in a Content-Type header. -func WithBody(body []byte) RequestOption { +func WithContentType(contentType string) RequestOption { + return WithHeader("Content-Type", contentType) +} + +func WithFileRequest(path, contentType string) RequestOption { return func(opts *requestOptions) { - if body == nil { - return + if contentType == "" { + contentType = "application/octet-stream" } - opts.requestPayload = func() ([]byte, error) { - return body, nil + WithContentType(contentType)(opts) + opts.setBody = func(req *gohttp.Request) error { + info, err := os.Stat(path) + if err != nil { + return err + } + return setBody(req, info.Size(), func() (io.ReadCloser, error) { + return os.Open(path) //nolint:gosec // the caller names the file it uploads + }) } } } -func withHeader(key, value string) RequestOption { - return appendRequestModifier(func(req *gohttp.Request) error { - req.Header.Set(key, value) - return nil - }) -} +// wireCompatibility keeps the body encoding/json v1 produced: the meshObject API may read null and +// an empty collection differently on a PUT, and the Terraform provider hashes this JSON. +var wireCompatibility = json.JoinOptions( + json.Deterministic(true), + json.FormatNilSliceAsNull(true), + json.FormatNilMapAsNull(true), +) -// WithJsonPayload sends a value as a JSON body, and both sends and asks for the given content -// type. The type is a parameter because meshStack names a meshObject's kind and version in it. -func WithJsonPayload(payload any, contentType string) RequestOption { +func WithJsonRequest(payload any, contentType string) RequestOption { return func(opts *requestOptions) { - if payload == nil { - return + if contentType == "" { + contentType = "application/json" } - WithAccept(contentType)(opts) - withHeader("Content-Type", contentType)(opts) - opts.requestPayload = func() ([]byte, error) { - return json.Marshal(payload) + + WithHeader("Accept", contentType)(opts) + WithContentType(contentType)(opts) + WithJsonBody(payload)(opts) + } +} + +func WithJsonBody(payload any) RequestOption { + return func(opts *requestOptions) { + if payload != nil { + opts.setBody = setBytesBody(func() ([]byte, error) { + return json.Marshal(payload, wireCompatibility) + }) } } } -// WithFormPayload sends the values as an url-encoded form body — converted from a struct or a +// WithFormRequest sends the values as an url-encoded form body — converted from a struct or a // map as [WithUrlQuery] describes — and asks for JSON in return, which is what an OIDC grant // expects. -func WithFormPayload(payload any) RequestOption { +func WithFormRequest(payload any) RequestOption { return func(opts *requestOptions) { if payload == nil { return } - WithAccept("application/json")(opts) - withHeader("Content-Type", "application/x-www-form-urlencoded")(opts) - opts.requestPayload = func() ([]byte, error) { + WithHeader("Accept", "application/json")(opts) + WithContentType("application/x-www-form-urlencoded")(opts) + opts.setBody = setBytesBody(func() ([]byte, error) { values, err := convertStructOrMapToUrlValues(payload) if err != nil { return nil, fmt.Errorf("cannot convert form payload: %w", err) } return []byte(values.Encode()), nil + }) + } +} + +func setBytesBody(build func() ([]byte, error)) requestModifier { + return func(req *gohttp.Request) error { + body, err := build() + if err != nil { + return err } + return setBody(req, int64(len(body)), func() (io.ReadCloser, error) { + return io.NopCloser(bytes.NewReader(body)), nil + }) + } +} + +func setBody(req *gohttp.Request, length int64, open func() (io.ReadCloser, error)) (err error) { + if length == 0 { + // A ContentLength of 0 with a body would mean an unknown length, sent chunked. + open = func() (io.ReadCloser, error) { return gohttp.NoBody, nil } } + req.ContentLength, req.GetBody = length, open + req.Body, err = open() + return err } diff --git a/client/http/retry.go b/client/http/retry.go index 8befe34f..202efa77 100644 --- a/client/http/retry.go +++ b/client/http/retry.go @@ -8,69 +8,62 @@ import ( "io" "log/slog" "math" + "net" gohttp "net/http" "strconv" "syscall" "time" ) -type RetryOptions struct { - MaxRetries int - Backoff RetryBackoff +type RetryOn uint8 + +const ( + RetryOnBusy RetryOn = 1 << iota + // RetryOnGatewayError covers 502 and 504, after which the server may have acted on the request. + RetryOnGatewayError + RetryOnBrokenConnection + RetryOnLocked + + RetryOnTransient = RetryOnBusy | RetryOnGatewayError | RetryOnBrokenConnection | RetryOnLocked +) + +type retryOptions struct { + policy func(method string) RetryOn + maxRetries int + backoff retryBackoff } -// ApplyTo makes the given client retry a GET on its own, and any other method only where the -// caller marked the request with [Retryable]. -func (options RetryOptions) ApplyTo(c *gohttp.Client) { - next := gohttp.DefaultTransport - if c.Transport != nil { - next = c.Transport +func (on RetryOn) backoff(resp *gohttp.Response, err error, backoff retryBackoff) retryBackoff { + isBrokenConnection := func(err error) bool { + return errors.Is(err, syscall.ECONNRESET) || errors.Is(err, syscall.EPIPE) || + errors.Is(err, io.EOF) || errors.Is(err, io.ErrUnexpectedEOF) || errors.Is(err, net.ErrClosed) } - c.Transport = &retryRoundTripper{ - Next: next, - MaxRetries: options.MaxRetries, - ShouldRetryRequest: func(req *gohttp.Request) bool { - if options.Backoff == nil { - return false - } - return req.Method == MethodGet || isRetryable(req.Context()) - }, - ShouldRetryResponse: func(resp *gohttp.Response, err error) RetryBackoff { - if err != nil { - // Only a connection that broke once it was up clears on a retry, as one an ingress drops - // during a rolling deploy does. An unknown host, a refused connection or a TLS error - // repeats on every attempt, and a timeout would multiply by the retries. - if isBrokenConnection(err) { - return options.Backoff - } - return nil - } - switch resp.StatusCode { - case gohttp.StatusTooManyRequests, gohttp.StatusServiceUnavailable: - return retryAfterBackoff{Response: resp, Fallback: options.Backoff} - case gohttp.StatusBadGateway, gohttp.StatusGatewayTimeout: - return options.Backoff - default: - return nil - } - }, + switch { + case err != nil: + if on&RetryOnBrokenConnection != 0 && isBrokenConnection(err) { + return backoff + } + return nil + case on&RetryOnGatewayError != 0 && (resp.StatusCode == gohttp.StatusBadGateway || resp.StatusCode == gohttp.StatusGatewayTimeout): + return backoff + case on&RetryOnBusy != 0 && (resp.StatusCode == gohttp.StatusTooManyRequests || resp.StatusCode == gohttp.StatusServiceUnavailable): + return retryAfterBackoff{Response: resp, Fallback: backoff} + case on&RetryOnLocked != 0 && resp.StatusCode == gohttp.StatusLocked: + return backoff + default: + return nil } } -func isBrokenConnection(err error) bool { - return errors.Is(err, syscall.ECONNRESET) || errors.Is(err, syscall.EPIPE) || - errors.Is(err, io.EOF) || errors.Is(err, io.ErrUnexpectedEOF) -} - -type RetryBackoff interface { +type retryBackoff interface { Calculate(attempt int) time.Duration } -type ExponentialBackoff struct { +type exponentialBackoff struct { MinWait, MaxWait time.Duration } -func (b ExponentialBackoff) Calculate(attempt int) time.Duration { +func (b exponentialBackoff) Calculate(attempt int) time.Duration { nextWait := time.Duration(math.Pow(2, float64(attempt-1))) * b.MinWait if b.MaxWait > 0 && nextWait > b.MaxWait { return b.MaxWait @@ -82,7 +75,7 @@ var timeNow = time.Now type retryAfterBackoff struct { Response *gohttp.Response - Fallback RetryBackoff + Fallback retryBackoff } func (b retryAfterBackoff) Calculate(attempt int) (waitTime time.Duration) { @@ -112,27 +105,27 @@ func (b retryAfterBackoff) Calculate(attempt int) (waitTime time.Duration) { } type retryRoundTripper struct { - Next gohttp.RoundTripper - MaxRetries int - ShouldRetryRequest func(req *gohttp.Request) bool - ShouldRetryResponse func(resp *gohttp.Response, err error) RetryBackoff + next gohttp.RoundTripper } -func (r *retryRoundTripper) RoundTrip(req *gohttp.Request) (*gohttp.Response, error) { - if !r.ShouldRetryRequest(req) { - return r.Next.RoundTrip(req) +func (r retryRoundTripper) RoundTrip(req *gohttp.Request) (*gohttp.Response, error) { + retryOpts := requestOptionsFrom(req).retry + on := retryOpts.policy(req.Method) + if on == 0 { + return r.next.RoundTrip(req) } req = makeRequestBodyRetryable(req) for attempt := 1; ; attempt++ { - resp, err := r.Next.RoundTrip(req) + resp, err := r.next.RoundTrip(req) // A request the context ended is not retried. The context is checked rather than the error, // since the transport returns the context's cause, which for Ctrl-C is a signal error that // wraps no context.Canceled. if errors.Is(err, errRetryableBodyClose) || err != nil && req.Context().Err() != nil { return resp, err } - backoff := r.ShouldRetryResponse(resp, err) - if backoff == nil || attempt > r.MaxRetries { + + backoff := on.backoff(resp, err, retryOpts.backoff) + if backoff == nil || attempt > retryOpts.maxRetries { return resp, err } drainAndCloseResponseBody(req.Context(), resp) @@ -153,7 +146,7 @@ func (r *retryRoundTripper) RoundTrip(req *gohttp.Request) (*gohttp.Response, er }(), "method", req.Method, "path", req.URL.Path, - "attempt", fmt.Sprintf("%d/%d", attempt, r.MaxRetries), + "attempt", fmt.Sprintf("%d/%d", attempt, retryOpts.maxRetries), "waitTime", waitTime, )...) timer := time.NewTimer(waitTime) @@ -170,11 +163,10 @@ func makeRequestBodyRetryable(req *gohttp.Request) *gohttp.Request { if req.Body == nil { return req } - // gohttp.NewRequestWithContext sets GetBody for a *bytes.Buffer, *bytes.Reader or - // *strings.Reader body. if req.GetBody != nil { return req } + body := retryableBody{Closer: req.Body} body.Reader = io.TeeReader(req.Body, &body.Buffer) result := req.Clone(req.Context()) @@ -215,13 +207,11 @@ func (w *appendWriter) Write(p []byte) (int, error) { return len(p), nil } -// drainAndCloseResponseBody drains the body so that gohttp.Transport can reuse the connection. -// It reads at most maxBytes, so that a large or slow body cannot block the retry; the connection -// of such a body is then not reused. +const maxDrainBytes = 16 * 1024 + func drainAndCloseResponseBody(ctx context.Context, resp *gohttp.Response) { - const maxBytes = 16 * 1024 if resp != nil && resp.Body != nil { - drainedBytes, err := io.CopyN(io.Discard, resp.Body, maxBytes) + drainedBytes, err := io.CopyN(io.Discard, resp.Body, maxDrainBytes) if err != nil && !errors.Is(err, io.EOF) { slog.DebugContext(ctx, "failed to drain response body: "+err.Error()) } diff --git a/client/http/retry_test.go b/client/http/retry_test.go index fa172761..6e195a1e 100644 --- a/client/http/retry_test.go +++ b/client/http/retry_test.go @@ -1,20 +1,13 @@ package http import ( - "context" - "errors" "fmt" - "net" gohttp "net/http" - "net/http/httptest" - "sync/atomic" - "syscall" "testing" "testing/synctest" "time" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestExponentialBackoff_Calculate(t *testing.T) { @@ -30,7 +23,7 @@ func TestExponentialBackoff_Calculate(t *testing.T) { } for _, tt := range tests { t.Run(fmt.Sprintf("attempt %d", tt.attempt), func(t *testing.T) { - b := ExponentialBackoff{ + b := exponentialBackoff{ MinWait: 1 * time.Second, MaxWait: 5 * time.Second, } @@ -41,7 +34,7 @@ func TestExponentialBackoff_Calculate(t *testing.T) { func TestRetryAfterBackoff(t *testing.T) { bubbleStart := time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC) - fallback := ExponentialBackoff{MinWait: 1 * time.Second, MaxWait: 10 * time.Second} + fallback := exponentialBackoff{MinWait: 1 * time.Second, MaxWait: 10 * time.Second} tests := []struct { name string @@ -68,96 +61,3 @@ func TestRetryAfterBackoff(t *testing.T) { }) } } - -type roundTripperFunc func(*gohttp.Request) (*gohttp.Response, error) - -func (f roundTripperFunc) RoundTrip(req *gohttp.Request) (*gohttp.Response, error) { - return f(req) -} - -func TestRetryStopsOnceTheContextIsDone(t *testing.T) { - interrupted := errors.New("interrupt signal received") - ctx, cancel := context.WithCancelCause(t.Context()) - cancel(interrupted) - req, err := gohttp.NewRequestWithContext(ctx, MethodGet, "http://meshstack.invalid", nil) - require.NoError(t, err) - - calls := 0 - retrying := &retryRoundTripper{ - Next: roundTripperFunc(func(req *gohttp.Request) (*gohttp.Response, error) { - calls++ - return nil, context.Cause(req.Context()) - }), - MaxRetries: 3, - ShouldRetryRequest: func(*gohttp.Request) bool { return true }, - ShouldRetryResponse: func(*gohttp.Response, error) RetryBackoff { return ExponentialBackoff{} }, - } - - _, err = retrying.RoundTrip(req) //nolint:bodyclose // no response comes back - require.ErrorIs(t, err, interrupted) - assert.Equal(t, 1, calls) -} - -func TestRetryGivesUpOnAServerThatDoesNotAnswer(t *testing.T) { - var calls atomic.Int32 - server := httptest.NewServer(gohttp.HandlerFunc(func(_ gohttp.ResponseWriter, r *gohttp.Request) { - calls.Add(1) - <-r.Context().Done() - })) - defer server.Close() - client := &gohttp.Client{Transport: newTransport(10 * time.Millisecond)} - RetryOptions{MaxRetries: 3, Backoff: ExponentialBackoff{}}.ApplyTo(client) - - _, err := client.Get(server.URL) //nolint:bodyclose,noctx // no response comes back - - require.ErrorContains(t, err, "timeout awaiting response headers") - assert.Equal(t, int32(1), calls.Load()) -} - -func TestRetryGivesUpOnARefusedConnection(t *testing.T) { - server := httptest.NewServer(gohttp.NotFoundHandler()) - server.Close() - var calls atomic.Int32 - client := &gohttp.Client{Transport: roundTripperFunc(func(req *gohttp.Request) (*gohttp.Response, error) { - calls.Add(1) - return gohttp.DefaultTransport.RoundTrip(req) - })} - RetryOptions{MaxRetries: 3, Backoff: ExponentialBackoff{}}.ApplyTo(client) - - _, err := client.Get(server.URL) //nolint:bodyclose,noctx // no response comes back - - require.ErrorIs(t, err, syscall.ECONNREFUSED) - assert.Equal(t, int32(1), calls.Load()) -} - -func TestRetryRecoversFromABrokenConnection(t *testing.T) { - for name, breakConnection := range map[string]func(*net.TCPConn){ - "closed": func(*net.TCPConn) {}, - "reset": func(conn *net.TCPConn) { _ = conn.SetLinger(0) }, - } { - t.Run(name, func(t *testing.T) { - var calls atomic.Int32 - server := httptest.NewServer(gohttp.HandlerFunc(func(w gohttp.ResponseWriter, _ *gohttp.Request) { - if calls.Add(1) > 1 { - return - } - conn, _, err := gohttp.NewResponseController(w).Hijack() - if !assert.NoError(t, err) { - return - } - breakConnection(conn.(*net.TCPConn)) //nolint:forcetypeassert // httptest serves plain TCP - _ = conn.Close() - })) - defer server.Close() - client := &gohttp.Client{Transport: newTransport(time.Minute)} - RetryOptions{MaxRetries: 3, Backoff: ExponentialBackoff{}}.ApplyTo(client) - - resp, err := client.Get(server.URL) //nolint:noctx // the test server answers at once - - require.NoError(t, err) - _ = resp.Body.Close() - assert.Equal(t, gohttp.StatusOK, resp.StatusCode) - assert.Equal(t, int32(2), calls.Load()) - }) - } -} diff --git a/client/http/stall.go b/client/http/stall.go index d0108034..a6f06dd8 100644 --- a/client/http/stall.go +++ b/client/http/stall.go @@ -4,42 +4,31 @@ import ( "context" "fmt" "io" - gohttp "net/http" "time" ) -// stallGuard ends a request whose response body has sent nothing for Timeout. It bounds the -// silence rather than the whole body, so a long answer that is still arriving is read to the end. -type stallGuard struct { - Next gohttp.RoundTripper - Timeout time.Duration -} - -func (g stallGuard) RoundTrip(req *gohttp.Request) (*gohttp.Response, error) { - ctx, cancel := context.WithCancelCause(req.Context()) - resp, err := g.Next.RoundTrip(req.WithContext(ctx)) - if err != nil { - cancel(nil) - return resp, err - } - stalled := fmt.Errorf("response body stalled: nothing received for %s", g.Timeout) - body := &stallGuardedBody{ReadCloser: resp.Body, timeout: g.Timeout, cancel: cancel} - body.timer = time.AfterFunc(g.Timeout, func() { cancel(stalled) }) - resp.Body = body - return resp, nil -} +var stallTimeout = 1 * time.Minute +// stallGuardedBody bounds the silence of a body, so a long answer that is still arriving is read to the end. type stallGuardedBody struct { io.ReadCloser - timeout time.Duration - timer *time.Timer - cancel context.CancelCauseFunc + timer *time.Timer + cancel context.CancelCauseFunc +} + +func newStallGuardedBody(body io.ReadCloser, cancel context.CancelCauseFunc) io.ReadCloser { + stalled := fmt.Errorf("response body stalled: nothing received for %s", stallTimeout) + return &stallGuardedBody{ + ReadCloser: body, + timer: time.AfterFunc(stallTimeout, func() { cancel(stalled) }), + cancel: cancel, + } } func (b *stallGuardedBody) Read(p []byte) (int, error) { n, err := b.ReadCloser.Read(p) - b.timer.Reset(b.timeout) + b.timer.Reset(stallTimeout) return n, err } diff --git a/client/http/stall_test.go b/client/http/stall_test.go deleted file mode 100644 index dd379d87..00000000 --- a/client/http/stall_test.go +++ /dev/null @@ -1,81 +0,0 @@ -package http - -import ( - "bufio" - "context" - "fmt" - "io" - "net" - gohttp "net/http" - "testing" - "testing/synctest" - "time" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestStallGuardEndsABodyThatStopsArriving(t *testing.T) { - synctest.Test(t, func(t *testing.T) { - client := newPipeClient(t, time.Minute, 100, func(w io.Writer) { - _, _ = io.WriteString(w, "partial") - }) - - resp, err := client.Get("http://meshstack.invalid") //nolint:noctx // the stall guard is what ends it - require.NoError(t, err) - defer func() { - _ = resp.Body.Close() - }() - start := time.Now() - body, err := io.ReadAll(resp.Body) - - require.ErrorContains(t, err, "response body stalled: nothing received for 1m0s") - assert.Equal(t, "partial", string(body)) - assert.Equal(t, time.Minute, time.Since(start), "the body was ended as soon as it had been silent for the timeout") - }) -} - -func TestStallGuardReadsABodyThatKeepsArriving(t *testing.T) { - synctest.Test(t, func(t *testing.T) { - client := newPipeClient(t, time.Minute, 5, func(w io.Writer) { - for range 5 { - synctest.Sleep(40 * time.Second) - _, _ = io.WriteString(w, ".") - } - }) - - resp, err := client.Get("http://meshstack.invalid") //nolint:noctx // the server answers in full - require.NoError(t, err) - defer func() { - _ = resp.Body.Close() - }() - start := time.Now() - body, err := io.ReadAll(resp.Body) - - require.NoError(t, err) - assert.Equal(t, ".....", string(body)) - assert.Greater(t, time.Since(start), time.Minute, "the body took longer than the timeout, but was never silent for as long") - }) -} - -// newPipeClient serves its one connection in memory. A socket would keep the bubble's clock from -// advancing, since the clock only moves while every goroutine waits on something inside the bubble. -func newPipeClient(t *testing.T, timeout time.Duration, contentLength int, writeBody func(io.Writer)) *gohttp.Client { - t.Helper() - clientConn, serverConn := net.Pipe() - go func() { - defer func() { - _ = serverConn.Close() - }() - if _, err := gohttp.ReadRequest(bufio.NewReader(serverConn)); !assert.NoError(t, err) { - return - } - _, _ = fmt.Fprintf(serverConn, "HTTP/1.1 200 OK\r\nContent-Length: %d\r\nConnection: close\r\n\r\n", contentLength) - writeBody(serverConn) - _, _ = io.Copy(io.Discard, serverConn) - }() - transport := &gohttp.Transport{DialContext: func(context.Context, string, string) (net.Conn, error) { - return clientConn, nil - }} - return &gohttp.Client{Transport: stallGuard{Next: transport, Timeout: timeout}} -} diff --git a/client/http/user_agent.go b/client/http/user_agent.go index 1c00bb86..ba700199 100644 --- a/client/http/user_agent.go +++ b/client/http/user_agent.go @@ -13,7 +13,12 @@ type UserAgent struct { Version string } -func (u UserAgent) Validate() error { +func (u UserAgent) String() string { + _, repo, _ := strings.Cut(u.GitHubRepo, "/") + return repo + "/" + u.Version +} + +func (u UserAgent) validate() error { org, repo, ok := strings.Cut(u.GitHubRepo, "/") if !ok || org == "" || repo == "" { return fmt.Errorf("GitHub repo '%s' is not of / format", u.GitHubRepo) @@ -23,8 +28,3 @@ func (u UserAgent) Validate() error { } return nil } - -func (u UserAgent) String() string { - _, repo, _ := strings.Cut(u.GitHubRepo, "/") - return repo + "/" + u.Version -} diff --git a/client/integration_config.go b/client/integration_config.go index 5b63eb4e..16120199 100644 --- a/client/integration_config.go +++ b/client/integration_config.go @@ -2,12 +2,12 @@ package client import ( "encoding/json/jsontext" - "encoding/json/v2" "fmt" "github.com/meshcloud/meshstack-cli/client/types" "github.com/meshcloud/meshstack-cli/client/types/enum" "github.com/meshcloud/meshstack-cli/client/types/variant" + "github.com/meshcloud/meshstack-cli/internal/json" ) type MeshIntegrationConfigType string diff --git a/client/internal/mesh_object.go b/client/internal/mesh_object.go index 8f3cbe40..1991ecb8 100644 --- a/client/internal/mesh_object.go +++ b/client/internal/mesh_object.go @@ -90,7 +90,7 @@ func (c MeshObjectClient[M]) Get(ctx context.Context, id string) (resp *M, err e } func (c MeshObjectApi) GetAtPath[R any](ctx context.Context, id string, extraPath ...string) (R, error) { - return c.DoRequest[R](ctx, http.MethodGet, c.ApiUrl.JoinPath(id).JoinPath(extraPath...), http.WithAccept(c.MeshObjectMimeType())) + return http.UnmarshalJsonBody[R](c.DoRequest(ctx, http.MethodGet, c.ApiUrl.JoinPath(id).JoinPath(extraPath...), http.WithHeader("Accept", c.MeshObjectMimeType()))) } func (c MeshObjectClient[M]) Post[P any](ctx context.Context, payload P) (*M, error) { @@ -98,12 +98,11 @@ func (c MeshObjectClient[M]) Post[P any](ctx context.Context, payload P) (*M, er } func (c MeshObjectApi) PostAtPath[R, P any](ctx context.Context, payload P, extraPath ...string) (R, error) { - return c.DoRequest[R](ctx, http.MethodPost, c.ApiUrl.JoinPath(extraPath...), - http.WithAccept(c.MeshObjectMimeType()), c.withMeshObjectPayload(payload)) + return http.UnmarshalJsonBody[R](c.DoRequest(ctx, http.MethodPost, c.ApiUrl.JoinPath(extraPath...), c.withMeshObjectPayload(payload))) } func (c MeshObjectClient[M]) Put[P any](ctx context.Context, id string, payload P) (*M, error) { - return c.DoRequest[*M](ctx, http.MethodPut, c.ApiUrl.JoinPath(id), c.withMeshObjectPayload(payload), http.Retryable()) + return http.UnmarshalJsonBody[*M](c.DoRequest(ctx, http.MethodPut, c.ApiUrl.JoinPath(id), c.withMeshObjectPayload(payload), http.Retryable(http.RetryOnTransient))) } func (c MeshObjectClient[M]) Delete(ctx context.Context, id string) (err error) { @@ -111,8 +110,7 @@ func (c MeshObjectClient[M]) Delete(ctx context.Context, id string) (err error) } func (c MeshObjectApi) DeleteAtPath(ctx context.Context, id string, extraPath ...string) (err error) { - _, err = c.DoRequest[any](ctx, http.MethodDelete, c.ApiUrl.JoinPath(id).JoinPath(extraPath...), http.Retryable(), http.WithAccept(c.MeshObjectMimeType())) - return + return http.IgnoreResponse(c.DoRequest(ctx, http.MethodDelete, c.ApiUrl.JoinPath(id).JoinPath(extraPath...), http.WithHeader("Accept", c.MeshObjectMimeType()))) } func (c MeshObjectClient[M]) ListSeq(ctx context.Context, options ...http.RequestOption) iter.Seq2[M, error] { @@ -165,7 +163,7 @@ type paginatedResponse[T any] struct { // withMeshObjectPayload takes P rather than an any because the `,embed` tag takes a struct, a // string-keyed map or a jsontext.Value, never an any. func (c MeshObjectApi) withMeshObjectPayload[P any](payload P) http.RequestOption { - return http.WithJsonPayload(struct { + return http.WithJsonRequest(struct { ApiVersion string `json:"apiVersion"` Kind string `json:"kind"` Payload P `json:",embed"` @@ -177,10 +175,10 @@ func (c MeshObjectApi) getPage[T any](ctx context.Context, listOptions ListOptio if listOptions.PageSize > 0 { query["size"] = listOptions.PageSize } - response, err := c.DoRequest[paginatedResponse[T]](ctx, http.MethodGet, c.ApiUrl, append(options, - http.WithAccept(c.MeshObjectMimeType()), + response, err := http.UnmarshalJsonBody[paginatedResponse[T]](c.DoRequest(ctx, http.MethodGet, c.ApiUrl, append(options, + http.WithHeader("Accept", c.MeshObjectMimeType()), http.WithUrlQuery(query), - )...) + )...)) if err != nil && pageNumber > 0 { // The first page fails for what fails the whole list, such as a missing role, and a page // number would only distract from it. diff --git a/client/mesh_info.go b/client/mesh_info.go index e2c123e4..8c0846cb 100644 --- a/client/mesh_info.go +++ b/client/mesh_info.go @@ -45,7 +45,7 @@ func NewMeshInfoClient(client http.Client, endpoint xurl.URL) MeshInfoClient { } func (c meshInfoClient) Read(ctx context.Context) (MeshInfo, error) { - return c.DoRequest[MeshInfo](ctx, "GET", c.Endpoint.JoinPath("/mesh/info"), http.WithAccept("application/json")) + return http.UnmarshalJsonBody[MeshInfo](c.DoRequest(ctx, http.MethodGet, c.Endpoint.JoinPath("/mesh/info"), http.WithHeader("Accept", "application/json"))) } func (info MeshInfo) CheckVersion() error { diff --git a/client/openapi/doc.go b/client/openapi/doc.go index a610df5f..d693587e 100644 --- a/client/openapi/doc.go +++ b/client/openapi/doc.go @@ -3,10 +3,11 @@ package openapi import ( "cmp" "encoding/json/jsontext" - "encoding/json/v2" "fmt" "slices" "strings" + + "github.com/meshcloud/meshstack-cli/internal/json" ) // OperationDoc is what the API docs say about an operation, for a person to read. diff --git a/client/openapi/media_type.go b/client/openapi/media_type.go index 6845798b..282bb966 100644 --- a/client/openapi/media_type.go +++ b/client/openapi/media_type.go @@ -4,12 +4,13 @@ import ( "bytes" "cmp" "encoding/json/jsontext" - "encoding/json/v2" "fmt" "regexp" "slices" "strconv" "strings" + + "github.com/meshcloud/meshstack-cli/internal/json" ) // Only a hal+json type carries a meshObject: application/vnd.meshcloud.api.meshobjects.v1+json is diff --git a/client/openapi/spec.go b/client/openapi/spec.go index bb1bcd1c..34ac5012 100644 --- a/client/openapi/spec.go +++ b/client/openapi/spec.go @@ -4,13 +4,14 @@ package openapi import ( "encoding/json/jsontext" - "encoding/json/v2" "fmt" "io" "maps" "regexp" "slices" "strings" + + "github.com/meshcloud/meshstack-cli/internal/json" ) // Spec is an OpenAPI document. After Select, it marshals to the selected operations and the diff --git a/client/openapi/spec_test.go b/client/openapi/spec_test.go index 9203a66f..c4af9cb4 100644 --- a/client/openapi/spec_test.go +++ b/client/openapi/spec_test.go @@ -3,7 +3,6 @@ package openapi_test import ( "bytes" "encoding/json/jsontext" - "encoding/json/v2" "os" "testing" @@ -11,6 +10,7 @@ import ( "github.com/stretchr/testify/require" "github.com/meshcloud/meshstack-cli/client/openapi" + "github.com/meshcloud/meshstack-cli/internal/json" ) func TestSpec(t *testing.T) { diff --git a/client/raw.go b/client/raw.go index 665580b7..3931a6fe 100644 --- a/client/raw.go +++ b/client/raw.go @@ -62,15 +62,15 @@ func (r *RawClient) Get[M any](ctx context.Context, uuid uuid.UUID, pathElems .. if err != nil { return nil, err } - return api.DoRequest[jsontext.Value](ctx, http.MethodGet, api.ApiUrl.JoinPath(uuid.String()).JoinPath(pathElems...), - http.WithAccept(api.MeshObjectMimeType())) + return http.UnmarshalJsonBody[jsontext.Value](api.DoRequest(ctx, http.MethodGet, api.ApiUrl.JoinPath(uuid.String()).JoinPath(pathElems...), + http.WithHeader("Accept", api.MeshObjectMimeType()))) } // DoRequest joins path onto the endpoint, even one that names a host, so that the bearer token // never leaves for another host. The answer is of any content type, such as a plan artifact's // application/octet-stream, so it is returned unparsed. func (r *RawClient) DoRequest(ctx context.Context, method, path string, opts ...http.RequestOption) ([]byte, error) { - return r.httpClient.DoRequest[[]byte](ctx, method, r.httpClient.EndpointUrl.JoinPath(path), opts...) + return http.ReadAllBody(r.httpClient.DoRequest(ctx, method, r.httpClient.EndpointUrl.JoinPath(path), opts...)) } // with makes List and Get reach the objects of M through the API version of meshObject, so that diff --git a/client/types/variant/variant.go b/client/types/variant/variant.go index 127acb34..e138694a 100644 --- a/client/types/variant/variant.go +++ b/client/types/variant/variant.go @@ -2,10 +2,11 @@ package variant import ( "encoding/json/jsontext" - "encoding/json/v2" "errors" "fmt" "reflect" + + "github.com/meshcloud/meshstack-cli/internal/json" ) // A Variant decodes one JSON value into X or into Y. When both decode, X wins, so Y can be a type diff --git a/client/types/version/version_test.go b/client/types/version/version_test.go index 9ec81afc..0ec1952b 100644 --- a/client/types/version/version_test.go +++ b/client/types/version/version_test.go @@ -1,12 +1,13 @@ package version import ( - "encoding/json/v2" "fmt" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/meshcloud/meshstack-cli/internal/json" ) func TestParse(t *testing.T) { diff --git a/cmd/api/api.go b/cmd/api/api.go index 65bd3c63..569ca21e 100644 --- a/cmd/api/api.go +++ b/cmd/api/api.go @@ -72,8 +72,14 @@ To see what the API docs say about the request, run the same command line with ' r.header.Set("Content-Type", "application/json") } - answer, err := meshStack.Raw.DoRequest(ctx, r.method, r.target.Path, - http.WithUrlQuery(r.target.Query()), http.WithHeaders(r.header), http.WithBody(r.body)) + options := []http.RequestOption{http.WithUrlQuery(r.target.Query())} + if r.body != nil { + options = append(options, http.WithJsonRequest(r.body, r.header.Get("Content-Type")), http.WithHeader("Accept", r.header.Values("Accept")...)) + } + for key, values := range r.header { + options = append(options, http.WithHeader(key, values...)) + } + answer, err := meshStack.Raw.DoRequest(ctx, r.method, r.target.Path, options...) if httpErr, ok := errors.AsType[client.HttpError](err); ok { if writeErr := writeAnswer(cmd.OutOrStdout(), httpErr.ResponseBody); writeErr != nil { return writeErr @@ -83,7 +89,6 @@ To see what the API docs say about the request, run the same command line with ' return withHint(fmt.Sprintf("%s. Run %s to see what the API expects", httpErr.Summary(), docsCommand(cmd, args)), httpErr) } - // What wraps the HTTP error, such as the auth scope of a 403, stays. return withHint(strings.Replace(err.Error(), httpErr.Error(), httpErr.Summary(), 1), httpErr) } if err != nil { diff --git a/cmd/api/api_test.go b/cmd/api/api_test.go index e25bb28a..2962087d 100644 --- a/cmd/api/api_test.go +++ b/cmd/api/api_test.go @@ -130,7 +130,7 @@ func TestApi(t *testing.T) { for status, wantError := range map[int]string{ gohttp.StatusConflict: "meshStack answered HTTP 409: still in use. Run meshstack api-docs /api/x -H 'Accept: application/json' -X POST to see what the API expects", gohttp.StatusBadGateway: "meshStack answered HTTP 502: still in use", - gohttp.StatusForbidden: "auth scope endpoint " + meshStack.URL + ": meshStack answered HTTP 403: still in use", + gohttp.StatusForbidden: "auth manual for " + meshStack.URL + ": meshStack answered HTTP 403: still in use", } { meshStack.answer(status, `{"message":"still in use"}`) diff --git a/cmd/api/docs.go b/cmd/api/docs.go index 090497a8..227531b9 100644 --- a/cmd/api/docs.go +++ b/cmd/api/docs.go @@ -4,7 +4,6 @@ import ( "cmp" _ "embed" "encoding/json/jsontext" - "encoding/json/v2" "errors" "fmt" gohttp "net/http" @@ -17,6 +16,7 @@ import ( "github.com/meshcloud/meshstack-cli/client/types/xurl" "github.com/meshcloud/meshstack-cli/cmd/internal" "github.com/meshcloud/meshstack-cli/cmd/internal/markdown" + "github.com/meshcloud/meshstack-cli/internal/json" "github.com/meshcloud/meshstack-cli/internal/profile" "github.com/meshcloud/meshstack-cli/internal/setting" ) diff --git a/cmd/api/request.go b/cmd/api/request.go index 7b1e0ea6..79ab2c84 100644 --- a/cmd/api/request.go +++ b/cmd/api/request.go @@ -3,7 +3,6 @@ package api import ( "context" "encoding/json/jsontext" - "encoding/json/v2" "fmt" gohttp "net/http" "net/url" @@ -18,6 +17,7 @@ import ( "github.com/meshcloud/meshstack-cli/client/types/xurl" "github.com/meshcloud/meshstack-cli/cmd/internal" "github.com/meshcloud/meshstack-cli/internal/apidocs" + "github.com/meshcloud/meshstack-cli/internal/json" "github.com/meshcloud/meshstack-cli/internal/meshstack" "github.com/meshcloud/meshstack-cli/internal/setting" ) @@ -134,13 +134,9 @@ func (f *requestFlags) selector(r request) (openapi.Selector, error) { } func (f *requestFlags) loadApiDocs(cmd *cobra.Command, endpoint xurl.URL) (openapi.Spec, func(), error) { - httpClient, err := internal.ResolveClientOptions().HttpClient() - if err != nil { - return openapi.Spec{}, func() {}, err - } return apidocs.Load(cmd.Context(), apidocs.Options{ Sources: internal.SettingSources(), - Client: httpClient, + Client: internal.ResolveClientOptions().HttpClient(), Endpoint: endpoint, Version: internal.Version, Dev: f.dev, diff --git a/cmd/auth/status_test.go b/cmd/auth/status_test.go index 1c6887b5..e0a60b45 100644 --- a/cmd/auth/status_test.go +++ b/cmd/auth/status_test.go @@ -3,7 +3,6 @@ package auth import ( "bytes" "encoding/base64" - "encoding/json/v2" "fmt" "io" "testing" @@ -15,6 +14,7 @@ import ( "github.com/meshcloud/meshstack-cli/cmd/internal" "github.com/meshcloud/meshstack-cli/internal/auth" + "github.com/meshcloud/meshstack-cli/internal/json" "github.com/meshcloud/meshstack-cli/internal/testutil/fakemeshstack" "github.com/meshcloud/meshstack-cli/internal/testutil/testlogin" ) diff --git a/cmd/auth/token.go b/cmd/auth/token.go index 188bac61..055a6bda 100644 --- a/cmd/auth/token.go +++ b/cmd/auth/token.go @@ -26,7 +26,7 @@ Paste the token as the Bearer token in the API docs to try a request against you if err != nil { return err } - _, err = fmt.Fprintln(cmd.OutOrStdout(), token) + _, err = fmt.Fprintln(cmd.OutOrStdout(), string(token)) return err }, } diff --git a/cmd/buildingblock/approve_run_internal_test.go b/cmd/buildingblock/approve_run_internal_test.go index b4b9e60d..7f1e27fa 100644 --- a/cmd/buildingblock/approve_run_internal_test.go +++ b/cmd/buildingblock/approve_run_internal_test.go @@ -2,7 +2,6 @@ package buildingblock import ( "bytes" - "encoding/json/v2" "io" gohttp "net/http" "strings" @@ -14,6 +13,7 @@ import ( "github.com/meshcloud/meshstack-cli/cmd/internal" "github.com/meshcloud/meshstack-cli/cmd/internal/prompt" + "github.com/meshcloud/meshstack-cli/internal/json" "github.com/meshcloud/meshstack-cli/internal/testutil/fakemeshstack" "github.com/meshcloud/meshstack-cli/internal/testutil/testlogin" ) diff --git a/cmd/buildingblock/buildingblock.go b/cmd/buildingblock/buildingblock.go index 6e7ae905..eaebce90 100644 --- a/cmd/buildingblock/buildingblock.go +++ b/cmd/buildingblock/buildingblock.go @@ -3,7 +3,6 @@ package buildingblock import ( "context" "encoding/json/jsontext" - "encoding/json/v2" "fmt" "io" "log/slog" @@ -15,6 +14,7 @@ import ( "github.com/meshcloud/meshstack-cli/cmd/buildingblock/tfstate" "github.com/meshcloud/meshstack-cli/cmd/internal" "github.com/meshcloud/meshstack-cli/cmd/internal/prompt" + "github.com/meshcloud/meshstack-cli/internal/json" ) func New() *cobra.Command { diff --git a/cmd/buildingblock/tfstate/exec.go b/cmd/buildingblock/tfstate/exec.go index 9fd6f0c4..161c5527 100644 --- a/cmd/buildingblock/tfstate/exec.go +++ b/cmd/buildingblock/tfstate/exec.go @@ -111,10 +111,7 @@ With --%[8]s, exec copies the stored state into that directory before it replace if err != nil { return err } - api, err := internal.ResolveClientOptions().HttpClient() - if err != nil { - return err - } + api := internal.ResolveClientOptions().HttpClient() var problems []error proxy := &tfstate.Proxy{ Store: store, diff --git a/cmd/buildingblock/tfstate/tfstate_test.go b/cmd/buildingblock/tfstate/tfstate_test.go index 0857473c..20e98e98 100644 --- a/cmd/buildingblock/tfstate/tfstate_test.go +++ b/cmd/buildingblock/tfstate/tfstate_test.go @@ -3,6 +3,7 @@ package tfstate_test import ( "bytes" "context" + "encoding/json/jsontext" "errors" "fmt" "log/slog" @@ -75,7 +76,7 @@ func runChild(steps string) int { address, _ := url.Parse(os.Getenv("TF_HTTP_ADDRESS")) r := httptest.NewRequestWithContext(context.Background(), step, "/", nil) r.SetBasicAuth(os.Getenv("TF_HTTP_USERNAME"), os.Getenv("TF_HTTP_PASSWORD")) - _, _ = http.NewClient(fakemeshstack.UserAgent).DoRequest[[]byte](context.Background(), step, address, http.WithHeaders(r.Header), http.WithBody([]byte(state))) + _ = http.IgnoreResponse(http.NewClient(fakemeshstack.UserAgent).DoRequest(context.Background(), step, address, http.WithHeader("Authorization", r.Header.Get("Authorization")), http.WithJsonRequest(jsontext.Value(state), ""))) } return 0 } diff --git a/cmd/buildingblockrun/list.go b/cmd/buildingblockrun/list.go index bec8a1ea..95d62fd0 100644 --- a/cmd/buildingblockrun/list.go +++ b/cmd/buildingblockrun/list.go @@ -3,7 +3,6 @@ package buildingblockrun import ( "context" "encoding/json/jsontext" - "encoding/json/v2" "errors" "fmt" "iter" @@ -15,6 +14,7 @@ import ( "github.com/meshcloud/meshstack-cli/client" "github.com/meshcloud/meshstack-cli/cmd/internal" + "github.com/meshcloud/meshstack-cli/internal/json" ) const buildingBlockFlagName = "building-block" diff --git a/cmd/buildingblockrun/list_internal_test.go b/cmd/buildingblockrun/list_internal_test.go index 0e0c5768..e1b28c17 100644 --- a/cmd/buildingblockrun/list_internal_test.go +++ b/cmd/buildingblockrun/list_internal_test.go @@ -2,7 +2,6 @@ package buildingblockrun import ( "encoding/json/jsontext" - "encoding/json/v2" "errors" "fmt" "iter" @@ -10,6 +9,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/meshcloud/meshstack-cli/internal/json" ) // blockRuns yields a run named block/i, created at the i-th of createdAts, and counts into pulled the diff --git a/cmd/buildingblockrun/logs.go b/cmd/buildingblockrun/logs.go index c4b5c58c..dd9df62c 100644 --- a/cmd/buildingblockrun/logs.go +++ b/cmd/buildingblockrun/logs.go @@ -2,7 +2,6 @@ package buildingblockrun import ( "context" - "encoding/json/v2" "errors" "fmt" "io" @@ -15,6 +14,7 @@ import ( "github.com/meshcloud/meshstack-cli/client" "github.com/meshcloud/meshstack-cli/cmd/internal" + "github.com/meshcloud/meshstack-cli/internal/json" ) const followFlagName = "follow" diff --git a/cmd/internal/buildingblock/run_wait.go b/cmd/internal/buildingblock/run_wait.go index 57ec7780..5563db7e 100644 --- a/cmd/internal/buildingblock/run_wait.go +++ b/cmd/internal/buildingblock/run_wait.go @@ -5,12 +5,12 @@ package buildingblock import ( "context" "encoding/json/jsontext" - "encoding/json/v2" "fmt" "time" "uuid" "github.com/meshcloud/meshstack-cli/client" + "github.com/meshcloud/meshstack-cli/internal/json" ) const ( diff --git a/cmd/internal/output.go b/cmd/internal/output.go index 8394f53b..101dba7a 100644 --- a/cmd/internal/output.go +++ b/cmd/internal/output.go @@ -2,7 +2,6 @@ package internal import ( "encoding/json/jsontext" - "encoding/json/v2" "fmt" "io" "iter" @@ -11,6 +10,7 @@ import ( "github.com/spf13/pflag" "github.com/meshcloud/meshstack-cli/cmd/internal/markdown" + "github.com/meshcloud/meshstack-cli/internal/json" ) const OutputFlagName = "output" diff --git a/cmd/internal/read.go b/cmd/internal/read.go index 7c61c5cc..cf09a0c1 100644 --- a/cmd/internal/read.go +++ b/cmd/internal/read.go @@ -2,13 +2,14 @@ package internal import ( "encoding/json/jsontext" - "encoding/json/v2" "fmt" "io" "os" "github.com/spf13/cobra" "github.com/spf13/pflag" + + "github.com/meshcloud/meshstack-cli/internal/json" ) // JsonInputFlag names a JSON file to read into a T, or - for stdin. diff --git a/cmd/internal/testacc/api_get_test.go b/cmd/internal/testacc/api_get_test.go index ae05ac28..7834d253 100644 --- a/cmd/internal/testacc/api_get_test.go +++ b/cmd/internal/testacc/api_get_test.go @@ -4,7 +4,6 @@ import ( "cmp" "context" "encoding/json/jsontext" - "encoding/json/v2" "errors" "fmt" gohttp "net/http" @@ -23,6 +22,7 @@ import ( "github.com/meshcloud/meshstack-cli/client/openapi" "github.com/meshcloud/meshstack-cli/cmd/internal" "github.com/meshcloud/meshstack-cli/internal/apidocs" + "github.com/meshcloud/meshstack-cli/internal/json" "github.com/meshcloud/meshstack-cli/pkg/auth" ) @@ -101,11 +101,9 @@ func organizationAdmin(t *testing.T, logins []devLogin) organizationAdminLogin { func devApiDocs(t *testing.T) openapi.Spec { t.Helper() t.Setenv(envConfigDir, t.TempDir()) - httpClient, err := internal.ResolveClientOptions().HttpClient() - require.NoError(t, err) spec, wait, err := apidocs.Load(t.Context(), apidocs.Options{ Sources: internal.SettingSources(), - Client: httpClient, + Client: internal.ResolveClientOptions().HttpClient(), Version: internal.Version, Dev: true, }) @@ -158,7 +156,7 @@ type listed struct { func (o *firstObjects) get(ctx context.Context, r getRequest, operation openapi.Operation) (int, string, error) { options := []http.RequestOption{http.WithUrlQuery(r.query)} if mediaType, ok := operation.LatestMediaType(); ok { - options = append(options, http.WithAccept(mediaType.Name)) + options = append(options, http.WithHeader("Accept", mediaType.Name)) } body, err := o.meshStack.Raw.DoRequest(ctx, gohttp.MethodGet, r.path, options...) if httpErr, ok := errors.AsType[client.HttpError](err); ok { diff --git a/cmd/internal/testacc/api_test.go b/cmd/internal/testacc/api_test.go index f8591162..0c4f3803 100644 --- a/cmd/internal/testacc/api_test.go +++ b/cmd/internal/testacc/api_test.go @@ -1,13 +1,13 @@ package testacc import ( - "encoding/json/v2" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/meshcloud/meshstack-cli/client" + "github.com/meshcloud/meshstack-cli/internal/json" ) // apiAsksForJson checks the answers of meshStack that request.negotiate in cmd/api relies on where diff --git a/cmd/internal/testacc/buildingblock_test.go b/cmd/internal/testacc/buildingblock_test.go index 21e12a9f..b18d146b 100644 --- a/cmd/internal/testacc/buildingblock_test.go +++ b/cmd/internal/testacc/buildingblock_test.go @@ -1,7 +1,6 @@ package testacc import ( - "encoding/json/v2" "slices" "strings" "testing" @@ -9,6 +8,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/meshcloud/meshstack-cli/internal/json" ) // ndjsonObjects skips the lines of the log, which share the output with stdout. diff --git a/cmd/internal/testacc/list_test.go b/cmd/internal/testacc/list_test.go index c4763c7e..26130a2a 100644 --- a/cmd/internal/testacc/list_test.go +++ b/cmd/internal/testacc/list_test.go @@ -1,7 +1,6 @@ package testacc import ( - "encoding/json/v2" "os" "slices" "strings" @@ -9,6 +8,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/meshcloud/meshstack-cli/internal/json" ) // workspaceHoldingABuildingBlock is for the steps that need a building block, which a listing diff --git a/cmd/internal/testacc/login_test.go b/cmd/internal/testacc/login_test.go index 8b870c90..a4709171 100644 --- a/cmd/internal/testacc/login_test.go +++ b/cmd/internal/testacc/login_test.go @@ -1,7 +1,6 @@ package testacc import ( - "encoding/json/v2" "html" "io" "maps" @@ -18,6 +17,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/meshcloud/meshstack-cli/internal/json" "github.com/meshcloud/meshstack-cli/pkg/setting" ) diff --git a/cmd/internal/testacc/testacc_test.go b/cmd/internal/testacc/testacc_test.go index be316324..fe10c03e 100644 --- a/cmd/internal/testacc/testacc_test.go +++ b/cmd/internal/testacc/testacc_test.go @@ -2,7 +2,6 @@ package testacc import ( "context" - "encoding/json/v2" goio "io" "log/slog" gohttp "net/http" @@ -25,6 +24,7 @@ import ( "github.com/meshcloud/meshstack-cli/cmd/eventlog" "github.com/meshcloud/meshstack-cli/cmd/profile" "github.com/meshcloud/meshstack-cli/cmd/workspace" + "github.com/meshcloud/meshstack-cli/internal/json" "github.com/meshcloud/meshstack-cli/pkg/io" "github.com/meshcloud/meshstack-cli/pkg/setting" ) diff --git a/cmd/internal/testacc/tfstate_test.go b/cmd/internal/testacc/tfstate_test.go index c702a1d9..bc0caf6f 100644 --- a/cmd/internal/testacc/tfstate_test.go +++ b/cmd/internal/testacc/tfstate_test.go @@ -3,7 +3,6 @@ package testacc import ( "context" "crypto/rand" - "encoding/json/v2" "fmt" "maps" "os" @@ -17,6 +16,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/meshcloud/meshstack-cli/internal/json" "github.com/meshcloud/meshstack-cli/internal/tfstate" ) diff --git a/cmd/profile/show_test.go b/cmd/profile/show_test.go index 958d4115..07334d9d 100644 --- a/cmd/profile/show_test.go +++ b/cmd/profile/show_test.go @@ -1,7 +1,6 @@ package profile import ( - "encoding/json/v2" "log/slog" "maps" "slices" @@ -12,6 +11,7 @@ import ( "github.com/meshcloud/meshstack-cli/cmd/internal" "github.com/meshcloud/meshstack-cli/internal/auth/credential" + "github.com/meshcloud/meshstack-cli/internal/json" "github.com/meshcloud/meshstack-cli/internal/logs" "github.com/meshcloud/meshstack-cli/internal/profile" ) diff --git a/docs/demo/fakemeshstack/server.go b/docs/demo/fakemeshstack/server.go index 9e72cf1c..cc697d3f 100644 --- a/docs/demo/fakemeshstack/server.go +++ b/docs/demo/fakemeshstack/server.go @@ -9,7 +9,6 @@ import ( "crypto/x509" "crypto/x509/pkix" "encoding/json/jsontext" - "encoding/json/v2" "encoding/pem" "errors" "fmt" @@ -22,6 +21,7 @@ import ( "slices" "time" + "github.com/meshcloud/meshstack-cli/internal/json" "github.com/meshcloud/meshstack-cli/internal/testutil/fakemeshstack" ) diff --git a/flake.nix b/flake.nix index 16dfa6f2..a138c356 100644 --- a/flake.nix +++ b/flake.nix @@ -37,7 +37,7 @@ # directory's tests. docs/demo holds the demo's fake meshStack, which is no part of the CLI. excludedPackages = [ "docs/demo" ]; - vendorHash = "sha256-0CyEO5Ke53YInaO2xGf1JK4abXaEarExROXODGUy0CU="; + vendorHash = "sha256-ysQOO0vh9bzdao70d1QGO9Dh7R9FHYmrTolJ4qjz6mo="; # .goreleaser.yml and the Dockerfile set the same ldflag, and all three have to # agree. The linker ignores an -X whose path does not resolve and warns about diff --git a/go.mod b/go.mod index d379a20b..5490b54f 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ module github.com/meshcloud/meshstack-cli // Dockerfile in lock-step. The nixpkgs package (pkgs/by-name/me/meshstack-cli/package.nix // of NixOS/nixpkgs) builds with the default Go of nixpkgs, so raising the floor above that // default breaks its automatic update PRs until nixpkgs raises the default. -go 1.27 +go 1.27.0 // gotestsum is not a convenience: meshfed-release's go-satellite build plugin runs // `go tool gotestsum` in this directory to drive the acceptance suite. @@ -22,10 +22,12 @@ require ( charm.land/huh/v2 v2.0.3 charm.land/lipgloss/v2 v2.1.1 charm.land/log/v2 v2.0.1 + github.com/Shopify/toxiproxy/v2 v2.13.0 github.com/charmbracelet/colorprofile v0.4.3 github.com/charmbracelet/x/ansi v0.11.10 github.com/charmbracelet/x/term v0.2.2 github.com/gofrs/flock v0.13.2 + github.com/rs/zerolog v1.35.1 github.com/spf13/cobra v1.10.2 github.com/spf13/pflag v1.1.0 github.com/stretchr/testify v1.12.1 @@ -114,7 +116,6 @@ require ( github.com/go-xmlfmt/xmlfmt v1.1.3 // indirect github.com/gobwas/glob v0.2.3 // indirect github.com/godoc-lint/godoc-lint v0.11.2 // indirect - github.com/golang/protobuf v1.5.3 // indirect github.com/golangci/asciicheck v0.5.0 // indirect github.com/golangci/canonicalheader v0.0.0-20260827115959-a25c71c521f6 // indirect github.com/golangci/dupl v0.0.0-20260401084720-c99c5cf5c202 // indirect @@ -132,6 +133,7 @@ require ( github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect github.com/gordonklaus/ineffassign v0.2.0 // indirect github.com/gorilla/css v1.0.1 // indirect + github.com/gorilla/mux v1.8.1 // indirect github.com/gostaticanalysis/analysisutil v0.7.1 // indirect github.com/gostaticanalysis/comment v1.5.0 // indirect github.com/gostaticanalysis/forcetypeassert v0.2.0 // indirect @@ -168,7 +170,6 @@ require ( github.com/mattn/go-colorable v0.1.15 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.31 // indirect - github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect github.com/mgechev/revive v1.15.0 // indirect github.com/microcosm-cc/bluemonday v1.0.27 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect @@ -176,16 +177,17 @@ require ( github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/moricho/tparallel v0.3.2 // indirect github.com/muesli/cancelreader v0.2.2 // indirect + github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/nakabonne/nestif v0.3.1 // indirect github.com/nishanths/exhaustive v0.12.0 // indirect github.com/nishanths/predeclared v0.2.2 // indirect github.com/nunnatsa/ginkgolinter v0.24.0 // indirect github.com/pelletier/go-toml v1.9.5 // indirect github.com/pelletier/go-toml/v2 v2.4.3 // indirect - github.com/prometheus/client_golang v1.12.1 // indirect - github.com/prometheus/client_model v0.2.0 // indirect - github.com/prometheus/common v0.32.1 // indirect - github.com/prometheus/procfs v0.7.3 // indirect + github.com/prometheus/client_golang v1.24.1 // indirect + github.com/prometheus/client_model v0.6.2 // indirect + github.com/prometheus/common v0.70.1 // indirect + github.com/prometheus/procfs v0.21.1 // indirect github.com/quasilyte/go-ruleguard v0.4.5 // indirect github.com/quasilyte/go-ruleguard/dsl v0.3.23 // indirect github.com/quasilyte/gogrep v0.5.0 // indirect @@ -194,6 +196,7 @@ require ( github.com/raeperd/recvcheck v0.3.0 // indirect github.com/rivo/uniseg v0.4.8-0.20261110175422-3a370411ca06 // indirect github.com/rogpeppe/go-internal v1.16.0 // indirect + github.com/rs/xid v1.6.0 // indirect github.com/ryancurrah/gomodguard v1.4.1 // indirect github.com/ryancurrah/gomodguard/v2 v2.1.3 // indirect github.com/ryanrolds/sqlclosecheck v0.6.0 // indirect @@ -252,6 +255,7 @@ require ( golang.org/x/vuln v1.8.0 // indirect google.golang.org/protobuf v1.36.11 // indirect gopkg.in/ini.v1 v1.67.0 // indirect + gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect gotest.tools/gotestsum v1.13.0 // indirect diff --git a/go.sum b/go.sum index f1d521ca..c38296c6 100644 --- a/go.sum +++ b/go.sum @@ -14,38 +14,6 @@ charm.land/lipgloss/v2 v2.1.1 h1:F+vKWis9Kz3MFRsbICSDFtT1ZwVL+8f+36Dtg+OpKwc= charm.land/lipgloss/v2 v2.1.1/go.mod h1:k79y/56yThpkJvbwyrcHr8MyZF42e84Q5fW9Ibu6LFc= charm.land/log/v2 v2.0.1 h1:uMk+t1hM/fomIqt7vn/Ub0AKo7IHvnDu6NK17nbOVx0= charm.land/log/v2 v2.0.1/go.mod h1:VXZNB8zoPPEIcvd7bRi2fpQpGCWweCSfWOwczA9dibs= -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= -cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= -cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= -cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= -cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= -cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To= -cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4= -cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M= -cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc= -cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk= -cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs= -cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc= -cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY= -cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= -cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= -cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= -cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg= -cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc= -cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= -cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= -cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= -cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= -cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= -cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= -cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU= -cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= -cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= -cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= -cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= -cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= codeberg.org/chavacava/garif v0.2.0 h1:F0tVjhYbuOCnvNcU3YSpO6b3Waw6Bimy4K0mM8y6MfY= codeberg.org/chavacava/garif v0.2.0/go.mod h1:P2BPbVbT4QcvLZrORc2T29szK3xEOlnl0GiPTJmEqBQ= codeberg.org/polyfloyd/go-errorlint v1.9.0 h1:VkdEEmA1VBpH6ecQoMR4LdphVI3fA4RrCh2an7YmodI= @@ -56,7 +24,6 @@ dev.gaijin.team/go/exhaustruct/v5 v5.0.3 h1:yOeA7DNjlT8y4yfmN6nWWYYggA13N523YAj9 dev.gaijin.team/go/exhaustruct/v5 v5.0.3/go.mod h1:KwtBsX8nHHH1YxhxkpiBq6bfsmw5WnazWpNvJPHgY9Y= dev.gaijin.team/go/golib v0.8.1 h1:JYju4x9BSo+QD/AYeHULVDcvEhiFg8wOi6pT0IaZF5E= dev.gaijin.team/go/golib v0.8.1/go.mod h1:c5fu7t1RSGMxSQgcUYO1sODbzsYnOCXJLmHeNG1Eb+0= -dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/4meepo/tagalign v1.4.3 h1:Bnu7jGWwbfpAie2vyl63Zup5KuRv21olsPIha53BJr8= github.com/4meepo/tagalign v1.4.3/go.mod h1:00WwRjiuSbrRJnSVeGWPLp2epS5Q/l4UEy0apLLS37c= github.com/Abirdcfly/dupword v0.1.8 h1:SrhcUuGsROBuChFxHALRYzyyPODWn9zwghmzPvD9Cd8= @@ -71,10 +38,8 @@ github.com/Antonboom/nilnil v1.1.2 h1:aNlFuJhaEseXe4fHO3xbjXlSeEiQVYa2lEkWD2s2hA github.com/Antonboom/nilnil v1.1.2/go.mod h1:0ynwvphOLmAuMwTNDyBnDZmSwZoDpcFXmUHmzoHH2WA= github.com/Antonboom/testifylint v1.6.4 h1:gs9fUEy+egzxkEbq9P4cpcMB6/G0DYdMeiFS87UiqmQ= github.com/Antonboom/testifylint v1.6.4/go.mod h1:YO33FROXX2OoUfwjz8g+gUxQXio5i9qpVy7nXGbxDD4= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk= github.com/BurntSushi/toml v1.6.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= -github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/ClickHouse/clickhouse-go-linter v1.2.1 h1:zGEKIyd5YL08ieWG/LOUmlau2DxbxPVOfAeo+4Jz3ck= github.com/ClickHouse/clickhouse-go-linter v1.2.1/go.mod h1:pLorS7ffPTfuUV9M0SJgfHA/h/WQPQUk2FWG9x74cQ4= github.com/Djarvur/go-err113 v0.1.1 h1:eHfopDqXRwAi+YmCUas75ZE0+hoBHJ2GQNLYRSxao4g= @@ -87,6 +52,8 @@ github.com/MirrexOne/unqueryvet v1.5.4 h1:38QOxShO7JmMWT+eCdDMbcUgGCOeJphVkzzRgy github.com/MirrexOne/unqueryvet v1.5.4/go.mod h1:fs9Zq6eh1LRIhsDIsxf9PONVUjYdFHdtkHIgZdJnyPU= github.com/OpenPeeDeeP/depguard/v2 v2.2.1 h1:vckeWVESWp6Qog7UZSARNqfu/cZqvki8zsuj3piCMx4= github.com/OpenPeeDeeP/depguard/v2 v2.2.1/go.mod h1:q4DKzC4UcVaAvcfd41CZh0PWpGgzrVxUYBlgKNGquUo= +github.com/Shopify/toxiproxy/v2 v2.13.0 h1:+SASZmq0GBNEc38gHzWvWkntJCk7olgfZr1sP6O/Bhk= +github.com/Shopify/toxiproxy/v2 v2.13.0/go.mod h1:MeXHdiGjtrmZqR8N1kR9++itfDm2FnzhdfQHOyKFfm8= github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0= github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= github.com/alecthomas/chroma/v2 v2.27.0 h1:FodwmyOBgJULFYmDqibcp9pvfDLWdtPRh9v/r5BXYZs= @@ -95,11 +62,6 @@ github.com/alecthomas/go-check-sumtype v0.3.1 h1:u9aUvbGINJxLVXiFvHUlPEaD7VDULsr github.com/alecthomas/go-check-sumtype v0.3.1/go.mod h1:A8TSiN3UPRw3laIgWEUOHHLPa6/r9MtoigdlP5h3K/E= github.com/alecthomas/repr v0.5.2 h1:SU73FTI9D1P5UNtvseffFSGmdNci/O6RsqzeXJtP0Qs= github.com/alecthomas/repr v0.5.2/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= -github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= -github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= -github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= github.com/alexkohler/nakedret/v2 v2.0.6 h1:ME3Qef1/KIKr3kWX3nti3hhgNxw6aqN5pZmQiFSsuzQ= github.com/alexkohler/nakedret/v2 v2.0.6/go.mod h1:l3RKju/IzOMQHmsEvXwkqMDzHHvurNQfAgE1eVmT40Q= github.com/alexkohler/prealloc v1.1.0 h1:cKGRBqlXw5iyQGLYhrXrDlcHxugXpTq4tQ5c91wkf8M= @@ -120,8 +82,6 @@ github.com/aymanbagabas/go-udiff v0.4.1 h1:OEIrQ8maEeDBXQDoGCbbTTXYJMYRCRO1fnodZ github.com/aymanbagabas/go-udiff v0.4.1/go.mod h1:0L9PGwj20lrtmEMeyw4WKJ/TMyDtvAoK9bf2u/mNo3w= github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk= github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4= -github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= -github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bitfield/gotestdox v0.2.2 h1:x6RcPAbBbErKLnapz1QeAlf3ospg8efBsedU93CDsnE= @@ -148,9 +108,6 @@ github.com/catppuccin/go v0.2.0 h1:ktBeIrIP42b/8FGiScP9sgrWOss3lw0Z5SktRoithGA= github.com/catppuccin/go v0.2.0/go.mod h1:8IHJuMGaUUjQM82qBrGNBv7LFq6JI3NnQCF6MOlZjpc= github.com/ccojocar/zxcvbn-go v1.0.4 h1:FWnCIRMXPj43ukfX000kvBZvV6raSxakYr1nzyNrUcc= github.com/ccojocar/zxcvbn-go v1.0.4/go.mod h1:3GxGX+rHmueTUMvm5ium7irpyjmm7ikxYFOSJB21Das= -github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/charithe/durationcheck v0.0.11 h1:g1/EX1eIiKS57NTWsYtHDZ/APfeXKhye1DidBcABctk= @@ -181,17 +138,12 @@ github.com/charmbracelet/x/windows v0.2.2 h1:IofanmuvaxnKHuV04sC0eBy/smG6kIKrWG2 github.com/charmbracelet/x/windows v0.2.2/go.mod h1:/8XtdKZzedat74NQFn0NGlGL4soHB0YQZrETF96h75k= github.com/charmbracelet/x/xpty v0.1.3 h1:eGSitii4suhzrISYH50ZfufV3v085BXQwIytcOdFSsw= github.com/charmbracelet/x/xpty v0.1.3/go.mod h1:poPYpWuLDBFCKmKLDnhBp51ATa0ooD8FhypRwEFtH3Y= -github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= -github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= -github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/ckaznocha/intrange v0.3.1 h1:j1onQyXvHUsPWujDH6WIjhyH26gkRt/txNlV7LspvJs= github.com/ckaznocha/intrange v0.3.1/go.mod h1:QVepyz1AkUoFQkpEqksSYpNpUo3c5W7nWh/s6SHIJJk= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/clipperhouse/displaywidth v0.11.0 h1:lBc6kY44VFw+TDx4I8opi/EtL9m20WSEFgwIwO+UVM8= github.com/clipperhouse/displaywidth v0.11.0/go.mod h1:bkrFNkf81G8HyVqmKGxsPufD3JhNl3dSqnGhOoSD/o0= github.com/clipperhouse/uax29/v2 v2.7.0 h1:+gs4oBZ2gPfVrKPthwbMzWZDaAFPGYK72F0NJv2v7Vk= github.com/clipperhouse/uax29/v2 v2.7.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJSwu5BF98AuoVM= -github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/creack/pty v1.1.24 h1:bJrF4RRfyJnbTJqzRLHzcGaZK1NeM5kTC9jGgovnR1s= github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE= @@ -217,10 +169,6 @@ github.com/dnephin/pflag v1.0.7 h1:oxONGlWxhmUct0YzKTgrpQv9AUA1wtPBn7zuSjJqptk= github.com/dnephin/pflag v1.0.7/go.mod h1:uxE91IoWURlOiTUIA8Mq5ZZkAv3dPUfZNaT80Zm7OQE= github.com/dustin/go-humanize v1.1.0 h1:dbKTrvD0klcbBV/h4AWJdMuZogJACoMlvWIWZ5b2xWg= github.com/dustin/go-humanize v1.1.0/go.mod h1:hc1CvRkJMsgxqjmjMQF3QNRAZBwY8AXBAzKYoSX9sFI= -github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= -github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/ettle/strcase v0.2.0 h1:fGNiVF21fHXpX1niBgk0aROov1LagYsOwV/xqKDKR/Q= github.com/ettle/strcase v0.2.0/go.mod h1:DajmHElDSaX76ITe3/VHVyMin4LWSJN5Z909Wp+ED1A= github.com/fatih/color v1.19.0 h1:Zp3PiM21/9Ld6FzSKyL5c/BULoe/ONr9KlbYVOfG8+w= @@ -239,22 +187,12 @@ github.com/ghostiam/protogetter v0.3.21 h1:EeWTGvL/Eyosp653hiWb6Byx4b69iJC4/E+za github.com/ghostiam/protogetter v0.3.21/go.mod h1:iAKSpyoHwYzay+OpjoWgwzRtPFthEfuUvmlomTThck0= github.com/go-critic/go-critic v0.14.4 h1:dSX4C3pWSeuMVxvQh6yG8U0ReSf3YOmKi4nwX5q7n/8= github.com/go-critic/go-critic v0.14.4/go.mod h1:xwntfW6SYAd7h1OqDzmN6hBX/JxsEKl5up/Y2bsxgVQ= -github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= -github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= -github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= -github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= -github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= -github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= -github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= github.com/go-logfmt/logfmt v0.6.1 h1:4hvbpePJKnIzH1B+8OR/JPbTx37NktoI9LE2QZBBkvE= github.com/go-logfmt/logfmt v0.6.1/go.mod h1:EV2pOAQoZaT1ZXZbqDl5hrymndi4SY9ED9/z6CO0XAk= github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-quicktest/qt v1.102.0 h1:HSQxCeh5YZH3EL3W39ixjtyaEhcWSXQHtHnMBzSs474= github.com/go-quicktest/qt v1.102.0/go.mod h1:p4lGIVX+8Wa6ZPNDvqcxq36XpUDLh42FLetFU7odllI= -github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= github.com/go-toolsmith/astcast v1.1.0 h1:+JN9xZV1A+Re+95pgnMgDboWNVnIMMQXwfBwLRPgSC8= @@ -286,36 +224,6 @@ github.com/godoc-lint/godoc-lint v0.11.2 h1:Bp0FkJWoSdNsBikdNgIcgtaoo+xz6I/Y9s5W github.com/godoc-lint/godoc-lint v0.11.2/go.mod h1:iVpGdL1JCikNH2gGeAn3Hh+AgN5Gx/I/cxV+91L41jo= github.com/gofrs/flock v0.13.2 h1:9o62TArG4T0f8L46kSf8sLtNUGvJEfiCK9md7/ilko0= github.com/gofrs/flock v0.13.2/go.mod h1:OEjpF6MC2Plt1fLXTTgXwnZohWbs/Alxf2i1qTne/Vg= -github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= -github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= -github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= -github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= -github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= -github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= -github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= -github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= -github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golangci/asciicheck v0.5.0 h1:jczN/BorERZwK8oiFBOGvlGPknhvq0bjnysTj4nUfo0= github.com/golangci/asciicheck v0.5.0/go.mod h1:5RMNAInbNFw2krqN6ibBxN/zfRFa9S6tA1nPdM0l8qQ= github.com/golangci/canonicalheader v0.0.0-20260827115959-a25c71c521f6 h1:fVLolA3dG6s0brGetsiDAtcnpMSwVa2LqXJEw/9RJG4= @@ -342,45 +250,25 @@ github.com/golangci/swaggoswag v0.0.0-20250504205917-77f2aca3143e h1:ai0EfmVYE2b github.com/golangci/swaggoswag v0.0.0-20250504205917-77f2aca3143e/go.mod h1:Vrn4B5oR9qRwM+f54koyeH3yzphlecwERs0el27Fr/s= github.com/golangci/unconvert v0.0.0-20250410112200-a129a6e6413e h1:gD6P7NEo7Eqtt0ssnqSJNNndxe69DOQ24A5h7+i3KpM= github.com/golangci/unconvert v0.0.0-20250410112200-a129a6e6413e/go.mod h1:h+wZwLjUTJnm/P2rwlbJdRPZXOzaT36/FwnPnY2inzc= -github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmdtest v0.4.1-0.20220921163831-55ab3332a786 h1:rcv+Ippz6RAtvaGgKxc+8FQIpxHgsF+HBzPyYL2cyVU= github.com/google/go-cmdtest v0.4.1-0.20220921163831-55ab3332a786/go.mod h1:apVn/GCasLZUVpAJ6oWAuyP7Ne7CEsQbTnc0plM3m+o= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= -github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= -github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= -github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/pprof v0.0.0-20260709232956-b9395ee17fa0 h1:du0WGc8xSKq/++e0cglxhS/mXVqsR7+c7jLEi5Vqduw= github.com/google/pprof v0.0.0-20260709232956-b9395ee17fa0/go.mod h1:MxpfABSjhmINe3F1It9d+8exIHFvUqtLIRCdOGNXqiI= github.com/google/renameio v0.1.0 h1:GOZbcHa3HfsPKPlmyPyN2KEohoMXOhdMbHrvbpl2QaA= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= -github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= -github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/gordonklaus/ineffassign v0.2.0 h1:Uths4KnmwxNJNzq87fwQQDDnbNb7De00VOk9Nu0TySs= github.com/gordonklaus/ineffassign v0.2.0/go.mod h1:TIpymnagPSexySzs7F9FnO1XFTy8IT3a59vmZp5Y9Lw= github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8= github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0= +github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= +github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= github.com/gostaticanalysis/analysisutil v0.7.1 h1:ZMCjoue3DtDWQ5WyU16YbjbQEQ3VuzwxALrpYd+HeKk= github.com/gostaticanalysis/analysisutil v0.7.1/go.mod h1:v21E3hY37WKMGSnbsw2S/ojApNWb6C1//mXO48CXbVc= github.com/gostaticanalysis/comment v1.4.2/go.mod h1:KLUTGDv6HOCotCH8h2erHKmpci2ZoR8VPu34YA2uzdM= @@ -400,47 +288,30 @@ github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/b github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go-version v1.9.0 h1:CeOIz6k+LoN3qX9Z0tyQrPtiB1DFYRPfCIBtaXPSCnA= github.com/hashicorp/go-version v1.9.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= -github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/jgautheron/goconst v1.11.0 h1:KgN90z5qXt5f0Uzf3cWXev3hfMMFUyNeKdpkSBRvLDk= github.com/jgautheron/goconst v1.11.0/go.mod h1:0p+wv1lFOiUr0IlNNT1nrm6+8DB8u2sU6KHGzFRXHDc= github.com/jjti/go-spancheck v0.6.5 h1:lmi7pKxa37oKYIMScialXUK6hP3iY5F1gu+mLBPgYB8= github.com/jjti/go-spancheck v0.6.5/go.mod h1:aEogkeatBrbYsyW6y5TgDfihCulDYciL1B7rG2vSsrU= -github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= -github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= -github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= -github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= -github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= -github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= -github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/julz/importas v0.2.0 h1:y+MJN/UdL63QbFJHws9BVC5RpA2iq0kpjrFajTGivjQ= github.com/julz/importas v0.2.0/go.mod h1:pThlt589EnCYtMnmhmRYY/qn9lCf/frPOK+WMx3xiJY= github.com/karamaru-alpha/copyloopvar v1.2.2 h1:yfNQvP9YaGQR7VaWLYcfZUlRP2eo2vhExWKxD/fP6q0= github.com/karamaru-alpha/copyloopvar v1.2.2/go.mod h1:oY4rGZqZ879JkJMtX3RRkcXRkmUvH0x35ykgaKgsgJY= github.com/kisielk/errcheck v1.20.0 h1:9rwHBNKzd4wkDWcROy3DvFGNqEPlkxBg305rvk7HabI= github.com/kisielk/errcheck v1.20.0/go.mod h1:O+f80MKNwX8Oor2jwgpeQ9An7uJm+hRSgT+h22knRJU= -github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kkHAIKE/contextcheck v1.1.6 h1:7HIyRcnyzxL9Lz06NGhiKvenXq7Zw6Q0UQu/ttjfJCE= github.com/kkHAIKE/contextcheck v1.1.6/go.mod h1:3dDbMRNBFaq8HFXWC1JyvDSPm43CmE6IuHam8Wr0rkg= -github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/klauspost/compress v1.19.1 h1:VsB4HPswih7mmZ8WleSFQ75c/Ui1M4trX5oAsJnhSlk= +github.com/klauspost/compress v1.19.1/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kulti/thelper v0.7.1 h1:fI8QITAoFVLx+y+vSyuLBP+rcVIB8jKooNSCT2EiI98= @@ -487,8 +358,6 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.31 h1:1oCV4ReTlosDBc6rYRw5cL8S/4y8iv5oRl4SJ5IBgwo= github.com/mattn/go-runewidth v0.0.31/go.mod h1:3qAiGCV4Koz/yuveO58qUefmUTRm8r0IGEXZ9jeHp/8= -github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= -github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/mgechev/revive v1.15.0 h1:vJ0HzSBzfNyPbHKolgiFjHxLek9KUijhqh42yGoqZ8Q= github.com/mgechev/revive v1.15.0/go.mod h1:LlAKO3QQe9OJ0pVZzI2GPa8CbXGZ/9lNpCGvK4T/a8A= github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwXFM08ygZfk= @@ -499,17 +368,12 @@ github.com/mitchellh/hashstructure/v2 v2.0.2 h1:vGKWl0YJqUNxE8d+h8f6NJLcCJrgbhC4 github.com/mitchellh/hashstructure/v2 v2.0.2/go.mod h1:MG3aRVU/N29oo/V/IhBX8GR/zz4kQkprJgF2EVszyDE= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/moricho/tparallel v0.3.2 h1:odr8aZVFA3NZrNybggMkYO3rgPRcqjeQUlBBFVxKHTI= github.com/moricho/tparallel v0.3.2/go.mod h1:OQ+K3b4Ln3l2TZveGCywybl68glfLEwFGqvnjok8b+U= github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA= github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= -github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= -github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/nakabonne/nestif v0.3.1 h1:wm28nZjhQY5HyYPx+weN3Q65k6ilSBxDb8v5S81B81U= github.com/nakabonne/nestif v0.3.1/go.mod h1:9EtoZochLn5iUprVDmDjqGKPofoUEBL8U4Ngq6aY7OE= github.com/nishanths/exhaustive v0.12.0 h1:vIY9sALmw6T/yxiASewa4TQcFsVYZQQRUQJhKRf3Swg= @@ -533,32 +397,15 @@ github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3v github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/pelletier/go-toml/v2 v2.4.3 h1:GTRvJQutkOSftxIFD5xw9aepkYNuPWmVJpffdDPYVpY= github.com/pelletier/go-toml/v2 v2.4.3/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= -github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= -github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= -github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= -github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= -github.com/prometheus/client_golang v1.12.1 h1:ZiaPsmm9uiBeaSMRznKsCDNtPCS0T3JVDGF+06gjBzk= -github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY= -github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= -github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M= -github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= -github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= -github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc= -github.com/prometheus/common v0.32.1 h1:hWIdL3N2HoUx3B8j3YN9mWor0qhY/NlEKZEaXxuIRh4= -github.com/prometheus/common v0.32.1/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls= -github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= -github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= -github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= -github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU= -github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= +github.com/prometheus/client_golang v1.24.1 h1:JnJkREXzWxUdCuPFpIWZiPispT9xVV59uiuyR2bPlnU= +github.com/prometheus/client_golang v1.24.1/go.mod h1:F+oSRECHg4sse5ucfYpYDeIv/hu68Zo0uoHKetWnzcE= +github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk= +github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE= +github.com/prometheus/common v0.70.1 h1:1HvjP4D5oL3t8RsPlwxA9onvvStjtIHYE5XuuwOi/PY= +github.com/prometheus/common v0.70.1/go.mod h1:VdFUQDMZK3VLkurFUVhia6uys/0suUp86TJz5qbJRhc= +github.com/prometheus/procfs v0.21.1 h1:GljZCt+zSTS+NZq88cyQ1LjZ+RCHp3uVuabBWA5+OJI= +github.com/prometheus/procfs v0.21.1/go.mod h1:aB55Cww9pdSJVHk0hUf0inxWyyjPogFIjmHKYgMKmtY= github.com/quasilyte/go-ruleguard v0.4.5 h1:AGY0tiOT5hJX9BTdx/xBdoCubQUAE2grkqY2lSwvZcA= github.com/quasilyte/go-ruleguard v0.4.5/go.mod h1:Vl05zJ538vcEEwu16V/Hdu7IYZWyKSwIy4c88Ro1kRE= github.com/quasilyte/go-ruleguard/dsl v0.3.23 h1:lxjt5B6ZCiBeeNO8/oQsegE6fLeCzuMRoVWSkXC4uvY= @@ -573,9 +420,12 @@ github.com/raeperd/recvcheck v0.3.0 h1:PM+XYvyxIj3bo+kobJfFTdTuU3Lmfu96mKDbyHDbR github.com/raeperd/recvcheck v0.3.0/go.mod h1:PZNwG+HztFYMH2ZPq0Hu3QgkV2yiA6VrtNz9c1fXWJo= github.com/rivo/uniseg v0.4.8-0.20261110175422-3a370411ca06 h1:e3d0GqpC//2tTV8c43tVSNmUS/NaR0JUXyqigUuc6Co= github.com/rivo/uniseg v0.4.8-0.20261110175422-3a370411ca06/go.mod h1:f2N4/YqLrDrVp5TT4AefKt4trMkR5vN6+yaqpJBUerQ= -github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.16.0 h1:O9DK+vNMDVGLr2BeZqmpLeMjiMNkuXfcqntWbZV6S5g= github.com/rogpeppe/go-internal v1.16.0/go.mod h1:DrUVZyrJU+txYW5/1kwtXQSMFio52ZOxX7yM1VHvnxs= +github.com/rs/xid v1.6.0 h1:fV591PaemRlL6JfRxGDEPl69wICngIQ3shQtzfy2gxU= +github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0= +github.com/rs/zerolog v1.35.1 h1:m7xQeoiLIiV0BCEY4Hs+j2NG4Gp2o2KPKmhnnLiazKI= +github.com/rs/zerolog v1.35.1/go.mod h1:EjML9kdfa/RMA7h/6z6pYmq1ykOuA8/mjWaEvGI+jcw= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryancurrah/gomodguard v1.4.1 h1:eWC8eUMNZ/wM/PWuZBv7JxxqT5fiIKSIyTvjb7Elr+g= github.com/ryancurrah/gomodguard v1.4.1/go.mod h1:qnMJwV1hX9m+YJseXEBhd2s90+1Xn6x9dLz11ualI1I= @@ -597,9 +447,6 @@ github.com/securego/gosec/v2 v2.28.0 h1:ZsSdiDb0AtTpLFVol5z91gbMei9ZiLEPG/pZjZuj github.com/securego/gosec/v2 v2.28.0/go.mod h1:lb4/9AHe+lJy/kjWmWRWWsEipvbwGKuxf+tY1Pmjdnk= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= -github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= -github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= -github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= github.com/sirupsen/logrus v1.10.1 h1:xi4336Zh11WpU14fXR6I67V3yaTPQYwRx2WEtHbRg4Q= github.com/sirupsen/logrus v1.10.1/go.mod h1:vsQHnG7xzNsxk3NrwboUiWPnIC3dmbjcGPykD7+tiHk= github.com/sivchari/containedctx v1.0.3 h1:x+etemjbsh2fB5ewm5FeLNi5bUjK0V8n0RB+Wwfd0XE= @@ -627,7 +474,6 @@ github.com/ssgreg/nlreturn/v2 v2.2.1/go.mod h1:E/iiPB78hV7Szg2YfRgyIrk1AD6JVMTRk github.com/stbenjam/no-sprintf-host-port v0.3.1 h1:AyX7+dxI4IdLBPtDbsGAyqiTSLpCP9hWRrXQDU4Cm/g= github.com/stbenjam/no-sprintf-host-port v0.3.1/go.mod h1:ODbZesTCHMVKthBHskvUUexdcNHAQRXk9NpSsL8p/HQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.5.3 h1:jmXUvGomnU1o3W/V5h2VEradbpJDwGrzugQQvL0POH4= github.com/stretchr/objx v0.5.3/go.mod h1:rDQraq+vQZU7Fde9LOZLr8Tax6zZvy4kuNKF+QYS+U0= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= @@ -670,7 +516,6 @@ github.com/yeya24/promlinter v0.3.0/go.mod h1:cDfJQQYv9uYciW60QT0eeHlFodotkYZlL+ github.com/ykadowak/zerologlint v0.1.5 h1:Gy/fMz1dFQN9JZTPjv1hxEk+sRWm05row04Yoolgdiw= github.com/ykadowak/zerologlint v0.1.5/go.mod h1:KaUskqF3e/v59oPmdq1U1DnKcuHokl2/K1U4pmIELKg= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= @@ -692,61 +537,27 @@ go.augendre.info/arangolint v0.4.0 h1:xSCZjRoS93nXazBSg5d0OGCi9APPLNMmmLrC995tR5 go.augendre.info/arangolint v0.4.0/go.mod h1:l+f/b4plABuFISuKnTGD4RioXiCCgghv2xqst/xOvAA= go.augendre.info/fatcontext v0.10.0 h1:HhFopmivh8U1+AU7f0kuwUeg2eiIns7YsGQOMHwSJ90= go.augendre.info/fatcontext v0.10.0/go.mod h1:pqpGvA9GlrXy+aXkp8L2dKz12Zp4g2FhzcAtwToU+2w= -go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= -go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= -go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= -go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= -go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ= go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= +go.yaml.in/yaml/v2 v2.4.4 h1:tuyd0P+2Ont/d6e2rl3be67goVK4R6deVxCUX5vyPaQ= +go.yaml.in/yaml/v2 v2.4.4/go.mod h1:gMZqIpDtDqOfM0uNfy0SkpRhvUryYH0Z6wdMYcacYXQ= go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw= go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg= -golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= -golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= -golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= -golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= -golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= -golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= -golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= -golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b h1:M2rDM6z3Fhozi9O7NWsxAkg/yqS/lQJ6PmkyIV3YP+o= golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b/go.mod h1:3//PLf8L/X+8b4vuAfHzxeRUl04Adcb341+IGKfnqS8= golang.org/x/exp/typeparams v0.0.0-20220428152302-39d4317da171/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= golang.org/x/exp/typeparams v0.0.0-20230203172020-98cc5a0785f9/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= golang.org/x/exp/typeparams v0.0.0-20260811152304-ee035b5b010f h1:+lI8cDJ4uceLipg2f1ODay7fEuLkk0BIHXd6PB8icxo= golang.org/x/exp/typeparams v0.0.0-20260811152304-ee035b5b010f/go.mod h1:PqrXSW65cXDZH0k4IeUbhmg/bcAZDbzNz3byBpKCsXo= -golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= -golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= -golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= -golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= -golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= -golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= -golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= -golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= -golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= @@ -755,103 +566,36 @@ golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91 golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.41.0 h1:qJmnOUb4YB+FsEuM3HcWucdZASCPGhsX6uljO6pog0c= golang.org/x/mod v0.41.0/go.mod h1:Ek9pY8RKWXwsWvd3rQiHYtMqkjSUV+s1Rj7j4H5Ur6o= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.59.0 h1:5zfYln+w5XCxwrnMMJPufRgNoXEaGxl0wo5GqPXyues= golang.org/x/net v0.59.0/go.mod h1:2DA/G1UfVbCpQPeWTmMPGY7Cs2PkBkwu743bVX5PIVg= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.23.0 h1:KameEIfc1IkluZyXWLn39Wd4tURc6GbCiISGiZm2bQk= golang.org/x/sync v0.23.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211105183446-c75c47738b0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -865,9 +609,7 @@ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuX golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.46.0 h1:3+OXuTbaKDgwk8jTi3aSLHRlmWqHEUDUtxnbFigO4YE= golang.org/x/term v0.46.0/go.mod h1:+K02xbkittuwc0Am4abfA3Fc+XRGXkvBXNO88NCXPoc= -golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -875,51 +617,10 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.42.0 h1:JbOZXgfeCPU9gacVtYliJqOhD+zhrEqK4LfdpmlUZqI= golang.org/x/text v0.42.0/go.mod h1:ojzP1Z+2QtioaF8DTtO8K5q7JWVVYwZKenzujK0Zd0E= -golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= -golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= golang.org/x/tools v0.0.0-20200329025819-fd4102a86c65/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= -golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= -golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200724022722-7017fd6b1305/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= -golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= -golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= -golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.1.1-0.20210205202024-ef80cdb6ec6d/go.mod h1:9bzcO0MWcOuT0tm1iBGzDVPshzfwoVvREIui8C+MHqU= golang.org/x/tools v0.1.1-0.20210302220138-2ac05c832e1a/go.mod h1:9bzcO0MWcOuT0tm1iBGzDVPshzfwoVvREIui8C+MHqU= golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= @@ -937,96 +638,16 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= -google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= -google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= -google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= -google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= -google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= -google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= -google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= -google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= -google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM= -google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= -google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= -google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA= -google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= -google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= -google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= -google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= -google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= -google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= -google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= -google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= -google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= -gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= @@ -1035,19 +656,9 @@ gotest.tools/gotestsum v1.13.0 h1:+Lh454O9mu9AMG1APV4o0y7oDYKyik/3kBOiCqiEpRo= gotest.tools/gotestsum v1.13.0/go.mod h1:7f0NS5hFb0dWr4NtcsAsF0y1kzjEFfAil0HiBQJE03Q= gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q= gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA= -honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= -honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= -honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= honnef.co/go/tools v0.8.1 h1:+JKf3xJ1ni4CwrhVg4/pqsfPGP6vNAXcKbMXJodYx3w= honnef.co/go/tools v0.8.1/go.mod h1:XA+OnlRA9EDh/ukGvXMNSZNKGwFQJ+5dER0ioUkOxks= mvdan.cc/gofumpt v0.11.0 h1:0H01XB95PnN2QgCSR9ELdZyTlJqNZ7181B0BTMh5VZc= mvdan.cc/gofumpt v0.11.0/go.mod h1:BeT5wCsOJt6J9zT2MZIOGszjUHzFkn1/l9g6xAzqsXo= mvdan.cc/unparam v0.0.0-20260823230713-2fa3d841b0c8 h1:Re1NRyLpiAt9kB+ImaaoapwWiQXrKwER4tY8fLOkDew= mvdan.cc/unparam v0.0.0-20260823230713-2fa3d841b0c8/go.mod h1:MrS/+zJ1M2xvGXhKktiHbNQeQPyg3Qel+KkzT+f7/i4= -rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= -rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= -rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/internal/apidocs/apidocs.go b/internal/apidocs/apidocs.go index f88ba1c2..6be387dd 100644 --- a/internal/apidocs/apidocs.go +++ b/internal/apidocs/apidocs.go @@ -75,46 +75,41 @@ func Load(ctx context.Context, opts Options) (spec openapi.Spec, wait func(), er if err = custom.UnmarshalText([]byte(customEnv)); err != nil { return spec, wait, fmt.Errorf("%s: %w", urlEnv, err) } - return opts.download(ctx, custom.URL, dir.Join(fmt.Sprintf("api-docs-custom-%s.json", urlHash(custom.URL))), true) + return opts.download(ctx, custom.URL, dir.Join(fmt.Sprintf("api-docs-custom-%s.json", urlHash(custom.URL)))) } if opts.Endpoint.URL != nil && !opts.Dev { served := opts.Endpoint.JoinPath("api", "openapi") - spec, wait, err = opts.download(ctx, served, dir.Join(fmt.Sprintf("api-docs-%s.json", urlHash(served))), true) + spec, wait, err = opts.download(ctx, served, dir.Join(fmt.Sprintf("api-docs-%s.json", urlHash(served)))) if httpErr, ok := errors.AsType[http.Error](err); !ok || (!httpErr.IsUnauthorized() && !httpErr.IsNotFound()) { return spec, wait, err } slog.DebugContext(ctx, fmt.Sprintf("%s serves no API docs at /api/openapi, reading those of the docs site", opts.Endpoint)) } - url, path, conditionalGet := releasedUrl, dir.Join("api-docs.json"), false + url, path := releasedUrl, dir.Join("api-docs.json") if cliVersion, parseErr := version.Parse(opts.Version); opts.Dev || parseErr != nil || !cliVersion.IsRelease() { - url, path, conditionalGet = devUrl, dir.Join("api-docs-dev.json"), true + url, path = devUrl, dir.Join("api-docs-dev.json") } - return opts.download(ctx, url.URL, path, conditionalGet) + return opts.download(ctx, url.URL, path) } -// urlHash names one file per URL, because the conditional GET asks only for a document newer than the -// stored one: after a switch to the docs of an older meshStack, it would keep those of the newer one. func urlHash(url *gourl.URL) string { sum := sha256.Sum256([]byte(url.String())) return hex.EncodeToString(sum[:6]) } -func (opts Options) download(ctx context.Context, url *gourl.URL, path string, conditionalGet bool) (spec openapi.Spec, wait func(), err error) { - wait, err = opts.Client.Download(ctx, url, path, http.WithConditionalGet(conditionalGet)) +func (opts Options) download(ctx context.Context, url *gourl.URL, path string) (spec openapi.Spec, wait func(), err error) { + wait = func() {} + document, err := http.ReadAllBody(opts.Client.DoRequest(ctx, http.MethodGet, url)) if err != nil { return spec, wait, fmt.Errorf("cannot download the API docs from %s: %w", url, err) } - document, err := os.ReadFile(path) //nolint:gosec // G304: the path is the config directory's, joined above - if err != nil { + if err = os.WriteFile(path, document, 0o600); err != nil { //nolint:gosec // G703: the path is the config directory's, joined above return spec, wait, err } spec, err = openapi.Parse(bytes.NewReader(document)) if err != nil { - // Removed, because a conditional GET would keep it for good: a captive portal's page, say, - // stored with the time of its download, is newer than the document. - return spec, wait, fmt.Errorf("%s: %w, so it is removed for the next command to download again", - path, errors.Join(err, os.Remove(path))) + return spec, wait, fmt.Errorf("%s: %w", path, err) } return spec, wait, nil } diff --git a/internal/auth/cache.go b/internal/auth/cache.go index 3c9c3983..23b6b1a9 100644 --- a/internal/auth/cache.go +++ b/internal/auth/cache.go @@ -1,6 +1,7 @@ package auth import ( + "bytes" "context" "encoding/json/jsontext" "errors" @@ -142,7 +143,7 @@ func (c Credential) read(ctx context.Context) (matched bool, err error) { default: matched = true credential.WithCacheOf(c.Credential, func(cache reflect.Value) { - err = json.Unmarshal(file.Cache, cache.Addr().Interface()) + err = json.UnmarshalRead(bytes.NewReader(file.Cache), cache.Addr().Interface()) }) } return diff --git a/internal/auth/credential/apikey.go b/internal/auth/credential/apikey.go index cfc69195..2a31c0a2 100644 --- a/internal/auth/credential/apikey.go +++ b/internal/auth/credential/apikey.go @@ -46,12 +46,12 @@ func (apiKey *ApiKey) RefreshCachedToken(ctx context.Context, client http.Client ClientSecret string `json:"clientSecret"` }{apiKey.ClientId, apiKey.ClientSecret} - answer, err := client.DoRequest[struct { + answer, err := http.UnmarshalJsonBody[struct { AccessToken jwt.JWT `json:"access_token"` - }](ctx, http.MethodPost, loginEndpoint, - http.Retryable(), - http.WithJsonPayload(payload, "application/json"), - ) + }](client.DoRequest(ctx, http.MethodPost, loginEndpoint, + http.Retryable(http.RetryOnTransient), + http.WithJsonRequest(payload, "application/json"), + )) if httpError, ok := errors.AsType[http.Error](err); ok && httpError.IsUnauthorized() { return fmt.Errorf("api key %s at %s refused: %w; check the secret, or issue a new key in meshPanel", apiKey.ClientId, loginEndpoint, err) diff --git a/internal/auth/credential/identity.go b/internal/auth/credential/identity.go index b3eddb29..3686cb00 100644 --- a/internal/auth/credential/identity.go +++ b/internal/auth/credential/identity.go @@ -3,9 +3,10 @@ package credential import ( "crypto/sha256" "encoding/hex" - "encoding/json/v2" "fmt" "reflect" + + "github.com/meshcloud/meshstack-cli/internal/json" ) type Identity struct { diff --git a/internal/auth/login.go b/internal/auth/login.go index e49a19ab..1adf567b 100644 --- a/internal/auth/login.go +++ b/internal/auth/login.go @@ -35,10 +35,7 @@ func Login(ctx context.Context, withAuth credential.Name, opts ResolveSessionOpt if err != nil { return Session{}, nil, nil, err } - session, err := newSessionFor(ctx, currentProfile, opts) - if err != nil { - return Session{}, nil, nil, err - } + session := newSessionFor(ctx, currentProfile, opts) var creds profile.Credentials creds, err = session.CurrentProfile.Credentials(ctx) diff --git a/internal/auth/logout.go b/internal/auth/logout.go index 5add4c77..4827484b 100644 --- a/internal/auth/logout.go +++ b/internal/auth/logout.go @@ -36,11 +36,7 @@ func endSession(ctx context.Context, p *profile.Profile, oidcLogin *credential.O if oidcLogin.Cache == nil || oidcLogin.Cache.RefreshToken == "" { return errors.New("its refresh token is not cached") } - httpClient, err := opts.HttpClient() - if err != nil { - return err - } - oidcClient, err := oidc.NewClient(ctx, httpClient, oidcLogin.Issuer, oidcLogin.ClientId) + oidcClient, err := oidc.NewClient(ctx, opts.HttpClient(), oidcLogin.Issuer, oidcLogin.ClientId) if err != nil { return err } diff --git a/internal/auth/session.go b/internal/auth/session.go index 67ab0e5f..974e1393 100644 --- a/internal/auth/session.go +++ b/internal/auth/session.go @@ -45,10 +45,7 @@ func ResolveSession(ctx context.Context, opts ResolveSessionOptions) (Session, e if err != nil { return Session{}, err } - session, err := newSessionFor(ctx, currentProfile, opts) - if err != nil { - return Session{}, err - } + session := newSessionFor(ctx, currentProfile, opts) session.profiles = profiles resolved, err := session.resolveCredentials(ctx, opts) if err != nil { @@ -67,12 +64,10 @@ func ResolveSession(ctx context.Context, opts ResolveSessionOptions) (Session, e return session.withCredential(ctx, resolved, opts) } -// Scope names the profile, and the workspace where the settings choose it: only a browser login -// works in that workspace, while an API key works in the one that owns it. -func (s Session) Scope() string { - scope := "profile " + string(s.CurrentProfile.Name) +func (s Session) String() string { + scope := string(s.Credential.Name()) + " profile " + string(s.CurrentProfile.Name) if s.CurrentProfile.Name == "" { - scope = "endpoint " + s.CurrentProfile.Endpoint.String() + scope = string(s.Credential.Name()) + " for " + s.CurrentProfile.Endpoint.String() } if _, browserLogin := s.Credential.Credential.(*credential.OidcLogin); browserLogin { if workspace, err := s.getWorkspace(); err == nil && workspace != meshstack.NoWorkspace { @@ -83,10 +78,7 @@ func (s Session) Scope() string { } func StoredSession(ctx context.Context, p *profile.Profile, opts ResolveSessionOptions) (Session, error) { - session, err := newSessionFor(ctx, p, opts) - if err != nil { - return Session{}, err - } + session := newSessionFor(ctx, p, opts) stored, err := session.storedCredential(ctx, nil) if err != nil { return Session{}, err @@ -99,18 +91,12 @@ func StoredSession(ctx context.Context, p *profile.Profile, opts ResolveSessionO // HttpClient is for a request that the meshStack client does not make, such as the download of the // API docs. It carries the user agent of the front end, as the session's client does. -func (opts ResolveSessionOptions) HttpClient() (http.Client, error) { - if err := opts.Validate(); err != nil { - return http.Client{}, err - } - return http.NewClient(opts.UserAgent), nil +func (opts ResolveSessionOptions) HttpClient() http.Client { + return http.NewClient(opts.UserAgent) } -func newSessionFor(ctx context.Context, currentProfile *profile.Profile, opts ResolveSessionOptions) (Session, error) { - httpClient, err := opts.HttpClient() - if err != nil { - return Session{}, err - } +func newSessionFor(ctx context.Context, currentProfile *profile.Profile, opts ResolveSessionOptions) Session { + httpClient := opts.HttpClient() return Session{ CurrentProfile: currentProfile, httpClient: httpClient, @@ -121,7 +107,7 @@ func newSessionFor(ctx context.Context, currentProfile *profile.Profile, opts Re getWorkspace: func() (meshstack.Workspace, error) { return meshstack.NoWorkspace, nil }, - }, nil + } } func (s Session) withCredential(ctx context.Context, cred Credential, opts ResolveSessionOptions) (Session, error) { @@ -157,8 +143,8 @@ func (s Session) buildClient(ctx context.Context, opts ResolveSessionOptions) (c return client.Client{}, workspaceErr } endpoint := s.CurrentProfile.Endpoint - slog.DebugContext(ctx, fmt.Sprintf("Building client for endpoint %s with user agent %s authenticated by %s, workspace %s", - endpoint, s.httpClient.UserAgent, s.Credential.Name(), workspace)) + slog.DebugContext(ctx, fmt.Sprintf("Building client for endpoint %s from %s, authenticated by %s, workspace %s", + endpoint, s.httpClient, s.Credential.Name(), workspace)) c := client.New(ctx, endpoint, s.httpClient, s) if skipVersionCheck, err := opts.ResolveSetting(ctx, meshstack.SkipVersionCheckSetting); err != nil { return client.Client{}, err diff --git a/internal/auth/session_test.go b/internal/auth/session_test.go index c4675e76..185cf449 100644 --- a/internal/auth/session_test.go +++ b/internal/auth/session_test.go @@ -202,9 +202,8 @@ func setApiKeyEnv(t *testing.T, key fakemeshstack.ApiKey) { // ask brings its own http.Client, because the session keeps its own to itself. What these tests // drive is the authorization, which the session supplies either way. func ask(ctx context.Context, server *fakemeshstack.Server, session auth.Session) error { - _, err := http.NewClient(fakemeshstack.UserAgent).WithAuthorization(session). - DoRequest[[]byte](ctx, gohttp.MethodGet, must(url.Parse(server.URL+"/api/meshobjects/meshworkspaces"))) - return err + return http.IgnoreResponse(http.NewClient(fakemeshstack.UserAgent).WithAuthorization(session). + DoRequest(ctx, gohttp.MethodGet, must(url.Parse(server.URL+"/api/meshobjects/meshworkspaces")))) } func requireAnswer(t *testing.T, server *fakemeshstack.Server, session auth.Session) { diff --git a/internal/auth/status_test.go b/internal/auth/status_test.go index 1986a487..764a39ae 100644 --- a/internal/auth/status_test.go +++ b/internal/auth/status_test.go @@ -2,7 +2,6 @@ package auth_test import ( "encoding/base64" - "encoding/json/v2" "log/slog" "testing" "time" @@ -15,6 +14,7 @@ import ( "github.com/meshcloud/meshstack-cli/internal/auth" "github.com/meshcloud/meshstack-cli/internal/auth/credential" "github.com/meshcloud/meshstack-cli/internal/config" + "github.com/meshcloud/meshstack-cli/internal/json" "github.com/meshcloud/meshstack-cli/internal/logs" "github.com/meshcloud/meshstack-cli/internal/meshstack" "github.com/meshcloud/meshstack-cli/internal/oidc" @@ -62,7 +62,7 @@ func TestStatusOfABrowserLogin(t *testing.T) { session, err := auth.StoredSession(t.Context(), p, testSessionOpts) require.NoError(t, err) - assert.Equal(t, "profile dev working in workspace ops", session.Scope()) + assert.Equal(t, "oidcLogin profile dev working in workspace ops", session.String()) }) t.Run("lists the stored credentials besides the one in use", func(t *testing.T) { diff --git a/internal/auth/version_check.go b/internal/auth/version_check.go index 91ce02f0..4eccc47d 100644 --- a/internal/auth/version_check.go +++ b/internal/auth/version_check.go @@ -52,9 +52,9 @@ func warnIfNewerReleasePresent(ctx context.Context, configDir config.Directory, ctxRequest, cancel := context.WithTimeout(ctx, releaseCheckTimeout) defer cancel() apiUrl := xurl.MustParsef("https://api.github.com/repos/%s/releases/latest", opts.GitHubRepo) - latestRelease, err := client.DoRequest[struct { + latestRelease, err := http.UnmarshalJsonBody[struct { TagName string `json:"tag_name"` - }](ctxRequest, http.MethodGet, apiUrl.URL, http.Retryable()) + }](client.DoRequest(ctxRequest, http.MethodGet, apiUrl.URL, http.Retryable(http.RetryOnTransient))) if httpError, ok := errors.AsType[http.Error](err); ok && httpError.IsNotFound() { return fmt.Errorf("no latest release found at %s: %w", apiUrl, err) } else if err != nil { diff --git a/internal/json/marshal.go b/internal/json/marshal.go index 762bb4fe..e8dff6b5 100644 --- a/internal/json/marshal.go +++ b/internal/json/marshal.go @@ -6,24 +6,24 @@ import ( "encoding/json/v2" "errors" "fmt" + "io" "log/slog" "os" "path/filepath" ) -// wireCompatibility holds the output to the shape encoding/json v1 produced: a nil slice and a -// nil map go out as null rather than as [] and {}, and object members are sorted. json/v2 would -// write [] and {} and leave map order to chance, and neither change is ours to make — the -// meshObject API may read null and an empty collection differently on a PUT, and the Terraform -// provider hashes this JSON to decide whether a resource changed. -var wireCompatibility = json.JoinOptions( - json.Deterministic(true), - json.FormatNilSliceAsNull(true), - json.FormatNilMapAsNull(true), -) +type MarshalerTo = json.MarshalerTo + +func Marshal(in any, opts ...Options) ([]byte, error) { + return json.Marshal(in, opts...) +} + +func MarshalWrite(out io.Writer, in any, opts ...Options) error { + return json.MarshalWrite(out, in, opts...) +} -func Marshal(payload any) ([]byte, error) { - return json.Marshal(payload, wireCompatibility) +func MarshalEncode(out *jsontext.Encoder, in any, opts ...Options) error { + return json.MarshalEncode(out, in, opts...) } type MarshalOption func(opts *marshalOptions) @@ -67,6 +67,5 @@ func MarshalTo(ctx context.Context, file string, payload any, options ...Marshal slog.DebugContext(ctx, "Marshaled json to "+file) } }() - encoder := jsontext.NewEncoder(out, jsontext.WithIndent(" ")) - return json.MarshalEncode(encoder, payload, wireCompatibility) + return json.MarshalWrite(out, payload, json.Deterministic(true), jsontext.WithIndent(" ")) } diff --git a/internal/json/options.go b/internal/json/options.go new file mode 100644 index 00000000..685aee51 --- /dev/null +++ b/internal/json/options.go @@ -0,0 +1,40 @@ +package json + +import ( + "encoding/json/jsontext" + "encoding/json/v2" +) + +type ( + Options = json.Options + Unmarshalers = json.Unmarshalers +) + +func JoinOptions(opts ...Options) Options { + return json.JoinOptions(opts...) +} + +func Deterministic(v bool) Options { + return json.Deterministic(v) +} + +func FormatNilSliceAsNull(v bool) Options { + return json.FormatNilSliceAsNull(v) +} + +func FormatNilMapAsNull(v bool) Options { + return json.FormatNilMapAsNull(v) +} + +func WithUnmarshalers(unmarshalers ...*Unmarshalers) Options { + joined := json.JoinUnmarshalers(unmarshalers...) + if joined == nil { + // json/v2 dereferences a nil *Unmarshalers when it decodes into an any. + return nil + } + return json.WithUnmarshalers(joined) +} + +func UnmarshalFromFunc[T any](fn func(*jsontext.Decoder, T) error) *Unmarshalers { + return json.UnmarshalFromFunc(fn) +} diff --git a/internal/json/unmarshal.go b/internal/json/unmarshal.go index 34f241b8..45ae0735 100644 --- a/internal/json/unmarshal.go +++ b/internal/json/unmarshal.go @@ -6,15 +6,26 @@ import ( "encoding/json/v2" "errors" "fmt" + "io" "log/slog" "os" ) -func Unmarshal(in []byte, out any) error { - return json.Unmarshal(in, out) +type UnmarshalerFrom = json.UnmarshalerFrom + +func Unmarshal(in []byte, out any, opts ...Options) error { + return json.Unmarshal(in, out, opts...) +} + +func UnmarshalRead(in io.Reader, out any, opts ...Options) error { + return json.UnmarshalRead(in, out, opts...) +} + +func UnmarshalDecode(in *jsontext.Decoder, out any, opts ...Options) error { + return json.UnmarshalDecode(in, out, opts...) } -func UnmarshalFrom(ctx context.Context, file string, out any, unmarshalers ...*json.Unmarshalers) (err error) { +func UnmarshalFrom(ctx context.Context, file string, out any, opts ...Options) (err error) { var f *os.File //nolint:gosec // G304: internal/config builds every path here from the config dir and validated names f, err = os.Open(file) @@ -29,15 +40,12 @@ func UnmarshalFrom(ctx context.Context, file string, out any, unmarshalers ...*j slog.DebugContext(ctx, "Unmarshaled json from "+file) } }() - err = json.UnmarshalDecode(jsontext.NewDecoder(f), &out, - json.WithUnmarshalers(json.JoinUnmarshalers(unmarshalers...)), - ) - return + return UnmarshalRead(f, out, opts...) } -func ModifyAfterUnmarshal[T any](modifier func(target *T)) *json.Unmarshalers { +func ModifyAfterUnmarshal[T any](modifier func(target *T)) Options { var decoding bool - return json.UnmarshalFromFunc(func(decoder *jsontext.Decoder, t *T) error { + return WithUnmarshalers(UnmarshalFromFunc(func(decoder *jsontext.Decoder, t *T) error { if decoding { // The nested decode below dispatches here again, and json.JoinUnmarshalers reads // errors.ErrUnsupported as "leave this value to the default behavior". @@ -45,10 +53,10 @@ func ModifyAfterUnmarshal[T any](modifier func(target *T)) *json.Unmarshalers { } decoding = true defer func() { decoding = false }() - if err := json.UnmarshalDecode(decoder, t); err != nil { + if err := UnmarshalDecode(decoder, t); err != nil { return err } modifier(t) return nil - }) + })) } diff --git a/internal/oidc/client.go b/internal/oidc/client.go index 9b669660..460f35b2 100644 --- a/internal/oidc/client.go +++ b/internal/oidc/client.go @@ -1,9 +1,11 @@ package oidc import ( + "bytes" "context" "errors" "fmt" + "io" "log/slog" "net/url" "time" @@ -32,8 +34,8 @@ type ClientConfig struct { } func NewClient(ctx context.Context, httpClient http.Client, issuer xurl.URL, clientId string) (Client, error) { - clientConfig, err := httpClient.DoRequest[ClientConfig](ctx, http.MethodGet, - issuer.JoinPath(".well-known", "openid-configuration")) + clientConfig, err := http.UnmarshalJsonBody[ClientConfig](httpClient.DoRequest(ctx, http.MethodGet, + issuer.JoinPath(".well-known", "openid-configuration"))) if err != nil { return Client{}, err } @@ -92,12 +94,11 @@ func (c Client) RevokeRefreshToken(ctx context.Context, refreshToken string) err if c.RevocationEndpoint == nil { return fmt.Errorf("%s advertises no revocation_endpoint", c.Issuer) } - _, err := c.doPost[any](ctx, c.RevocationEndpoint.URL, map[string]any{ + return http.IgnoreResponse(c.post(ctx, c.RevocationEndpoint.URL, map[string]any{ "client_id": c.Id, "token": refreshToken, "token_type_hint": "refresh_token", - }) - return err + })) } func (c Client) requestToken(ctx context.Context, payload map[string]any) (Token, error) { @@ -109,16 +110,20 @@ func (c Client) requestToken(ctx context.Context, payload map[string]any) (Token return token, err } -func (c Client) doPost[R any](ctx context.Context, endpoint *url.URL, payload map[string]any) (result R, err error) { - result, err = c.DoRequest[R](ctx, http.MethodPost, endpoint, http.WithFormPayload(payload)) +func (c Client) doPost[R any](ctx context.Context, endpoint *url.URL, payload map[string]any) (R, error) { + return http.UnmarshalJsonBody[R](c.post(ctx, endpoint, payload)) +} + +func (c Client) post(ctx context.Context, endpoint *url.URL, payload map[string]any) (io.ReadCloser, error) { + body, err := c.DoRequest(ctx, http.MethodPost, endpoint, http.WithFormRequest(payload)) if httpErr, ok := errors.AsType[http.Error](err); ok { var protocolErr protocolError - if unmarshalErr := json.Unmarshal(httpErr.ResponseBody, &protocolErr); unmarshalErr != nil { - return result, errors.Join(httpErr, unmarshalErr) + if unmarshalErr := json.UnmarshalRead(bytes.NewReader(httpErr.ResponseBody), &protocolErr); unmarshalErr != nil { + return body, errors.Join(httpErr, unmarshalErr) } - return result, errors.Join(httpErr, protocolErr) + return body, errors.Join(httpErr, protocolErr) } - return + return body, err } type protocolError struct { diff --git a/internal/oidc/jwt/jwt.go b/internal/oidc/jwt/jwt.go index 638b98b3..68d33c8f 100644 --- a/internal/oidc/jwt/jwt.go +++ b/internal/oidc/jwt/jwt.go @@ -5,8 +5,9 @@ import ( "encoding" "encoding/base64" "encoding/json/jsontext" - "encoding/json/v2" "fmt" + + "github.com/meshcloud/meshstack-cli/internal/json" ) var ( @@ -33,7 +34,7 @@ func (jwt JWT) MarshalText() (text []byte, err error) { //goland:noinspection GoMixedReceiverTypes func (jwt *JWT) UnmarshalText(text []byte) error { - jwt.encoded = text + jwt.encoded = bytes.Clone(text) parts := bytes.Split(jwt.encoded, []byte(".")) if len(parts) != 3 { return fmt.Errorf("the access token is not a JWT: it has %d dot-separated parts rather than 3", len(parts)) diff --git a/internal/oidc/jwt/jwt_test.go b/internal/oidc/jwt/jwt_test.go index 3cbf16d8..f0000c13 100644 --- a/internal/oidc/jwt/jwt_test.go +++ b/internal/oidc/jwt/jwt_test.go @@ -2,13 +2,13 @@ package jwt import ( _ "embed" - "encoding/json/v2" "testing" "testing/synctest" "time" "github.com/stretchr/testify/assert" + "github.com/meshcloud/meshstack-cli/internal/json" "github.com/meshcloud/meshstack-cli/internal/meshstack" "github.com/meshcloud/meshstack-cli/internal/oidc/scope" "github.com/meshcloud/meshstack-cli/internal/testutil/jsontest" diff --git a/internal/testutil/fakemeshstack/fakemeshstack.go b/internal/testutil/fakemeshstack/fakemeshstack.go index 8bb6372c..3c67471e 100644 --- a/internal/testutil/fakemeshstack/fakemeshstack.go +++ b/internal/testutil/fakemeshstack/fakemeshstack.go @@ -12,7 +12,6 @@ package fakemeshstack import ( "bytes" "cmp" - "encoding/json/v2" "io" gohttp "net/http" "net/http/httptest" @@ -25,6 +24,7 @@ import ( "time" "github.com/meshcloud/meshstack-cli/client/http" + "github.com/meshcloud/meshstack-cli/internal/json" ) // DefaultVersion is at least client.MinMeshStackVersion, or the CLI refuses the backend. diff --git a/internal/testutil/fakemeshstack/keycloak.go b/internal/testutil/fakemeshstack/keycloak.go index f2f087a3..268500dc 100644 --- a/internal/testutil/fakemeshstack/keycloak.go +++ b/internal/testutil/fakemeshstack/keycloak.go @@ -4,12 +4,13 @@ import ( "crypto/rand" "crypto/sha256" "encoding/base64" - "encoding/json/v2" gohttp "net/http" "net/url" "strings" "sync" "time" + + "github.com/meshcloud/meshstack-cli/internal/json" ) const cliClientId = "meshstack-cli" diff --git a/internal/testutil/jsontest/jsontest.go b/internal/testutil/jsontest/jsontest.go index 34d41225..7baf1e25 100644 --- a/internal/testutil/jsontest/jsontest.go +++ b/internal/testutil/jsontest/jsontest.go @@ -1,6 +1,7 @@ package jsontest import ( + "bytes" "testing" "github.com/stretchr/testify/require" @@ -10,6 +11,6 @@ import ( func MustUnmarshal[T any](t *testing.T, in []byte) (out T) { t.Helper() - require.NoError(t, json.Unmarshal(in, &out)) + require.NoError(t, json.UnmarshalRead(bytes.NewReader(in), &out)) return } diff --git a/internal/tfstate/apiproxy/apiproxy.go b/internal/tfstate/apiproxy/apiproxy.go deleted file mode 100644 index 1bbc56ef..00000000 --- a/internal/tfstate/apiproxy/apiproxy.go +++ /dev/null @@ -1,37 +0,0 @@ -// Package apiproxy passes requests on to the meshStack API. It stands apart from internal/tfstate -// because httputil.ReverseProxy takes a transport rather than a client, and forbidigo keeps the -// transport to client/http and this package. -package apiproxy - -import ( - gohttp "net/http" - "net/http/httputil" - "net/url" - "strings" - - "github.com/meshcloud/meshstack-cli/client/http" -) - -// New replaces the Authorization a request came with by that of client, and passes a request -// without one on as it came. The User-Agent names the command first, as it built the request, and -// then the front end of client, through which it went. -func New(client http.AuthorizedClient, endpoint *url.URL, onError func(gohttp.ResponseWriter, *gohttp.Request, error)) gohttp.Handler { - proxy := &httputil.ReverseProxy{ - Rewrite: func(out *httputil.ProxyRequest) { - out.SetURL(endpoint) - out.Out.Header.Set("User-Agent", strings.TrimSpace(out.In.Header.Get("User-Agent")+" "+client.UserAgent.String())) - }, - Transport: client.Transport, - ErrorHandler: onError, - } - return gohttp.HandlerFunc(func(w gohttp.ResponseWriter, r *gohttp.Request) { - if r.Header.Get("Authorization") != "" { - r = r.Clone(r.Context()) - if err := client.Authorize(r); err != nil { - onError(w, r, err) - return - } - } - proxy.ServeHTTP(w, r) - }) -} diff --git a/internal/tfstate/buildingblock.go b/internal/tfstate/buildingblock.go index 8d49ef6b..d555ab49 100644 --- a/internal/tfstate/buildingblock.go +++ b/internal/tfstate/buildingblock.go @@ -2,11 +2,11 @@ package tfstate import ( "context" - "encoding/json/v2" "fmt" "uuid" "github.com/meshcloud/meshstack-cli/client" + "github.com/meshcloud/meshstack-cli/internal/json" ) type buildingBlock struct { diff --git a/internal/tfstate/lock.go b/internal/tfstate/lock.go index b5ec920f..7f25f203 100644 --- a/internal/tfstate/lock.go +++ b/internal/tfstate/lock.go @@ -2,7 +2,6 @@ package tfstate import ( "context" - "encoding/json/v2" "errors" "fmt" "time" @@ -10,6 +9,7 @@ import ( "github.com/meshcloud/meshstack-cli/client" "github.com/meshcloud/meshstack-cli/client/http" + "github.com/meshcloud/meshstack-cli/internal/json" ) type Lock struct { diff --git a/internal/tfstate/proxy.go b/internal/tfstate/proxy.go index 8d950847..5a77f150 100644 --- a/internal/tfstate/proxy.go +++ b/internal/tfstate/proxy.go @@ -5,13 +5,13 @@ import ( "crypto/rand" "crypto/subtle" "encoding/base64" - "encoding/json/v2" "errors" "fmt" "io" "log/slog" "net" gohttp "net/http" + "net/http/httputil" "net/url" "strconv" "sync" @@ -19,9 +19,9 @@ import ( "github.com/meshcloud/meshstack-cli/client/http" "github.com/meshcloud/meshstack-cli/internal/auth" + "github.com/meshcloud/meshstack-cli/internal/json" "github.com/meshcloud/meshstack-cli/internal/meshstack" "github.com/meshcloud/meshstack-cli/internal/profile" - "github.com/meshcloud/meshstack-cli/internal/tfstate/apiproxy" ) const ( @@ -168,8 +168,12 @@ func (p *Proxy) forward(w gohttp.ResponseWriter, r *gohttp.Request) { p.refuse(w, r, gohttp.StatusForbidden, fmt.Errorf("%w, so the command cannot %s %s", ErrReadOnlyApi, r.Method, r.URL.Path)) return } - apiproxy.New(p.Api, p.Endpoint, func(w gohttp.ResponseWriter, r *gohttp.Request, err error) { - p.fail(w, r, fmt.Errorf("cannot pass %s %s on to meshStack: %w", r.Method, r.URL.Path, err)) + (&httputil.ReverseProxy{ + Rewrite: func(out *httputil.ProxyRequest) { out.SetURL(p.Endpoint) }, + Transport: p.Api.ProxyTransport(), + ErrorHandler: func(w gohttp.ResponseWriter, r *gohttp.Request, err error) { + p.fail(w, r, fmt.Errorf("cannot pass %s %s on to meshStack: %w", r.Method, r.URL.Path, err)) + }, }).ServeHTTP(w, r) } diff --git a/internal/tfstate/proxy_test.go b/internal/tfstate/proxy_test.go index 890a5030..9537d652 100644 --- a/internal/tfstate/proxy_test.go +++ b/internal/tfstate/proxy_test.go @@ -39,8 +39,8 @@ type requester struct { } func (r requester) DoRequest(ctx context.Context, method, path string, opts ...http.RequestOption) ([]byte, error) { - return http.NewClient(fakemeshstack.UserAgent).WithAuthorization(http.BearerToken(fakemeshstack.Token)). - DoRequest[[]byte](ctx, method, r.endpoint.JoinPath(path), opts...) + return http.ReadAllBody(http.NewClient(fakemeshstack.UserAgent).WithAuthorization(http.BearerToken(fakemeshstack.Token)). + DoRequest(ctx, method, r.endpoint.JoinPath(path), opts...)) } type proxyUnderTest struct { @@ -347,9 +347,8 @@ func TestServeCountsTheRequestsUntilTheCommandEnds(t *testing.T) { var apiToken jwt.JWT require.NoError(t, apiToken.UnmarshalText([]byte(vars["MESHSTACK_API_TOKEN"])), "the provider since v0.26.0 takes only a JWT") assert.False(t, apiToken.GetClaim(jwt.ExpiryClaim).Expired(time.Hour)) - authorization := gohttp.Header{} - authorization.Set("Authorization", "Basic "+basicAuth(vars["TF_HTTP_USERNAME"], vars["TF_HTTP_PASSWORD"])) - served, err = http.NewClient(fakemeshstack.UserAgent).DoRequest[[]byte](t.Context(), http.MethodGet, address, http.WithHeaders(authorization)) + authorization := http.WithHeader("Authorization", "Basic "+basicAuth(vars["TF_HTTP_USERNAME"], vars["TF_HTTP_PASSWORD"])) + served, err = http.ReadAllBody(http.NewClient(fakemeshstack.UserAgent).DoRequest(t.Context(), http.MethodGet, address, authorization)) require.NoError(t, err) }) diff --git a/internal/tfstate/store.go b/internal/tfstate/store.go index a5430b84..91ba679f 100644 --- a/internal/tfstate/store.go +++ b/internal/tfstate/store.go @@ -4,13 +4,13 @@ package tfstate import ( "context" - "encoding/json/v2" + "encoding/json/jsontext" "errors" "fmt" - gohttp "net/http" "uuid" "github.com/meshcloud/meshstack-cli/client/http" + "github.com/meshcloud/meshstack-cli/internal/json" ) // ErrNoState is meshStack's 404, which tofu's http backend takes for a state not written yet. @@ -35,7 +35,7 @@ func NewStore(raw Requester, workspace string, buildingBlock uuid.UUID) Store { } func (s Store) Get(ctx context.Context) ([]byte, error) { - state, err := s.raw.DoRequest(ctx, http.MethodGet, s.path()) + state, err := s.do(ctx, http.MethodGet, s.path()) if httpErr, ok := errors.AsType[http.Error](err); ok && httpErr.IsNotFound() { return nil, ErrNoState } @@ -45,12 +45,12 @@ func (s Store) Get(ctx context.Context) ([]byte, error) { // Put and Delete send the ID of tofu's lock as tofu's http backend does, because meshStack refuses // a write without the ID of the lock it holds. func (s Store) Put(ctx context.Context, state []byte, lockId string) error { - _, err := s.raw.DoRequest(ctx, http.MethodPost, s.path(), withLockId(lockId, http.WithBody(state), jsonContent)...) + _, err := s.do(ctx, http.MethodPost, s.path(), withLockId(lockId, jsonBody(state)...)...) return s.wrap("store", err) } func (s Store) Delete(ctx context.Context, lockId string) error { - _, err := s.raw.DoRequest(ctx, http.MethodDelete, s.path(), withLockId(lockId)...) + _, err := s.do(ctx, http.MethodDelete, s.path(), withLockId(lockId)...) return s.wrap("delete", err) } @@ -61,24 +61,22 @@ func withLockId(lockId string, opts ...http.RequestOption) []http.RequestOption return append(opts, http.WithUrlQuery(map[string]string{"ID": lockId})) } -var jsonContent = http.WithHeaders(gohttp.Header{"Content-Type": {"application/json"}}) - // Lock and Unlock take tofu's lock info as tofu sends it. A Lock that meshStack refuses with 423 // is an [http.Error] that carries the lock info of the holder. func (s Store) Lock(ctx context.Context, info []byte) error { - _, err := s.raw.DoRequest(ctx, http.MethodPost, s.lockPath(), http.WithBody(info), jsonContent) + _, err := s.do(ctx, http.MethodPost, s.lockPath(), jsonBody(info)...) return s.wrap("lock", err) } // Unlock fails with a 423 of meshStack where meshStack holds a lock of another ID than the one in // info. func (s Store) Unlock(ctx context.Context, info []byte) error { - _, err := s.raw.DoRequest(ctx, http.MethodDelete, s.lockPath(), http.WithBody(info), jsonContent) + _, err := s.do(ctx, http.MethodDelete, s.lockPath(), jsonBody(info)...) return s.wrap("unlock", err) } func (s Store) ReadLock(ctx context.Context) (lock Lock, err error) { - read, err := s.raw.DoRequest(ctx, http.MethodGet, s.lockPath()) + read, err := s.do(ctx, http.MethodGet, s.lockPath()) if httpErr, ok := errors.AsType[http.Error](err); ok && httpErr.IsNotFound() { return lock, ErrNoLock } else if err != nil { @@ -87,6 +85,14 @@ func (s Store) ReadLock(ctx context.Context) (lock Lock, err error) { return lock, json.Unmarshal(read, &lock) } +func (s Store) do(ctx context.Context, method, path string, opts ...http.RequestOption) ([]byte, error) { + if method != http.MethodGet { + // A 423 goes back to tofu at once, which names the holder of the lock and waits itself. + opts = append(opts, http.Retryable(http.RetryOnBusy)) + } + return s.raw.DoRequest(ctx, method, path, opts...) +} + func (s Store) wrap(action string, err error) error { if err == nil { return nil @@ -103,3 +109,11 @@ func (s Store) path() string { func (s Store) lockPath() string { return s.path() + "/lock" } + +// jsonBody sends no body for an empty one, as tofu's force-unlock sends it. +func jsonBody(body []byte) []http.RequestOption { + if len(body) == 0 { + return nil + } + return []http.RequestOption{http.WithJsonRequest(jsontext.Value(body), "")} +}