Skip to content

Commit

Permalink
Merge pull request #29 from 0xsequence/tenant-not-found
Browse files Browse the repository at this point in the history
Specify "tenant not found"  error in ridl file
  • Loading branch information
patrislav authored Mar 6, 2024
2 parents 2ca1d56 + fabd8f2 commit e33b359
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 17 deletions.
11 changes: 6 additions & 5 deletions proto/authenticator.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions proto/authenticator.ridl
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ struct SessionData
##

error 1000 Unauthorized "Unauthorized access" HTTP 401
error 1001 TenantNotFound "Tenant not found" HTTP 404


##
Expand Down
11 changes: 6 additions & 5 deletions proto/clients/authenticator.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 17 additions & 2 deletions proto/clients/authenticator.gen.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable */
// sequence-waas-authenticator v0.1.0 c02d115f8e54a1d15199e321aa744883a7c2946e
// sequence-waas-authenticator v0.1.0 a753d63c2d2bbb862ca2c9efb16ba355b19a81aa
// --
// Code generated by [email protected] with typescript generator. DO NOT EDIT.
//
Expand All @@ -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
Expand Down Expand Up @@ -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',
Expand All @@ -620,6 +633,7 @@ export enum errors {
WebrpcStreamLost = 'WebrpcStreamLost',
WebrpcStreamFinished = 'WebrpcStreamFinished',
Unauthorized = 'Unauthorized',
TenantNotFound = 'TenantNotFound',
}

const webrpcErrorByCode: { [code: number]: any } = {
Expand All @@ -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<Response>
Expand Down
4 changes: 2 additions & 2 deletions proto/proto.go
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions rpc/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion rpc/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand Down

0 comments on commit e33b359

Please sign in to comment.