From c182e02e228a2a6ef60eac8aae3f4dbbe4172409 Mon Sep 17 00:00:00 2001 From: Alex Guerrieri Date: Fri, 29 Nov 2024 12:23:13 +0100 Subject: [PATCH 1/4] Update deps --- go.mod | 2 +- go.sum | 4 +- go.work.sum | 3 + proto/authcontrol.errors.ridl | 14 + proto/errors.ridl | 17 ++ proto/proto.go | 4 +- proto/quotacontrol.gen.go | 499 +++++++++++++++++++--------------- proto/quotacontrol.gen.ts | 108 +++++++- proto/quotacontrol.ridl | 27 +- scripts/import.sh | 21 +- tools/go.mod | 6 +- tools/go.sum | 12 +- 12 files changed, 442 insertions(+), 275 deletions(-) create mode 100644 proto/authcontrol.errors.ridl create mode 100644 proto/errors.ridl diff --git a/go.mod b/go.mod index 79b0229..6d78e29 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.23.2 // replace github.com/0xsequence/authcontrol => ../authcontrol require ( - github.com/0xsequence/authcontrol v0.3.2 + github.com/0xsequence/authcontrol v0.3.3 github.com/0xsequence/go-sequence v0.43.0 github.com/alicebob/miniredis/v2 v2.33.0 github.com/go-chi/chi/v5 v5.1.0 diff --git a/go.sum b/go.sum index 4615dee..055ed64 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/0xsequence/authcontrol v0.3.2 h1:oiLR2fNVEpeJu3SF1cWHQORRAVs1fRj/K+wRe/OJ5Mo= -github.com/0xsequence/authcontrol v0.3.2/go.mod h1:wicKJcmJYJU6jn07JBMqwxcAzyFm2BtfAzWpnL/40g8= +github.com/0xsequence/authcontrol v0.3.3 h1:aGRukGP/PFwrvKBXsjuMhxiXnqjHa+fchL+QwKQJgTU= +github.com/0xsequence/authcontrol v0.3.3/go.mod h1:wicKJcmJYJU6jn07JBMqwxcAzyFm2BtfAzWpnL/40g8= github.com/0xsequence/ethkit v1.28.0 h1:11p4UXXvYnixQk01+qmAcOF71N9DlSeMcEMbaCPtjaY= github.com/0xsequence/ethkit v1.28.0/go.mod h1:rv0FAIyEyN0hhwGefbduAz4ujmyjyJXhCd6a0/yF3tk= github.com/0xsequence/go-sequence v0.43.0 h1:PErMuTg4PeaamJutEJ6tAjrFBA8z0t6lvT9LOVC5RMs= diff --git a/go.work.sum b/go.work.sum index 3f73a78..478acbb 100644 --- a/go.work.sum +++ b/go.work.sum @@ -83,8 +83,11 @@ github.com/supranational/blst v0.3.12/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3 github.com/supranational/blst v0.3.13/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U= github.com/webrpc/gen-golang v0.15.0/go.mod h1:qy1qEWMlTvrRzjSuQLy+176RqNaX1ymUULDtlo7Dapo= +github.com/webrpc/gen-golang v0.17.0/go.mod h1:qy1qEWMlTvrRzjSuQLy+176RqNaX1ymUULDtlo7Dapo= github.com/webrpc/gen-typescript v0.14.1/go.mod h1:xQzYnVaSMfcygDXA5SuW8eYyCLHBHkj15wCF7gcJF5Y= +github.com/webrpc/gen-typescript v0.16.1/go.mod h1:xQzYnVaSMfcygDXA5SuW8eYyCLHBHkj15wCF7gcJF5Y= github.com/webrpc/webrpc v0.20.3/go.mod h1:nplt2iyIXMsMCGyQx1NgEXwQOifWqKNLXcFnQnG9dBU= +github.com/webrpc/webrpc v0.22.0/go.mod h1:eeABnLz9BC4F9GGw6UKebVPkzkFYLrZRlcOvh6o8n10= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= go.opentelemetry.io/contrib/detectors/gcp v1.29.0/go.mod h1:GW2aWZNwR2ZxDLdv8OyC2G8zkRoQBuURgV7RPQgcPoU= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0/go.mod h1:B9yO6b04uB80CzjedvewuqDhxJxi11s7/GtiGa8bAjI= diff --git a/proto/authcontrol.errors.ridl b/proto/authcontrol.errors.ridl new file mode 100644 index 0000000..0a81f86 --- /dev/null +++ b/proto/authcontrol.errors.ridl @@ -0,0 +1,14 @@ +webrpc = v1 + +name = authcontrol +version = v0.9.1 + +error 1000 Unauthorized "Unauthorized access" HTTP 401 +error 1001 PermissionDenied "Permission denied" HTTP 403 +error 1002 SessionExpired "Session expired" HTTP 403 +error 1003 MethodNotFound "Method not found" HTTP 404 +error 1004 RequestConflict "Conflict with target resource" HTTP 409 +error 1005 Aborted "Request aborted" HTTP 400 +error 1006 Geoblocked "Geoblocked region" HTTP 451 +error 1007 RateLimited "Rate-limited. Please slow down." HTTP 429 +error 1008 ProjectNotFound "Project not found" HTTP 401 diff --git a/proto/errors.ridl b/proto/errors.ridl new file mode 100644 index 0000000..26f23cc --- /dev/null +++ b/proto/errors.ridl @@ -0,0 +1,17 @@ +webrpc = v1 + +# 1100-1199: AccessKey/Project errors +error 1101 AccessKeyNotFound "Access key not found" HTTP 401 +error 1102 AccessKeyMismatch "Access key mismatch" HTTP 409 +error 1103 InvalidOrigin "Invalid origin for Access Key" HTTP 403 +error 1104 InvalidService "Service not enabled for Access key" HTTP 403 +error 1105 UnauthorizedUser "Unauthorized user" HTTP 403 +# 1200-1299: Limit errors +error 1200 QuotaExceeded "Quota request exceeded" HTTP 429 +error 1201 QuotaRateLimit "Quota rate limit exceeded" HTTP 429 +# 1300-1399: Access Key management errors +error 1300 NoDefaultKey "No default access key found" HTTP 403 +error 1301 MaxAccessKeys "Access keys limit reached" HTTP 403 +error 1302 AtLeastOneKey "You need at least one Access Key" HTTP 403 +# 1900-1999: Other errors +error 1900 Timeout "Request timed out" HTTP 408 diff --git a/proto/proto.go b/proto/proto.go index 2b418f6..83a32e6 100644 --- a/proto/proto.go +++ b/proto/proto.go @@ -1,5 +1,5 @@ -//go:generate go run github.com/webrpc/webrpc/cmd/webrpc-gen -schema=quotacontrol.ridl -target=golang@v0.15.0 -pkg=proto -server -client -out=./quotacontrol.gen.go -//go:generate go run github.com/webrpc/webrpc/cmd/webrpc-gen -schema=quotacontrol.ridl -target=typescript@v0.12.0 -client -out=./quotacontrol.gen.ts +//go:generate go run github.com/webrpc/webrpc/cmd/webrpc-gen -schema=quotacontrol.ridl -target=golang@v0.17.0 -pkg=proto -server -client -out=./quotacontrol.gen.go +//go:generate go run github.com/webrpc/webrpc/cmd/webrpc-gen -schema=quotacontrol.ridl -target=typescript@v0.16.1 -client -out=./quotacontrol.gen.ts package proto import ( diff --git a/proto/quotacontrol.gen.go b/proto/quotacontrol.gen.go index a7d6a51..2a11d5c 100644 --- a/proto/quotacontrol.gen.go +++ b/proto/quotacontrol.gen.go @@ -1,8 +1,8 @@ -// quota-control v0.17.1 89525de9ce8be62e64504eb077da5ae84ca0627e +// quota-control v0.17.1 32a02107e877876adc13bfa09c2fd16a52efed07 // -- -// Code generated by webrpc-gen@v0.21.0 with golang@v0.15.0 generator. DO NOT EDIT. +// Code generated by webrpc-gen@v0.22.0 with golang@v0.17.0 generator. DO NOT EDIT. // -// webrpc-gen -schema=quotacontrol.ridl -target=golang@v0.15.0 -pkg=proto -server -client -out=./quotacontrol.gen.go +// webrpc-gen -schema=quotacontrol.ridl -target=golang@v0.17.0 -pkg=proto -server -client -out=./quotacontrol.gen.go package proto import ( @@ -21,6 +21,10 @@ import ( "github.com/goware/validation" ) +const WebrpcHeader = "Webrpc" + +const WebrpcHeaderValue = "webrpc@v0.22.0;gen-golang@v0.17.0;quota-control@v0.17.1" + // WebRPC description and code-gen version func WebRPCVersion() string { return "v1" @@ -33,7 +37,58 @@ func WebRPCSchemaVersion() string { // Schema hash generated from your RIDL schema func WebRPCSchemaHash() string { - return "89525de9ce8be62e64504eb077da5ae84ca0627e" + return "32a02107e877876adc13bfa09c2fd16a52efed07" +} + +type WebrpcGenVersions struct { + WebrpcGenVersion string + CodeGenName string + CodeGenVersion string + SchemaName string + SchemaVersion string +} + +func VersionFromHeader(h http.Header) (*WebrpcGenVersions, error) { + if h.Get(WebrpcHeader) == "" { + return nil, fmt.Errorf("header is empty or missing") + } + + versions, err := parseWebrpcGenVersions(h.Get(WebrpcHeader)) + if err != nil { + return nil, fmt.Errorf("webrpc header is invalid: %w", err) + } + + return versions, nil +} + +func parseWebrpcGenVersions(header string) (*WebrpcGenVersions, error) { + versions := strings.Split(header, ";") + if len(versions) < 3 { + return nil, fmt.Errorf("expected at least 3 parts while parsing webrpc header: %v", header) + } + + _, webrpcGenVersion, ok := strings.Cut(versions[0], "@") + if !ok { + return nil, fmt.Errorf("webrpc gen version could not be parsed from: %s", versions[0]) + } + + tmplTarget, tmplVersion, ok := strings.Cut(versions[1], "@") + if !ok { + return nil, fmt.Errorf("tmplTarget and tmplVersion could not be parsed from: %s", versions[1]) + } + + schemaName, schemaVersion, ok := strings.Cut(versions[2], "@") + if !ok { + return nil, fmt.Errorf("schema name and schema version could not be parsed from: %s", versions[2]) + } + + return &WebrpcGenVersions{ + WebrpcGenVersion: webrpcGenVersion, + CodeGenName: tmplTarget, + CodeGenVersion: tmplVersion, + SchemaName: schemaName, + SchemaVersion: schemaVersion, + }, nil } // @@ -255,120 +310,127 @@ type ResourceAccess struct { Minter *Minter `json:"minter"` } -var ( - methods = map[string]method{ - "/rpc/QuotaControl/GetProjectStatus": { - Name: "GetProjectStatus", - Service: "QuotaControl", - Annotations: map[string]string{}, - }, - "/rpc/QuotaControl/GetAccessKey": { - Name: "GetAccessKey", - Service: "QuotaControl", - Annotations: map[string]string{}, - }, - "/rpc/QuotaControl/GetDefaultAccessKey": { - Name: "GetDefaultAccessKey", - Service: "QuotaControl", - Annotations: map[string]string{}, - }, - "/rpc/QuotaControl/CreateAccessKey": { - Name: "CreateAccessKey", - Service: "QuotaControl", - Annotations: map[string]string{}, - }, - "/rpc/QuotaControl/RotateAccessKey": { - Name: "RotateAccessKey", - Service: "QuotaControl", - Annotations: map[string]string{}, - }, - "/rpc/QuotaControl/UpdateAccessKey": { - Name: "UpdateAccessKey", - Service: "QuotaControl", - Annotations: map[string]string{}, - }, - "/rpc/QuotaControl/UpdateDefaultAccessKey": { - Name: "UpdateDefaultAccessKey", - Service: "QuotaControl", - Annotations: map[string]string{}, - }, - "/rpc/QuotaControl/ListAccessKeys": { - Name: "ListAccessKeys", - Service: "QuotaControl", - Annotations: map[string]string{}, - }, - "/rpc/QuotaControl/DisableAccessKey": { - Name: "DisableAccessKey", - Service: "QuotaControl", - Annotations: map[string]string{}, - }, - "/rpc/QuotaControl/GetProjectQuota": { - Name: "GetProjectQuota", - Service: "QuotaControl", - Annotations: map[string]string{}, - }, - "/rpc/QuotaControl/GetAccessQuota": { - Name: "GetAccessQuota", - Service: "QuotaControl", - Annotations: map[string]string{}, - }, - "/rpc/QuotaControl/ClearAccessQuotaCache": { - Name: "ClearAccessQuotaCache", - Service: "QuotaControl", - Annotations: map[string]string{}, - }, - "/rpc/QuotaControl/GetAccountUsage": { - Name: "GetAccountUsage", - Service: "QuotaControl", - Annotations: map[string]string{}, - }, - "/rpc/QuotaControl/GetAccessKeyUsage": { - Name: "GetAccessKeyUsage", - Service: "QuotaControl", - Annotations: map[string]string{}, - }, - "/rpc/QuotaControl/GetAsyncUsage": { - Name: "GetAsyncUsage", - Service: "QuotaControl", - Annotations: map[string]string{}, - }, - "/rpc/QuotaControl/PrepareUsage": { - Name: "PrepareUsage", - Service: "QuotaControl", - Annotations: map[string]string{}, - }, - "/rpc/QuotaControl/ClearUsage": { - Name: "ClearUsage", - Service: "QuotaControl", - Annotations: map[string]string{}, - }, - "/rpc/QuotaControl/NotifyEvent": { - Name: "NotifyEvent", - Service: "QuotaControl", - Annotations: map[string]string{}, - }, - "/rpc/QuotaControl/UpdateProjectUsage": { - Name: "UpdateProjectUsage", - Service: "QuotaControl", - Annotations: map[string]string{}, - }, - "/rpc/QuotaControl/UpdateKeyUsage": { - Name: "UpdateKeyUsage", - Service: "QuotaControl", - Annotations: map[string]string{}, - }, - "/rpc/QuotaControl/UpdateUsage": { - Name: "UpdateUsage", - Service: "QuotaControl", - Annotations: map[string]string{}, - }, - "/rpc/QuotaControl/GetUserPermission": { - Name: "GetUserPermission", - Service: "QuotaControl", - Annotations: map[string]string{}, - }, +var methods = map[string]method{ + "/rpc/QuotaControl/GetProjectStatus": { + Name: "GetProjectStatus", + Service: "QuotaControl", + Annotations: map[string]string{}, + }, + "/rpc/QuotaControl/GetAccessKey": { + Name: "GetAccessKey", + Service: "QuotaControl", + Annotations: map[string]string{}, + }, + "/rpc/QuotaControl/GetDefaultAccessKey": { + Name: "GetDefaultAccessKey", + Service: "QuotaControl", + Annotations: map[string]string{}, + }, + "/rpc/QuotaControl/CreateAccessKey": { + Name: "CreateAccessKey", + Service: "QuotaControl", + Annotations: map[string]string{}, + }, + "/rpc/QuotaControl/RotateAccessKey": { + Name: "RotateAccessKey", + Service: "QuotaControl", + Annotations: map[string]string{}, + }, + "/rpc/QuotaControl/UpdateAccessKey": { + Name: "UpdateAccessKey", + Service: "QuotaControl", + Annotations: map[string]string{}, + }, + "/rpc/QuotaControl/UpdateDefaultAccessKey": { + Name: "UpdateDefaultAccessKey", + Service: "QuotaControl", + Annotations: map[string]string{}, + }, + "/rpc/QuotaControl/ListAccessKeys": { + Name: "ListAccessKeys", + Service: "QuotaControl", + Annotations: map[string]string{}, + }, + "/rpc/QuotaControl/DisableAccessKey": { + Name: "DisableAccessKey", + Service: "QuotaControl", + Annotations: map[string]string{}, + }, + "/rpc/QuotaControl/GetProjectQuota": { + Name: "GetProjectQuota", + Service: "QuotaControl", + Annotations: map[string]string{}, + }, + "/rpc/QuotaControl/GetAccessQuota": { + Name: "GetAccessQuota", + Service: "QuotaControl", + Annotations: map[string]string{}, + }, + "/rpc/QuotaControl/ClearAccessQuotaCache": { + Name: "ClearAccessQuotaCache", + Service: "QuotaControl", + Annotations: map[string]string{}, + }, + "/rpc/QuotaControl/GetAccountUsage": { + Name: "GetAccountUsage", + Service: "QuotaControl", + Annotations: map[string]string{}, + }, + "/rpc/QuotaControl/GetAccessKeyUsage": { + Name: "GetAccessKeyUsage", + Service: "QuotaControl", + Annotations: map[string]string{}, + }, + "/rpc/QuotaControl/GetAsyncUsage": { + Name: "GetAsyncUsage", + Service: "QuotaControl", + Annotations: map[string]string{}, + }, + "/rpc/QuotaControl/PrepareUsage": { + Name: "PrepareUsage", + Service: "QuotaControl", + Annotations: map[string]string{}, + }, + "/rpc/QuotaControl/ClearUsage": { + Name: "ClearUsage", + Service: "QuotaControl", + Annotations: map[string]string{}, + }, + "/rpc/QuotaControl/NotifyEvent": { + Name: "NotifyEvent", + Service: "QuotaControl", + Annotations: map[string]string{}, + }, + "/rpc/QuotaControl/UpdateProjectUsage": { + Name: "UpdateProjectUsage", + Service: "QuotaControl", + Annotations: map[string]string{}, + }, + "/rpc/QuotaControl/UpdateKeyUsage": { + Name: "UpdateKeyUsage", + Service: "QuotaControl", + Annotations: map[string]string{}, + }, + "/rpc/QuotaControl/UpdateUsage": { + Name: "UpdateUsage", + Service: "QuotaControl", + Annotations: map[string]string{}, + }, + "/rpc/QuotaControl/GetUserPermission": { + Name: "GetUserPermission", + Service: "QuotaControl", + Annotations: map[string]string{}, + }, +} + +func WebrpcMethods() map[string]method { + res := make(map[string]method, len(methods)) + for k, v := range methods { + res[k] = v } -) + + return res +} var WebRPCServices = map[string][]string{ "QuotaControl": { @@ -489,11 +551,13 @@ func (s *quotaControlServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { defer func() { // In case of a panic, serve a HTTP 500 error and then panic. if rr := recover(); rr != nil { - s.sendErrorJSON(w, r, ErrWebrpcServerPanic.WithCause(fmt.Errorf("%v", rr))) + s.sendErrorJSON(w, r, ErrWebrpcServerPanic.WithCausef("%v", rr)) panic(rr) } }() + w.Header().Set(WebrpcHeader, WebrpcHeaderValue) + ctx := r.Context() ctx = context.WithValue(ctx, HTTPResponseWriterCtxKey, w) ctx = context.WithValue(ctx, HTTPRequestCtxKey, r) @@ -548,14 +612,14 @@ func (s *quotaControlServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { case "/rpc/QuotaControl/GetUserPermission": handler = s.serveGetUserPermissionJSON default: - err := ErrWebrpcBadRoute.WithCause(fmt.Errorf("no WebRPC method defined for path %v", r.URL.Path)) + err := ErrWebrpcBadRoute.WithCausef("no webrpc method defined for path %v", r.URL.Path) s.sendErrorJSON(w, r, err) return } if r.Method != "POST" { w.Header().Add("Allow", "POST") // RFC 9110. - err := ErrWebrpcBadMethod.WithCause(fmt.Errorf("unsupported method %v (only POST is allowed)", r.Method)) + err := ErrWebrpcBadMethod.WithCausef("unsupported HTTP method %v (only POST is allowed)", r.Method) s.sendErrorJSON(w, r, err) return } @@ -581,7 +645,7 @@ func (s *quotaControlServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { handler(ctx, w, r) default: - err := ErrWebrpcBadRequest.WithCause(fmt.Errorf("unsupported Content-Type %q (only application/json is allowed)", r.Header.Get("Content-Type"))) + err := ErrWebrpcBadRequest.WithCausef("unsupported Content-Type %q (only application/json is allowed)", r.Header.Get("Content-Type")) s.sendErrorJSON(w, r, err) } } @@ -591,7 +655,7 @@ func (s *quotaControlServer) serveGetProjectStatusJSON(ctx context.Context, w ht reqBody, err := io.ReadAll(r.Body) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to read request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to read request data: %w", err)) return } defer r.Body.Close() @@ -600,7 +664,7 @@ func (s *quotaControlServer) serveGetProjectStatusJSON(ctx context.Context, w ht Arg0 uint64 `json:"projectId"` }{} if err := json.Unmarshal(reqBody, &reqPayload); err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to unmarshal request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to unmarshal request data: %w", err)) return } @@ -620,7 +684,7 @@ func (s *quotaControlServer) serveGetProjectStatusJSON(ctx context.Context, w ht }{ret0} respBody, err := json.Marshal(respPayload) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to marshal json response: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCausef("failed to marshal json response: %w", err)) return } @@ -634,7 +698,7 @@ func (s *quotaControlServer) serveGetAccessKeyJSON(ctx context.Context, w http.R reqBody, err := io.ReadAll(r.Body) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to read request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to read request data: %w", err)) return } defer r.Body.Close() @@ -643,7 +707,7 @@ func (s *quotaControlServer) serveGetAccessKeyJSON(ctx context.Context, w http.R Arg0 string `json:"accessKey"` }{} if err := json.Unmarshal(reqBody, &reqPayload); err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to unmarshal request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to unmarshal request data: %w", err)) return } @@ -663,7 +727,7 @@ func (s *quotaControlServer) serveGetAccessKeyJSON(ctx context.Context, w http.R }{ret0} respBody, err := json.Marshal(respPayload) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to marshal json response: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCausef("failed to marshal json response: %w", err)) return } @@ -677,7 +741,7 @@ func (s *quotaControlServer) serveGetDefaultAccessKeyJSON(ctx context.Context, w reqBody, err := io.ReadAll(r.Body) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to read request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to read request data: %w", err)) return } defer r.Body.Close() @@ -686,7 +750,7 @@ func (s *quotaControlServer) serveGetDefaultAccessKeyJSON(ctx context.Context, w Arg0 uint64 `json:"projectID"` }{} if err := json.Unmarshal(reqBody, &reqPayload); err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to unmarshal request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to unmarshal request data: %w", err)) return } @@ -706,7 +770,7 @@ func (s *quotaControlServer) serveGetDefaultAccessKeyJSON(ctx context.Context, w }{ret0} respBody, err := json.Marshal(respPayload) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to marshal json response: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCausef("failed to marshal json response: %w", err)) return } @@ -720,7 +784,7 @@ func (s *quotaControlServer) serveCreateAccessKeyJSON(ctx context.Context, w htt reqBody, err := io.ReadAll(r.Body) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to read request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to read request data: %w", err)) return } defer r.Body.Close() @@ -732,7 +796,7 @@ func (s *quotaControlServer) serveCreateAccessKeyJSON(ctx context.Context, w htt Arg3 []Service `json:"allowedServices"` }{} if err := json.Unmarshal(reqBody, &reqPayload); err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to unmarshal request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to unmarshal request data: %w", err)) return } @@ -752,7 +816,7 @@ func (s *quotaControlServer) serveCreateAccessKeyJSON(ctx context.Context, w htt }{ret0} respBody, err := json.Marshal(respPayload) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to marshal json response: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCausef("failed to marshal json response: %w", err)) return } @@ -766,7 +830,7 @@ func (s *quotaControlServer) serveRotateAccessKeyJSON(ctx context.Context, w htt reqBody, err := io.ReadAll(r.Body) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to read request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to read request data: %w", err)) return } defer r.Body.Close() @@ -775,7 +839,7 @@ func (s *quotaControlServer) serveRotateAccessKeyJSON(ctx context.Context, w htt Arg0 string `json:"accessKey"` }{} if err := json.Unmarshal(reqBody, &reqPayload); err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to unmarshal request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to unmarshal request data: %w", err)) return } @@ -795,7 +859,7 @@ func (s *quotaControlServer) serveRotateAccessKeyJSON(ctx context.Context, w htt }{ret0} respBody, err := json.Marshal(respPayload) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to marshal json response: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCausef("failed to marshal json response: %w", err)) return } @@ -809,7 +873,7 @@ func (s *quotaControlServer) serveUpdateAccessKeyJSON(ctx context.Context, w htt reqBody, err := io.ReadAll(r.Body) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to read request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to read request data: %w", err)) return } defer r.Body.Close() @@ -821,7 +885,7 @@ func (s *quotaControlServer) serveUpdateAccessKeyJSON(ctx context.Context, w htt Arg3 []Service `json:"allowedServices"` }{} if err := json.Unmarshal(reqBody, &reqPayload); err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to unmarshal request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to unmarshal request data: %w", err)) return } @@ -841,7 +905,7 @@ func (s *quotaControlServer) serveUpdateAccessKeyJSON(ctx context.Context, w htt }{ret0} respBody, err := json.Marshal(respPayload) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to marshal json response: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCausef("failed to marshal json response: %w", err)) return } @@ -855,7 +919,7 @@ func (s *quotaControlServer) serveUpdateDefaultAccessKeyJSON(ctx context.Context reqBody, err := io.ReadAll(r.Body) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to read request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to read request data: %w", err)) return } defer r.Body.Close() @@ -865,7 +929,7 @@ func (s *quotaControlServer) serveUpdateDefaultAccessKeyJSON(ctx context.Context Arg1 string `json:"accessKey"` }{} if err := json.Unmarshal(reqBody, &reqPayload); err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to unmarshal request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to unmarshal request data: %w", err)) return } @@ -885,7 +949,7 @@ func (s *quotaControlServer) serveUpdateDefaultAccessKeyJSON(ctx context.Context }{ret0} respBody, err := json.Marshal(respPayload) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to marshal json response: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCausef("failed to marshal json response: %w", err)) return } @@ -899,7 +963,7 @@ func (s *quotaControlServer) serveListAccessKeysJSON(ctx context.Context, w http reqBody, err := io.ReadAll(r.Body) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to read request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to read request data: %w", err)) return } defer r.Body.Close() @@ -910,7 +974,7 @@ func (s *quotaControlServer) serveListAccessKeysJSON(ctx context.Context, w http Arg2 *Service `json:"service"` }{} if err := json.Unmarshal(reqBody, &reqPayload); err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to unmarshal request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to unmarshal request data: %w", err)) return } @@ -930,7 +994,7 @@ func (s *quotaControlServer) serveListAccessKeysJSON(ctx context.Context, w http }{ret0} respBody, err := json.Marshal(respPayload) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to marshal json response: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCausef("failed to marshal json response: %w", err)) return } @@ -944,7 +1008,7 @@ func (s *quotaControlServer) serveDisableAccessKeyJSON(ctx context.Context, w ht reqBody, err := io.ReadAll(r.Body) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to read request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to read request data: %w", err)) return } defer r.Body.Close() @@ -953,7 +1017,7 @@ func (s *quotaControlServer) serveDisableAccessKeyJSON(ctx context.Context, w ht Arg0 string `json:"accessKey"` }{} if err := json.Unmarshal(reqBody, &reqPayload); err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to unmarshal request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to unmarshal request data: %w", err)) return } @@ -973,7 +1037,7 @@ func (s *quotaControlServer) serveDisableAccessKeyJSON(ctx context.Context, w ht }{ret0} respBody, err := json.Marshal(respPayload) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to marshal json response: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCausef("failed to marshal json response: %w", err)) return } @@ -987,7 +1051,7 @@ func (s *quotaControlServer) serveGetProjectQuotaJSON(ctx context.Context, w htt reqBody, err := io.ReadAll(r.Body) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to read request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to read request data: %w", err)) return } defer r.Body.Close() @@ -997,7 +1061,7 @@ func (s *quotaControlServer) serveGetProjectQuotaJSON(ctx context.Context, w htt Arg1 time.Time `json:"now"` }{} if err := json.Unmarshal(reqBody, &reqPayload); err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to unmarshal request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to unmarshal request data: %w", err)) return } @@ -1017,7 +1081,7 @@ func (s *quotaControlServer) serveGetProjectQuotaJSON(ctx context.Context, w htt }{ret0} respBody, err := json.Marshal(respPayload) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to marshal json response: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCausef("failed to marshal json response: %w", err)) return } @@ -1031,7 +1095,7 @@ func (s *quotaControlServer) serveGetAccessQuotaJSON(ctx context.Context, w http reqBody, err := io.ReadAll(r.Body) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to read request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to read request data: %w", err)) return } defer r.Body.Close() @@ -1041,7 +1105,7 @@ func (s *quotaControlServer) serveGetAccessQuotaJSON(ctx context.Context, w http Arg1 time.Time `json:"now"` }{} if err := json.Unmarshal(reqBody, &reqPayload); err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to unmarshal request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to unmarshal request data: %w", err)) return } @@ -1061,7 +1125,7 @@ func (s *quotaControlServer) serveGetAccessQuotaJSON(ctx context.Context, w http }{ret0} respBody, err := json.Marshal(respPayload) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to marshal json response: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCausef("failed to marshal json response: %w", err)) return } @@ -1075,7 +1139,7 @@ func (s *quotaControlServer) serveClearAccessQuotaCacheJSON(ctx context.Context, reqBody, err := io.ReadAll(r.Body) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to read request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to read request data: %w", err)) return } defer r.Body.Close() @@ -1084,7 +1148,7 @@ func (s *quotaControlServer) serveClearAccessQuotaCacheJSON(ctx context.Context, Arg0 uint64 `json:"projectID"` }{} if err := json.Unmarshal(reqBody, &reqPayload); err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to unmarshal request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to unmarshal request data: %w", err)) return } @@ -1104,7 +1168,7 @@ func (s *quotaControlServer) serveClearAccessQuotaCacheJSON(ctx context.Context, }{ret0} respBody, err := json.Marshal(respPayload) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to marshal json response: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCausef("failed to marshal json response: %w", err)) return } @@ -1118,7 +1182,7 @@ func (s *quotaControlServer) serveGetAccountUsageJSON(ctx context.Context, w htt reqBody, err := io.ReadAll(r.Body) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to read request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to read request data: %w", err)) return } defer r.Body.Close() @@ -1130,7 +1194,7 @@ func (s *quotaControlServer) serveGetAccountUsageJSON(ctx context.Context, w htt Arg3 *time.Time `json:"to"` }{} if err := json.Unmarshal(reqBody, &reqPayload); err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to unmarshal request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to unmarshal request data: %w", err)) return } @@ -1150,7 +1214,7 @@ func (s *quotaControlServer) serveGetAccountUsageJSON(ctx context.Context, w htt }{ret0} respBody, err := json.Marshal(respPayload) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to marshal json response: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCausef("failed to marshal json response: %w", err)) return } @@ -1164,7 +1228,7 @@ func (s *quotaControlServer) serveGetAccessKeyUsageJSON(ctx context.Context, w h reqBody, err := io.ReadAll(r.Body) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to read request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to read request data: %w", err)) return } defer r.Body.Close() @@ -1176,7 +1240,7 @@ func (s *quotaControlServer) serveGetAccessKeyUsageJSON(ctx context.Context, w h Arg3 *time.Time `json:"to"` }{} if err := json.Unmarshal(reqBody, &reqPayload); err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to unmarshal request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to unmarshal request data: %w", err)) return } @@ -1196,7 +1260,7 @@ func (s *quotaControlServer) serveGetAccessKeyUsageJSON(ctx context.Context, w h }{ret0} respBody, err := json.Marshal(respPayload) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to marshal json response: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCausef("failed to marshal json response: %w", err)) return } @@ -1210,7 +1274,7 @@ func (s *quotaControlServer) serveGetAsyncUsageJSON(ctx context.Context, w http. reqBody, err := io.ReadAll(r.Body) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to read request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to read request data: %w", err)) return } defer r.Body.Close() @@ -1222,7 +1286,7 @@ func (s *quotaControlServer) serveGetAsyncUsageJSON(ctx context.Context, w http. Arg3 *time.Time `json:"to"` }{} if err := json.Unmarshal(reqBody, &reqPayload); err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to unmarshal request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to unmarshal request data: %w", err)) return } @@ -1242,7 +1306,7 @@ func (s *quotaControlServer) serveGetAsyncUsageJSON(ctx context.Context, w http. }{ret0} respBody, err := json.Marshal(respPayload) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to marshal json response: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCausef("failed to marshal json response: %w", err)) return } @@ -1256,7 +1320,7 @@ func (s *quotaControlServer) servePrepareUsageJSON(ctx context.Context, w http.R reqBody, err := io.ReadAll(r.Body) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to read request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to read request data: %w", err)) return } defer r.Body.Close() @@ -1267,7 +1331,7 @@ func (s *quotaControlServer) servePrepareUsageJSON(ctx context.Context, w http.R Arg2 time.Time `json:"now"` }{} if err := json.Unmarshal(reqBody, &reqPayload); err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to unmarshal request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to unmarshal request data: %w", err)) return } @@ -1287,7 +1351,7 @@ func (s *quotaControlServer) servePrepareUsageJSON(ctx context.Context, w http.R }{ret0} respBody, err := json.Marshal(respPayload) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to marshal json response: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCausef("failed to marshal json response: %w", err)) return } @@ -1301,7 +1365,7 @@ func (s *quotaControlServer) serveClearUsageJSON(ctx context.Context, w http.Res reqBody, err := io.ReadAll(r.Body) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to read request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to read request data: %w", err)) return } defer r.Body.Close() @@ -1311,7 +1375,7 @@ func (s *quotaControlServer) serveClearUsageJSON(ctx context.Context, w http.Res Arg1 time.Time `json:"now"` }{} if err := json.Unmarshal(reqBody, &reqPayload); err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to unmarshal request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to unmarshal request data: %w", err)) return } @@ -1331,7 +1395,7 @@ func (s *quotaControlServer) serveClearUsageJSON(ctx context.Context, w http.Res }{ret0} respBody, err := json.Marshal(respPayload) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to marshal json response: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCausef("failed to marshal json response: %w", err)) return } @@ -1345,7 +1409,7 @@ func (s *quotaControlServer) serveNotifyEventJSON(ctx context.Context, w http.Re reqBody, err := io.ReadAll(r.Body) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to read request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to read request data: %w", err)) return } defer r.Body.Close() @@ -1355,7 +1419,7 @@ func (s *quotaControlServer) serveNotifyEventJSON(ctx context.Context, w http.Re Arg1 EventType `json:"eventType"` }{} if err := json.Unmarshal(reqBody, &reqPayload); err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to unmarshal request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to unmarshal request data: %w", err)) return } @@ -1375,7 +1439,7 @@ func (s *quotaControlServer) serveNotifyEventJSON(ctx context.Context, w http.Re }{ret0} respBody, err := json.Marshal(respPayload) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to marshal json response: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCausef("failed to marshal json response: %w", err)) return } @@ -1389,7 +1453,7 @@ func (s *quotaControlServer) serveUpdateProjectUsageJSON(ctx context.Context, w reqBody, err := io.ReadAll(r.Body) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to read request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to read request data: %w", err)) return } defer r.Body.Close() @@ -1400,7 +1464,7 @@ func (s *quotaControlServer) serveUpdateProjectUsageJSON(ctx context.Context, w Arg2 map[uint64]*AccessUsage `json:"usage"` }{} if err := json.Unmarshal(reqBody, &reqPayload); err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to unmarshal request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to unmarshal request data: %w", err)) return } @@ -1420,7 +1484,7 @@ func (s *quotaControlServer) serveUpdateProjectUsageJSON(ctx context.Context, w }{ret0} respBody, err := json.Marshal(respPayload) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to marshal json response: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCausef("failed to marshal json response: %w", err)) return } @@ -1434,7 +1498,7 @@ func (s *quotaControlServer) serveUpdateKeyUsageJSON(ctx context.Context, w http reqBody, err := io.ReadAll(r.Body) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to read request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to read request data: %w", err)) return } defer r.Body.Close() @@ -1445,7 +1509,7 @@ func (s *quotaControlServer) serveUpdateKeyUsageJSON(ctx context.Context, w http Arg2 map[string]*AccessUsage `json:"usage"` }{} if err := json.Unmarshal(reqBody, &reqPayload); err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to unmarshal request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to unmarshal request data: %w", err)) return } @@ -1465,7 +1529,7 @@ func (s *quotaControlServer) serveUpdateKeyUsageJSON(ctx context.Context, w http }{ret0} respBody, err := json.Marshal(respPayload) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to marshal json response: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCausef("failed to marshal json response: %w", err)) return } @@ -1479,7 +1543,7 @@ func (s *quotaControlServer) serveUpdateUsageJSON(ctx context.Context, w http.Re reqBody, err := io.ReadAll(r.Body) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to read request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to read request data: %w", err)) return } defer r.Body.Close() @@ -1490,7 +1554,7 @@ func (s *quotaControlServer) serveUpdateUsageJSON(ctx context.Context, w http.Re Arg2 map[string]*AccessUsage `json:"usage"` }{} if err := json.Unmarshal(reqBody, &reqPayload); err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to unmarshal request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to unmarshal request data: %w", err)) return } @@ -1510,7 +1574,7 @@ func (s *quotaControlServer) serveUpdateUsageJSON(ctx context.Context, w http.Re }{ret0} respBody, err := json.Marshal(respPayload) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to marshal json response: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCausef("failed to marshal json response: %w", err)) return } @@ -1524,7 +1588,7 @@ func (s *quotaControlServer) serveGetUserPermissionJSON(ctx context.Context, w h reqBody, err := io.ReadAll(r.Body) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to read request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to read request data: %w", err)) return } defer r.Body.Close() @@ -1534,7 +1598,7 @@ func (s *quotaControlServer) serveGetUserPermissionJSON(ctx context.Context, w h Arg1 string `json:"userId"` }{} if err := json.Unmarshal(reqBody, &reqPayload); err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCause(fmt.Errorf("failed to unmarshal request data: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadRequest.WithCausef("failed to unmarshal request data: %w", err)) return } @@ -1555,7 +1619,7 @@ func (s *quotaControlServer) serveGetUserPermissionJSON(ctx context.Context, w h }{ret0, ret1} respBody, err := json.Marshal(respPayload) if err != nil { - s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to marshal json response: %w", err))) + s.sendErrorJSON(w, r, ErrWebrpcBadResponse.WithCausef("failed to marshal json response: %w", err)) return } @@ -1644,7 +1708,7 @@ func (c *quotaControlClient) GetProjectStatus(ctx context.Context, projectId uin if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1663,7 +1727,7 @@ func (c *quotaControlClient) GetAccessKey(ctx context.Context, accessKey string) if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1682,7 +1746,7 @@ func (c *quotaControlClient) GetDefaultAccessKey(ctx context.Context, projectID if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1704,7 +1768,7 @@ func (c *quotaControlClient) CreateAccessKey(ctx context.Context, projectId uint if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1723,7 +1787,7 @@ func (c *quotaControlClient) RotateAccessKey(ctx context.Context, accessKey stri if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1745,7 +1809,7 @@ func (c *quotaControlClient) UpdateAccessKey(ctx context.Context, accessKey stri if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1765,7 +1829,7 @@ func (c *quotaControlClient) UpdateDefaultAccessKey(ctx context.Context, project if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1786,7 +1850,7 @@ func (c *quotaControlClient) ListAccessKeys(ctx context.Context, projectId uint6 if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1805,7 +1869,7 @@ func (c *quotaControlClient) DisableAccessKey(ctx context.Context, accessKey str if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1825,7 +1889,7 @@ func (c *quotaControlClient) GetProjectQuota(ctx context.Context, projectId uint if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1845,7 +1909,7 @@ func (c *quotaControlClient) GetAccessQuota(ctx context.Context, accessKey strin if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1864,7 +1928,7 @@ func (c *quotaControlClient) ClearAccessQuotaCache(ctx context.Context, projectI if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1886,7 +1950,7 @@ func (c *quotaControlClient) GetAccountUsage(ctx context.Context, projectID uint if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1908,7 +1972,7 @@ func (c *quotaControlClient) GetAccessKeyUsage(ctx context.Context, accessKey st if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1930,7 +1994,7 @@ func (c *quotaControlClient) GetAsyncUsage(ctx context.Context, projectID uint64 if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1951,7 +2015,7 @@ func (c *quotaControlClient) PrepareUsage(ctx context.Context, projectID uint64, if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1971,7 +2035,7 @@ func (c *quotaControlClient) ClearUsage(ctx context.Context, projectID uint64, n if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1991,7 +2055,7 @@ func (c *quotaControlClient) NotifyEvent(ctx context.Context, projectID uint64, if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2012,7 +2076,7 @@ func (c *quotaControlClient) UpdateProjectUsage(ctx context.Context, service Ser if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2033,7 +2097,7 @@ func (c *quotaControlClient) UpdateKeyUsage(ctx context.Context, service Service if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2054,7 +2118,7 @@ func (c *quotaControlClient) UpdateUsage(ctx context.Context, service Service, n if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2075,7 +2139,7 @@ func (c *quotaControlClient) GetUserPermission(ctx context.Context, projectId ui if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2112,6 +2176,7 @@ func newRequest(ctx context.Context, url string, reqBody io.Reader, contentType } req.Header.Set("Accept", contentType) req.Header.Set("Content-Type", contentType) + req.Header.Set(WebrpcHeader, WebrpcHeaderValue) if headers, ok := HTTPRequestHeaders(ctx); ok { for k := range headers { for _, v := range headers[k] { @@ -2126,15 +2191,15 @@ func newRequest(ctx context.Context, url string, reqBody io.Reader, contentType func doHTTPRequest(ctx context.Context, client HTTPClient, url string, in, out interface{}) (*http.Response, error) { reqBody, err := json.Marshal(in) if err != nil { - return nil, ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to marshal JSON body: %w", err)) + return nil, ErrWebrpcRequestFailed.WithCausef("failed to marshal JSON body: %w", err) } if err = ctx.Err(); err != nil { - return nil, ErrWebrpcRequestFailed.WithCause(fmt.Errorf("aborted because context was done: %w", err)) + return nil, ErrWebrpcRequestFailed.WithCausef("aborted because context was done: %w", err) } req, err := newRequest(ctx, url, bytes.NewBuffer(reqBody), "application/json") if err != nil { - return nil, ErrWebrpcRequestFailed.WithCause(fmt.Errorf("could not build request: %w", err)) + return nil, ErrWebrpcRequestFailed.WithCausef("could not build request: %w", err) } resp, err := client.Do(req) @@ -2145,12 +2210,12 @@ func doHTTPRequest(ctx context.Context, client HTTPClient, url string, in, out i if resp.StatusCode != 200 { respBody, err := io.ReadAll(resp.Body) if err != nil { - return nil, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to read server error response body: %w", err)) + return nil, ErrWebrpcBadResponse.WithCausef("failed to read server error response body: %w", err) } var rpcErr WebRPCError if err := json.Unmarshal(respBody, &rpcErr); err != nil { - return nil, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to unmarshal server error: %w", err)) + return nil, ErrWebrpcBadResponse.WithCausef("failed to unmarshal server error: %w", err) } if rpcErr.Cause != "" { rpcErr.cause = errors.New(rpcErr.Cause) @@ -2161,12 +2226,12 @@ func doHTTPRequest(ctx context.Context, client HTTPClient, url string, in, out i if out != nil { respBody, err := io.ReadAll(resp.Body) if err != nil { - return nil, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to read response body: %w", err)) + return nil, ErrWebrpcBadResponse.WithCausef("failed to read response body: %w", err) } err = json.Unmarshal(respBody, &out) if err != nil { - return nil, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to unmarshal JSON response body: %w", err)) + return nil, ErrWebrpcBadResponse.WithCausef("failed to unmarshal JSON response body: %w", err) } } @@ -2343,7 +2408,7 @@ var ( ErrAborted = WebRPCError{Code: 1005, Name: "Aborted", Message: "Request aborted", HTTPStatus: 400} ErrGeoblocked = WebRPCError{Code: 1006, Name: "Geoblocked", Message: "Geoblocked region", HTTPStatus: 451} ErrRateLimited = WebRPCError{Code: 1007, Name: "RateLimited", Message: "Rate-limited. Please slow down.", HTTPStatus: 429} - ErrProjectNotFound = WebRPCError{Code: 1100, Name: "ProjectNotFound", Message: "Project not found", HTTPStatus: 401} + ErrProjectNotFound = WebRPCError{Code: 1008, Name: "ProjectNotFound", Message: "Project not found", HTTPStatus: 401} ErrAccessKeyNotFound = WebRPCError{Code: 1101, Name: "AccessKeyNotFound", Message: "Access key not found", HTTPStatus: 401} ErrAccessKeyMismatch = WebRPCError{Code: 1102, Name: "AccessKeyMismatch", Message: "Access key mismatch", HTTPStatus: 409} ErrInvalidOrigin = WebRPCError{Code: 1103, Name: "InvalidOrigin", Message: "Invalid origin for Access Key", HTTPStatus: 403} diff --git a/proto/quotacontrol.gen.ts b/proto/quotacontrol.gen.ts index b3b580a..c08576b 100644 --- a/proto/quotacontrol.gen.ts +++ b/proto/quotacontrol.gen.ts @@ -1,9 +1,13 @@ /* eslint-disable */ -// quota-control v0.17.1 89525de9ce8be62e64504eb077da5ae84ca0627e +// quota-control v0.17.1 32a02107e877876adc13bfa09c2fd16a52efed07 // -- -// Code generated by webrpc-gen@v0.21.0 with typescript@v0.12.0 generator. DO NOT EDIT. +// Code generated by webrpc-gen@v0.22.0 with typescript@v0.16.1 generator. DO NOT EDIT. // -// webrpc-gen -schema=quotacontrol.ridl -target=typescript@v0.12.0 -client -out=./quotacontrol.gen.ts +// webrpc-gen -schema=quotacontrol.ridl -target=typescript@v0.16.1 -client -out=./quotacontrol.gen.ts + +export const WebrpcHeader = "Webrpc" + +export const WebrpcHeaderValue = "webrpc@v0.22.0;gen-typescript@v0.16.1;quota-control@v0.17.1" // WebRPC description and code-gen version export const WebRPCVersion = "v1" @@ -12,7 +16,55 @@ export const WebRPCVersion = "v1" export const WebRPCSchemaVersion = "v0.17.1" // Schema hash generated from your RIDL schema -export const WebRPCSchemaHash = "89525de9ce8be62e64504eb077da5ae84ca0627e" +export const WebRPCSchemaHash = "32a02107e877876adc13bfa09c2fd16a52efed07" + +type WebrpcGenVersions = { + webrpcGenVersion: string; + codeGenName: string; + codeGenVersion: string; + schemaName: string; + schemaVersion: string; +}; + +export function VersionFromHeader(headers: Headers): WebrpcGenVersions { + const headerValue = headers.get(WebrpcHeader); + if (!headerValue) { + return { + webrpcGenVersion: "", + codeGenName: "", + codeGenVersion: "", + schemaName: "", + schemaVersion: "", + }; + } + + return parseWebrpcGenVersions(headerValue); +} + +function parseWebrpcGenVersions(header: string): WebrpcGenVersions { + const versions = header.split(";"); + if (versions.length < 3) { + return { + webrpcGenVersion: "", + codeGenName: "", + codeGenVersion: "", + schemaName: "", + schemaVersion: "", + }; + } + + const [_, webrpcGenVersion] = versions[0].split("@"); + const [codeGenName, codeGenVersion] = versions[1].split("@"); + const [schemaName, schemaVersion] = versions[2].split("@"); + + return { + webrpcGenVersion, + codeGenName, + codeGenVersion, + schemaName, + schemaVersion, + }; +} // // Types @@ -326,7 +378,7 @@ export class QuotaControl implements QuotaControl { protected path = '/rpc/QuotaControl/' constructor(hostname: string, fetch: Fetch) { - this.hostname = hostname + this.hostname = hostname.replace(/\/*$/, '') this.fetch = (input: RequestInfo, init?: RequestInit) => fetch(input, init) } @@ -646,9 +698,12 @@ export class QuotaControl implements QuotaControl { } const createHTTPRequest = (body: object = {}, headers: object = {}, signal: AbortSignal | null = null): object => { + const reqHeaders: {[key: string]: string} = { ...headers, 'Content-Type': 'application/json' } + reqHeaders[WebrpcHeader] = WebrpcHeaderValue + return { method: 'POST', - headers: { ...headers, 'Content-Type': 'application/json' }, + headers: reqHeaders, body: JSON.stringify(body || {}), signal } @@ -962,7 +1017,7 @@ export class RateLimitedError extends WebrpcError { export class ProjectNotFoundError extends WebrpcError { constructor( name: string = 'ProjectNotFound', - code: number = 1100, + code: number = 1008, message: string = 'Project not found', status: number = 0, cause?: string @@ -1150,7 +1205,41 @@ export enum errors { Timeout = 'Timeout', } -const webrpcErrorByCode: { [code: number]: any } = { +export enum WebrpcErrorCodes { + WebrpcEndpoint = 0, + WebrpcRequestFailed = -1, + WebrpcBadRoute = -2, + WebrpcBadMethod = -3, + WebrpcBadRequest = -4, + WebrpcBadResponse = -5, + WebrpcServerPanic = -6, + WebrpcInternalError = -7, + WebrpcClientDisconnected = -8, + WebrpcStreamLost = -9, + WebrpcStreamFinished = -10, + Unauthorized = 1000, + PermissionDenied = 1001, + SessionExpired = 1002, + MethodNotFound = 1003, + RequestConflict = 1004, + Aborted = 1005, + Geoblocked = 1006, + RateLimited = 1007, + ProjectNotFound = 1008, + AccessKeyNotFound = 1101, + AccessKeyMismatch = 1102, + InvalidOrigin = 1103, + InvalidService = 1104, + UnauthorizedUser = 1105, + QuotaExceeded = 1200, + QuotaRateLimit = 1201, + NoDefaultKey = 1300, + MaxAccessKeys = 1301, + AtLeastOneKey = 1302, + Timeout = 1900, +} + +export const webrpcErrorByCode: { [code: number]: any } = { [0]: WebrpcEndpointError, [-1]: WebrpcRequestFailedError, [-2]: WebrpcBadRouteError, @@ -1170,7 +1259,7 @@ const webrpcErrorByCode: { [code: number]: any } = { [1005]: AbortedError, [1006]: GeoblockedError, [1007]: RateLimitedError, - [1100]: ProjectNotFoundError, + [1008]: ProjectNotFoundError, [1101]: AccessKeyNotFoundError, [1102]: AccessKeyMismatchError, [1103]: InvalidOriginError, @@ -1185,3 +1274,4 @@ const webrpcErrorByCode: { [code: number]: any } = { } export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise + diff --git a/proto/quotacontrol.ridl b/proto/quotacontrol.ridl index 8143d5e..7134fed 100644 --- a/proto/quotacontrol.ridl +++ b/proto/quotacontrol.ridl @@ -95,31 +95,8 @@ struct ResourceAccess - subscription: Subscription - minter: Minter -# 1000-1099: AuthControl errors -error 1000 Unauthorized "Unauthorized access" HTTP 401 -error 1001 PermissionDenied "Permission denied" HTTP 403 -error 1002 SessionExpired "Session expired" HTTP 403 -error 1003 MethodNotFound "Method not found" HTTP 404 -error 1004 RequestConflict "Conflict with target resource" HTTP 409 -error 1005 Aborted "Request aborted" HTTP 400 -error 1006 Geoblocked "Geoblocked region" HTTP 451 -error 1007 RateLimited "Rate-limited. Please slow down." HTTP 429 -# 1100-1199: AccessKey/Project errors -error 1100 ProjectNotFound "Project not found" HTTP 401 -error 1101 AccessKeyNotFound "Access key not found" HTTP 401 -error 1102 AccessKeyMismatch "Access key mismatch" HTTP 409 -error 1103 InvalidOrigin "Invalid origin for Access Key" HTTP 403 -error 1104 InvalidService "Service not enabled for Access key" HTTP 403 -error 1105 UnauthorizedUser "Unauthorized user" HTTP 403 -# 1200-1299: Limit errors -error 1200 QuotaExceeded "Quota request exceeded" HTTP 429 -error 1201 QuotaRateLimit "Quota rate limit exceeded" HTTP 429 -# 1300-1399: Access Key management errors -error 1300 NoDefaultKey "No default access key found" HTTP 403 -error 1301 MaxAccessKeys "Access keys limit reached" HTTP 403 -error 1302 AtLeastOneKey "You need at least one Access Key" HTTP 403 -# 1900-1999: Other errors -error 1900 Timeout "Request timed out" HTTP 408 +import "authcontrol.errors.ridl" +import "errors.ridl" service QuotaControl # Project diff --git a/scripts/import.sh b/scripts/import.sh index dfd306c..33b9f17 100755 --- a/scripts/import.sh +++ b/scripts/import.sh @@ -5,17 +5,18 @@ # Sample usage in makefile: # # import-errors: -# curl https://raw.githubusercontent.com/0xsequence/quotacontrol/refs/heads/master/scripts/import.sh | sh; +# curl https://raw.githubusercontent.com/0xsequence/quotacontrol/refs/heads/master/scripts/import.sh | [PKG=package] sh; -PKG="0xsequence/quotacontrol" -TAG=$(cat go.mod | grep -v "//" | grep $PKG | awk '{print$ 2}') -URL="https://raw.githubusercontent.com/$PKG/refs/tags/$TAG/proto/quotacontrol.ridl" +PKG="${PKG:-"0xsequence/quotacontrol"}" -COMMIT=$(echo $TAG | cut -d'-' -f 3) -if [[ "$TAG" != "$COMMIT" ]]; then - URL="https://raw.githubusercontent.com/$PKG/refs/heads/$COMMIT/proto/quotacontrol.ridl"; +echo $PKG + +VERSION=$(cat go.mod | grep -v "//" | grep $PKG | awk '{print$ 2}') +REF="tags" +COMMIT=$(echo $VERSION | cut -d'-' -f 3) +if [[ "$VERSION" != "$COMMIT" ]]; then + REF="heads" + VERSION="$COMMIT" fi -printf "# $PKG $TAG \n"; -curl -s $URL | grep "^error 1"; -printf "\n" +curl -s "https://raw.githubusercontent.com/$PKG/refs/$REF/$VERSION/proto/errors.ridl" > ./proto/$(basename "$PKG").errors.ridl diff --git a/tools/go.mod b/tools/go.mod index 3a172e4..81934ec 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -4,7 +4,7 @@ go 1.21 require ( github.com/goware/rerun v0.0.9 - github.com/webrpc/webrpc v0.21.0 + github.com/webrpc/webrpc v0.22.0 ) require ( @@ -45,11 +45,11 @@ require ( github.com/skeema/knownhosts v1.2.2 // indirect github.com/spf13/cast v1.6.0 // indirect github.com/webrpc/gen-dart v0.1.1 // indirect - github.com/webrpc/gen-golang v0.16.0 // indirect + github.com/webrpc/gen-golang v0.17.0 // indirect github.com/webrpc/gen-javascript v0.13.0 // indirect github.com/webrpc/gen-kotlin v0.1.0 // indirect github.com/webrpc/gen-openapi v0.15.0 // indirect - github.com/webrpc/gen-typescript v0.15.0 // indirect + github.com/webrpc/gen-typescript v0.16.1 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect golang.org/x/crypto v0.28.0 // indirect golang.org/x/mod v0.20.0 // indirect diff --git a/tools/go.sum b/tools/go.sum index 7d2c6fc..5ca1403 100644 --- a/tools/go.sum +++ b/tools/go.sum @@ -206,18 +206,18 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/webrpc/gen-dart v0.1.1 h1:PZh5oNNdA84Qxu8ixKDf1cT8Iv6t0g7x6q9aeX1bti4= github.com/webrpc/gen-dart v0.1.1/go.mod h1:yq0ThW3ANNulJLyR50jx1aZMEVBDp19VUHucK65ayPs= -github.com/webrpc/gen-golang v0.16.0 h1:A41DrslXhvhSHUrpLx3Rdx3Jl3fxrk66L0z5M9MiT0A= -github.com/webrpc/gen-golang v0.16.0/go.mod h1:qy1qEWMlTvrRzjSuQLy+176RqNaX1ymUULDtlo7Dapo= +github.com/webrpc/gen-golang v0.17.0 h1:qCvkhrIdEalQNYJEyqUhKiZ/wK5yEOhx0TJ5X0fzoKM= +github.com/webrpc/gen-golang v0.17.0/go.mod h1:qy1qEWMlTvrRzjSuQLy+176RqNaX1ymUULDtlo7Dapo= github.com/webrpc/gen-javascript v0.13.0 h1:tw7U1xueUjZz3cQAAA4/DZ90BHydkQKiJC4VXd/j2hg= github.com/webrpc/gen-javascript v0.13.0/go.mod h1:5EhapSJgzbiWrIGlqzZN9Lg9mE9209wwX+Du2dgn4EU= github.com/webrpc/gen-kotlin v0.1.0 h1:tnlinqbDgowEoSy8E3VovTdP2OjyOIbgACCbahRjNcc= github.com/webrpc/gen-kotlin v0.1.0/go.mod h1:PIPys9Gn1Ro7q7uoacydEX8CtqBlAJSV98A++tdj4ak= github.com/webrpc/gen-openapi v0.15.0 h1:RrHAcDTlm0YH+YCz12p0KLCYIwfHrxf4x6/LjJ6kePY= github.com/webrpc/gen-openapi v0.15.0/go.mod h1:fwY3ylZmdiCr+WXjR8Ek8wm08CFRr2/GaXI7Zd/Ou4Y= -github.com/webrpc/gen-typescript v0.15.0 h1:cRnbarQiSoxA0taJ4V0v7TmHKE6UBhO6klvIrGu/CaM= -github.com/webrpc/gen-typescript v0.15.0/go.mod h1:xQzYnVaSMfcygDXA5SuW8eYyCLHBHkj15wCF7gcJF5Y= -github.com/webrpc/webrpc v0.21.0 h1:gjZFP6FUL++2Lp4+Ts23kVvW9zk/sxvajZ+kXwB/ZuU= -github.com/webrpc/webrpc v0.21.0/go.mod h1:1WwQ1WRobFUjJiG34r8QMCXRLb1hr27+rdWmfWjSF2Y= +github.com/webrpc/gen-typescript v0.16.1 h1:4t9YNGROOV2ZL0UyB5wjWMpJklXDDNEj8eg05+8BF5Y= +github.com/webrpc/gen-typescript v0.16.1/go.mod h1:xQzYnVaSMfcygDXA5SuW8eYyCLHBHkj15wCF7gcJF5Y= +github.com/webrpc/webrpc v0.22.0 h1:DkpXYA9p7em+Oqn76+VZrQJkrlbMEO8vBPpcjQ+lGvo= +github.com/webrpc/webrpc v0.22.0/go.mod h1:eeABnLz9BC4F9GGw6UKebVPkzkFYLrZRlcOvh6o8n10= github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= From b57c235d40f326609e8ddc9534b0bc4e6217a186 Mon Sep 17 00:00:00 2001 From: Alex Guerrieri Date: Fri, 29 Nov 2024 12:23:20 +0100 Subject: [PATCH 2/4] Test IPV6 --- middleware/middleware_ratelimit_test.go | 63 ++++++++++++++++++------- 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/middleware/middleware_ratelimit_test.go b/middleware/middleware_ratelimit_test.go index 9f8847c..561d117 100644 --- a/middleware/middleware_ratelimit_test.go +++ b/middleware/middleware_ratelimit_test.go @@ -15,6 +15,18 @@ import ( "github.com/stretchr/testify/assert" ) +func makeIP(ipv6 bool) net.IP { + size := 4 + if ipv6 { + size = 16 + } + buf := make([]byte, size) + for i := 0; i < size/4; i++ { + binary.LittleEndian.PutUint32(buf[i*4:], rand.Uint32()) + } + return net.IP(buf) +} + func TestRateLimiter(t *testing.T) { const ( _CustomErrorMessage = "Custom error message" @@ -37,25 +49,42 @@ func TestRateLimiter(t *testing.T) { }, nil, middleware.Options{ErrHandler: eh}) handler := rl(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})) - buf := make([]byte, 4) for i := 0; i < 10; i++ { - ip := rand.Uint32() - binary.LittleEndian.PutUint32(buf, ip) + ipAddress := makeIP(false).String() + for i := 0; i < 20; i++ { + req, _ := http.NewRequest("GET", "/", nil) + req.RemoteAddr = ipAddress + w := httptest.NewRecorder() + handler.ServeHTTP(w, req) + if i < 10 { + assert.Equal(t, http.StatusOK, w.Code) + continue + } + assert.Equal(t, http.StatusTooManyRequests, w.Code) + assert.Equal(t, _TestHeaderValue, w.Header().Get(_TestHeader)) + err := proto.WebRPCError{} + assert.Nil(t, json.Unmarshal(w.Body.Bytes(), &err)) + assert.Contains(t, err.Message, _CustomErrorMessage) + } } - ipAddress := net.IP(buf).String() - for i := 0; i < 20; i++ { - req, _ := http.NewRequest("GET", "/", nil) - req.RemoteAddr = ipAddress - w := httptest.NewRecorder() - handler.ServeHTTP(w, req) - if i < 10 { - assert.Equal(t, http.StatusOK, w.Code) - continue + + for i := 0; i < 80; i++ { + ipAddress := makeIP(true).String() + for i := 0; i < 20; i++ { + req, _ := http.NewRequest("GET", "/", nil) + req.RemoteAddr = ipAddress + w := httptest.NewRecorder() + handler.ServeHTTP(w, req) + if i < 10 { + assert.Equal(t, http.StatusOK, w.Code) + continue + } + assert.Equal(t, http.StatusTooManyRequests, w.Code) + assert.Equal(t, _TestHeaderValue, w.Header().Get(_TestHeader)) + err := proto.WebRPCError{} + assert.Nil(t, json.Unmarshal(w.Body.Bytes(), &err)) + assert.Contains(t, err.Message, _CustomErrorMessage) } - assert.Equal(t, http.StatusTooManyRequests, w.Code) - assert.Equal(t, _TestHeaderValue, w.Header().Get(_TestHeader)) - err := proto.WebRPCError{} - assert.Nil(t, json.Unmarshal(w.Body.Bytes(), &err)) - assert.Contains(t, err.Message, _CustomErrorMessage) } + } From d9f0aff3693bb0a064f8ba54c2657bb76f0b451d Mon Sep 17 00:00:00 2001 From: Alex Guerrieri Date: Fri, 29 Nov 2024 12:32:44 +0100 Subject: [PATCH 3/4] Bump version --- proto/quotacontrol.gen.go | 8 ++++---- proto/quotacontrol.gen.ts | 8 ++++---- proto/quotacontrol.ridl | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/proto/quotacontrol.gen.go b/proto/quotacontrol.gen.go index 2a11d5c..0278887 100644 --- a/proto/quotacontrol.gen.go +++ b/proto/quotacontrol.gen.go @@ -1,4 +1,4 @@ -// quota-control v0.17.1 32a02107e877876adc13bfa09c2fd16a52efed07 +// quota-control v0.19.2 4b5f19d012ae4365adc25b547b4d39ac58a974e8 // -- // Code generated by webrpc-gen@v0.22.0 with golang@v0.17.0 generator. DO NOT EDIT. // @@ -23,7 +23,7 @@ import ( const WebrpcHeader = "Webrpc" -const WebrpcHeaderValue = "webrpc@v0.22.0;gen-golang@v0.17.0;quota-control@v0.17.1" +const WebrpcHeaderValue = "webrpc@v0.22.0;gen-golang@v0.17.0;quota-control@v0.19.2" // WebRPC description and code-gen version func WebRPCVersion() string { @@ -32,12 +32,12 @@ func WebRPCVersion() string { // Schema version of your RIDL schema func WebRPCSchemaVersion() string { - return "v0.17.1" + return "v0.19.2" } // Schema hash generated from your RIDL schema func WebRPCSchemaHash() string { - return "32a02107e877876adc13bfa09c2fd16a52efed07" + return "4b5f19d012ae4365adc25b547b4d39ac58a974e8" } type WebrpcGenVersions struct { diff --git a/proto/quotacontrol.gen.ts b/proto/quotacontrol.gen.ts index c08576b..cac0cce 100644 --- a/proto/quotacontrol.gen.ts +++ b/proto/quotacontrol.gen.ts @@ -1,5 +1,5 @@ /* eslint-disable */ -// quota-control v0.17.1 32a02107e877876adc13bfa09c2fd16a52efed07 +// quota-control v0.19.2 4b5f19d012ae4365adc25b547b4d39ac58a974e8 // -- // Code generated by webrpc-gen@v0.22.0 with typescript@v0.16.1 generator. DO NOT EDIT. // @@ -7,16 +7,16 @@ export const WebrpcHeader = "Webrpc" -export const WebrpcHeaderValue = "webrpc@v0.22.0;gen-typescript@v0.16.1;quota-control@v0.17.1" +export const WebrpcHeaderValue = "webrpc@v0.22.0;gen-typescript@v0.16.1;quota-control@v0.19.2" // WebRPC description and code-gen version export const WebRPCVersion = "v1" // Schema version of your RIDL schema -export const WebRPCSchemaVersion = "v0.17.1" +export const WebRPCSchemaVersion = "v0.19.2" // Schema hash generated from your RIDL schema -export const WebRPCSchemaHash = "32a02107e877876adc13bfa09c2fd16a52efed07" +export const WebRPCSchemaHash = "4b5f19d012ae4365adc25b547b4d39ac58a974e8" type WebrpcGenVersions = { webrpcGenVersion: string; diff --git a/proto/quotacontrol.ridl b/proto/quotacontrol.ridl index 7134fed..57708f8 100644 --- a/proto/quotacontrol.ridl +++ b/proto/quotacontrol.ridl @@ -1,7 +1,7 @@ webrpc = v1 name = quota-control -version = v0.17.1 +version = v0.19.2 enum Service: uint16 - NodeGateway From b9687ed77618637ea9992504ef6e790d5ce0b826 Mon Sep 17 00:00:00 2001 From: Alex Guerrieri Date: Fri, 29 Nov 2024 12:45:41 +0100 Subject: [PATCH 4/4] ridlfmt --- proto/authcontrol.errors.ridl | 18 +++++++++--------- proto/errors.ridl | 12 ++++++------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/proto/authcontrol.errors.ridl b/proto/authcontrol.errors.ridl index 0a81f86..7b04933 100644 --- a/proto/authcontrol.errors.ridl +++ b/proto/authcontrol.errors.ridl @@ -3,12 +3,12 @@ webrpc = v1 name = authcontrol version = v0.9.1 -error 1000 Unauthorized "Unauthorized access" HTTP 401 -error 1001 PermissionDenied "Permission denied" HTTP 403 -error 1002 SessionExpired "Session expired" HTTP 403 -error 1003 MethodNotFound "Method not found" HTTP 404 -error 1004 RequestConflict "Conflict with target resource" HTTP 409 -error 1005 Aborted "Request aborted" HTTP 400 -error 1006 Geoblocked "Geoblocked region" HTTP 451 -error 1007 RateLimited "Rate-limited. Please slow down." HTTP 429 -error 1008 ProjectNotFound "Project not found" HTTP 401 +error 1000 Unauthorized "Unauthorized access" HTTP 401 +error 1001 PermissionDenied "Permission denied" HTTP 403 +error 1002 SessionExpired "Session expired" HTTP 403 +error 1003 MethodNotFound "Method not found" HTTP 404 +error 1004 RequestConflict "Conflict with target resource" HTTP 409 +error 1005 Aborted "Request aborted" HTTP 400 +error 1006 Geoblocked "Geoblocked region" HTTP 451 +error 1007 RateLimited "Rate-limited. Please slow down." HTTP 429 +error 1008 ProjectNotFound "Project not found" HTTP 401 diff --git a/proto/errors.ridl b/proto/errors.ridl index 26f23cc..a96ab83 100644 --- a/proto/errors.ridl +++ b/proto/errors.ridl @@ -7,11 +7,11 @@ error 1103 InvalidOrigin "Invalid origin for Access Key" HTTP 403 error 1104 InvalidService "Service not enabled for Access key" HTTP 403 error 1105 UnauthorizedUser "Unauthorized user" HTTP 403 # 1200-1299: Limit errors -error 1200 QuotaExceeded "Quota request exceeded" HTTP 429 -error 1201 QuotaRateLimit "Quota rate limit exceeded" HTTP 429 +error 1200 QuotaExceeded "Quota request exceeded" HTTP 429 +error 1201 QuotaRateLimit "Quota rate limit exceeded" HTTP 429 # 1300-1399: Access Key management errors -error 1300 NoDefaultKey "No default access key found" HTTP 403 -error 1301 MaxAccessKeys "Access keys limit reached" HTTP 403 -error 1302 AtLeastOneKey "You need at least one Access Key" HTTP 403 +error 1300 NoDefaultKey "No default access key found" HTTP 403 +error 1301 MaxAccessKeys "Access keys limit reached" HTTP 403 +error 1302 AtLeastOneKey "You need at least one Access Key" HTTP 403 # 1900-1999: Other errors -error 1900 Timeout "Request timed out" HTTP 408 +error 1900 Timeout "Request timed out" HTTP 408