From d4a381c0d3765350f5be139981f6d30b3cad0e41 Mon Sep 17 00:00:00 2001 From: Alex Guerrieri Date: Wed, 6 Mar 2024 15:22:48 +0100 Subject: [PATCH 1/2] specify error in ridl --- proto/authenticator.gen.go | 11 ++++++----- proto/authenticator.ridl | 1 + proto/clients/authenticator.gen.go | 11 ++++++----- proto/clients/authenticator.gen.ts | 19 +++++++++++++++++-- proto/proto.go | 4 ++-- rpc/admin.go | 4 ++-- 6 files changed, 34 insertions(+), 16 deletions(-) diff --git a/proto/authenticator.gen.go b/proto/authenticator.gen.go index 60cf6c1b..3fec520b 100644 --- a/proto/authenticator.gen.go +++ b/proto/authenticator.gen.go @@ -1,8 +1,8 @@ -// sequence-waas-authenticator v0.1.0 c02d115f8e54a1d15199e321aa744883a7c2946e +// sequence-waas-authenticator v0.1.0 a753d63c2d2bbb862ca2c9efb16ba355b19a81aa // -- -// Code generated by webrpc-gen@v0.14.0-dev with golang generator. DO NOT EDIT. +// Code generated by webrpc-gen@v0.14.0-dev with golang@v0.13.6 generator. DO NOT EDIT. // -// webrpc-gen -schema=authenticator.ridl -target=golang -pkg=proto -server -client -out=./authenticator.gen.go +// webrpc-gen -schema=authenticator.ridl -target=golang@v0.13.6 -pkg=proto -server -client -out=./authenticator.gen.go package proto import ( @@ -34,7 +34,7 @@ func WebRPCSchemaVersion() string { // Schema hash generated from your RIDL schema func WebRPCSchemaHash() string { - return "c02d115f8e54a1d15199e321aa744883a7c2946e" + return "a753d63c2d2bbb862ca2c9efb16ba355b19a81aa" } // @@ -1112,5 +1112,6 @@ var ( // Schema errors var ( - ErrUnauthorized = WebRPCError{Code: 1000, Name: "Unauthorized", Message: "Unauthorized access", HTTPStatus: 401} + ErrUnauthorized = WebRPCError{Code: 1000, Name: "Unauthorized", Message: "Unauthorized access", HTTPStatus: 401} + ErrTenantNotFound = WebRPCError{Code: 1001, Name: "TenantNotFound", Message: "Tenant not found", HTTPStatus: 404} ) diff --git a/proto/authenticator.ridl b/proto/authenticator.ridl index 3e7b7853..d576475a 100644 --- a/proto/authenticator.ridl +++ b/proto/authenticator.ridl @@ -139,6 +139,7 @@ struct SessionData ## error 1000 Unauthorized "Unauthorized access" HTTP 401 +error 1001 TenantNotFound "Tenant not found" HTTP 404 ## diff --git a/proto/clients/authenticator.gen.go b/proto/clients/authenticator.gen.go index bafc434c..705ba3d1 100644 --- a/proto/clients/authenticator.gen.go +++ b/proto/clients/authenticator.gen.go @@ -1,8 +1,8 @@ -// sequence-waas-authenticator v0.1.0 c02d115f8e54a1d15199e321aa744883a7c2946e +// sequence-waas-authenticator v0.1.0 a753d63c2d2bbb862ca2c9efb16ba355b19a81aa // -- -// Code generated by webrpc-gen@v0.14.0-dev with golang generator. DO NOT EDIT. +// Code generated by webrpc-gen@v0.14.0-dev with golang@v0.13.6 generator. DO NOT EDIT. // -// webrpc-gen -schema=authenticator.ridl -target=golang -pkg=proto -client -out=./clients/authenticator.gen.go +// webrpc-gen -schema=authenticator.ridl -target=golang@v0.13.6 -pkg=proto -client -out=./clients/authenticator.gen.go package proto import ( @@ -33,7 +33,7 @@ func WebRPCSchemaVersion() string { // Schema hash generated from your RIDL schema func WebRPCSchemaHash() string { - return "c02d115f8e54a1d15199e321aa744883a7c2946e" + return "a753d63c2d2bbb862ca2c9efb16ba355b19a81aa" } // @@ -597,5 +597,6 @@ var ( // Schema errors var ( - ErrUnauthorized = WebRPCError{Code: 1000, Name: "Unauthorized", Message: "Unauthorized access", HTTPStatus: 401} + ErrUnauthorized = WebRPCError{Code: 1000, Name: "Unauthorized", Message: "Unauthorized access", HTTPStatus: 401} + ErrTenantNotFound = WebRPCError{Code: 1001, Name: "TenantNotFound", Message: "Tenant not found", HTTPStatus: 404} ) diff --git a/proto/clients/authenticator.gen.ts b/proto/clients/authenticator.gen.ts index d8878b70..be0ce965 100644 --- a/proto/clients/authenticator.gen.ts +++ b/proto/clients/authenticator.gen.ts @@ -1,5 +1,5 @@ /* eslint-disable */ -// sequence-waas-authenticator v0.1.0 c02d115f8e54a1d15199e321aa744883a7c2946e +// sequence-waas-authenticator v0.1.0 a753d63c2d2bbb862ca2c9efb16ba355b19a81aa // -- // Code generated by webrpc-gen@v0.14.0-dev with typescript generator. DO NOT EDIT. // @@ -12,7 +12,7 @@ export const WebRPCVersion = "v1" export const WebRPCSchemaVersion = "v0.1.0" // Schema hash generated from your RIDL schema -export const WebRPCSchemaHash = "c02d115f8e54a1d15199e321aa744883a7c2946e" +export const WebRPCSchemaHash = "a753d63c2d2bbb862ca2c9efb16ba355b19a81aa" // // Types @@ -606,6 +606,19 @@ export class UnauthorizedError extends WebrpcError { } } +export class TenantNotFoundError extends WebrpcError { + constructor( + name: string = 'TenantNotFound', + code: number = 1001, + message: string = 'Tenant not found', + status: number = 0, + cause?: string + ) { + super(name, code, message, status, cause) + Object.setPrototypeOf(this, TenantNotFoundError.prototype) + } +} + export enum errors { WebrpcEndpoint = 'WebrpcEndpoint', @@ -620,6 +633,7 @@ export enum errors { WebrpcStreamLost = 'WebrpcStreamLost', WebrpcStreamFinished = 'WebrpcStreamFinished', Unauthorized = 'Unauthorized', + TenantNotFound = 'TenantNotFound', } const webrpcErrorByCode: { [code: number]: any } = { @@ -635,6 +649,7 @@ const webrpcErrorByCode: { [code: number]: any } = { [-9]: WebrpcStreamLostError, [-10]: WebrpcStreamFinishedError, [1000]: UnauthorizedError, + [1001]: TenantNotFoundError, } export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise diff --git a/proto/proto.go b/proto/proto.go index a42a5824..1628b719 100644 --- a/proto/proto.go +++ b/proto/proto.go @@ -1,8 +1,8 @@ // Server -//go:generate go run github.com/webrpc/webrpc/cmd/webrpc-gen -schema=authenticator.ridl -target=golang -pkg=proto -server -client -out=./authenticator.gen.go +//go:generate go run github.com/webrpc/webrpc/cmd/webrpc-gen -schema=authenticator.ridl -target=golang@v0.13.6 -pkg=proto -server -client -out=./authenticator.gen.go // Clients -//go:generate go run github.com/webrpc/webrpc/cmd/webrpc-gen -schema=authenticator.ridl -target=golang -pkg=proto -client -out=./clients/authenticator.gen.go +//go:generate go run github.com/webrpc/webrpc/cmd/webrpc-gen -schema=authenticator.ridl -target=golang@v0.13.6 -pkg=proto -client -out=./clients/authenticator.gen.go //go:generate go run github.com/webrpc/webrpc/cmd/webrpc-gen -schema=authenticator.ridl -target=typescript -client -out=./clients/authenticator.gen.ts package proto diff --git a/rpc/admin.go b/rpc/admin.go index bde91190..6b61cc3b 100644 --- a/rpc/admin.go +++ b/rpc/admin.go @@ -22,7 +22,7 @@ func (s *RPC) GetTenant(ctx context.Context, projectID uint64) (*proto.Tenant, e return nil, err } if tnt == nil { - return nil, fmt.Errorf("tenant not found") + return nil, proto.ErrTenantNotFound } tenantData, _, err := crypto.DecryptData[*proto.TenantData](ctx, tnt.EncryptedKey, tnt.Ciphertext, s.Config.KMS.TenantKeys) @@ -151,7 +151,7 @@ func (s *RPC) UpdateTenant( return nil, err } if !found { - return nil, fmt.Errorf("tenant not found") + return nil, proto.ErrTenantNotFound } tntData, _, err := crypto.DecryptData[*proto.TenantData](ctx, tnt.EncryptedKey, tnt.Ciphertext, s.Config.KMS.TenantKeys) From fabd8f2e702ef6090108ba99c975e46afa011094 Mon Sep 17 00:00:00 2001 From: Alex Guerrieri Date: Wed, 6 Mar 2024 15:54:26 +0100 Subject: [PATCH 2/2] fix test --- rpc/admin_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/admin_test.go b/rpc/admin_test.go index 7dc08611..c18fa454 100644 --- a/rpc/admin_test.go +++ b/rpc/admin_test.go @@ -58,7 +58,7 @@ func TestRPC_GetTenant(t *testing.T) { t.Run("MissingTenant", func(t *testing.T) { tnt, err := c.GetTenant(ctx, 2) - assert.ErrorContains(t, err, "tenant not found") + assert.ErrorIs(t, err, proto.ErrTenantNotFound) assert.Nil(t, tnt) }) }