Skip to content

Commit c6c57cf

Browse files
refactor(api)!: drop the removed permission namespace and name fields (#1897)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent 168e2b0 commit c6c57cf

5 files changed

Lines changed: 2483 additions & 2575 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ TAG := $(shell git rev-list --tags --max-count=1)
44
VERSION := $(shell git describe --tags ${TAG})
55
.PHONY: build check fmt lint test test-race vet test-cover-html help install proto admin-app compose-up-dev
66
.DEFAULT_GOAL := build
7-
PROTON_COMMIT := "194685ed0280d282261bc16f708266465dd1deb1"
7+
PROTON_COMMIT := "092b26eddcae87e16504380cf8333f22eb56591b"
88

99
admin-app:
1010
@echo " > generating admin build"

internal/api/v1beta1connect/permission.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,20 @@ func transformPermissionToPB(perm permission.Permission) (*frontierv1beta1.Permi
9191
}
9292
}
9393

94-
// key is the replacement for the deprecated namespace/name fields, so it
95-
// must read back to the exact stored pair. A row that cannot round-trip
96-
// (namespace without a slash, or with a dot in a part) fails loudly here
97-
// instead of returning a key that reads back as a different permission.
94+
// The key is the namespace and name joined with dots, and readers split
95+
// it back on dots. If splitting the key does not give back the same
96+
// namespace and name (a namespace without a slash, or a dot inside a
97+
// namespace part), the key would point at a different permission than
98+
// this row, so return an error instead of a misleading key.
9899
key := schema.PermissionKeyFromNamespaceAndName(perm.NamespaceID, perm.Name)
99100
if ns, name := schema.PermissionNamespaceAndNameFromKey(key); ns != perm.NamespaceID || name != perm.Name {
100101
return nil, fmt.Errorf("permission namespace %q and name %q do not round-trip through key %q", perm.NamespaceID, perm.Name, key)
101102
}
102103

103104
return &frontierv1beta1.Permission{
104105
Id: perm.ID,
105-
Name: perm.Name,
106106
CreatedAt: timestamppb.New(perm.CreatedAt),
107107
UpdatedAt: timestamppb.New(perm.UpdatedAt),
108-
Namespace: perm.NamespaceID,
109108
Metadata: metadata,
110109
Key: key,
111110
}, nil

internal/api/v1beta1connect/permission_test.go

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,6 @@ func TestHandler_CreatePermission(t *testing.T) {
120120
want: nil,
121121
wantErr: connect.NewError(connect.CodeInvalidArgument, ErrPermissionKeyNotation),
122122
},
123-
{
124-
name: "should return bad request error if deprecated fields are sent without key",
125-
setup: func(as *mocks.PermissionService, bs *mocks.BootstrapService) {},
126-
request: connect.NewRequest(&frontierv1beta1.CreatePermissionRequest{
127-
Bodies: []*frontierv1beta1.PermissionRequestBody{
128-
{
129-
Name: testPermissions[testPermissionIdx].Name,
130-
Namespace: testPermissions[testPermissionIdx].NamespaceID,
131-
},
132-
},
133-
}),
134-
want: nil,
135-
wantErr: connect.NewError(connect.CodeInvalidArgument, ErrPermissionKeyNotation),
136-
},
137123
{
138124
name: "should return success if permission service return nil error",
139125
setup: func(as *mocks.PermissionService, bs *mocks.BootstrapService) {
@@ -181,16 +167,12 @@ func TestHandler_CreatePermission(t *testing.T) {
181167
Permissions: []*frontierv1beta1.Permission{
182168
{
183169
Id: testPermissions[testPermissionIdx].ID,
184-
Name: testPermissions[testPermissionIdx].Name + "0",
185-
Namespace: testPermissions[testPermissionIdx].NamespaceID,
186170
Key: schema.PermissionKeyFromNamespaceAndName(testPermissions[testPermissionIdx].NamespaceID, testPermissions[testPermissionIdx].Name+"0"),
187171
CreatedAt: timestamppb.New(testPermissions[testPermissionIdx].CreatedAt),
188172
UpdatedAt: timestamppb.New(testPermissions[testPermissionIdx].UpdatedAt),
189173
},
190174
{
191175
Id: testPermissions[testPermissionIdx].ID,
192-
Name: testPermissions[testPermissionIdx].Name + "1",
193-
Namespace: testPermissions[testPermissionIdx].NamespaceID,
194176
Key: schema.PermissionKeyFromNamespaceAndName(testPermissions[testPermissionIdx].NamespaceID, testPermissions[testPermissionIdx].Name+"1"),
195177
CreatedAt: timestamppb.New(testPermissions[testPermissionIdx].CreatedAt),
196178
UpdatedAt: timestamppb.New(testPermissions[testPermissionIdx].UpdatedAt),
@@ -233,8 +215,6 @@ func TestHandler_CreatePermission(t *testing.T) {
233215
Permissions: []*frontierv1beta1.Permission{
234216
{
235217
Id: testPermissions[testPermissionIdx].ID,
236-
Name: testPermissions[testPermissionIdx].Name + "0",
237-
Namespace: testPermissions[testPermissionIdx].NamespaceID,
238218
Key: schema.PermissionKeyFromNamespaceAndName(testPermissions[testPermissionIdx].NamespaceID, testPermissions[testPermissionIdx].Name+"0"),
239219
CreatedAt: timestamppb.New(testPermissions[testPermissionIdx].CreatedAt),
240220
UpdatedAt: timestamppb.New(testPermissions[testPermissionIdx].UpdatedAt),
@@ -452,19 +432,6 @@ func TestHandler_UpdatePermission(t *testing.T) {
452432
want: nil,
453433
wantErr: connect.NewError(connect.CodeInvalidArgument, schema.ValidateCustomPermission("Ab/resource", "get")),
454434
},
455-
{
456-
name: "should return bad request error if deprecated fields are sent without key",
457-
setup: func(as *mocks.PermissionService) {},
458-
request: connect.NewRequest(&frontierv1beta1.UpdatePermissionRequest{
459-
Id: testPermissions[testPermissionIdx].ID,
460-
Body: &frontierv1beta1.PermissionRequestBody{
461-
Name: testPermissions[testPermissionIdx].Name,
462-
Namespace: testPermissions[testPermissionIdx].NamespaceID,
463-
},
464-
}),
465-
want: nil,
466-
wantErr: connect.NewError(connect.CodeInvalidArgument, ErrPermissionKeyNotation),
467-
},
468435
{
469436
name: "should return success if permission service return nil error",
470437
setup: func(as *mocks.PermissionService) {
@@ -483,8 +450,6 @@ func TestHandler_UpdatePermission(t *testing.T) {
483450
want: connect.NewResponse(&frontierv1beta1.UpdatePermissionResponse{
484451
Permission: &frontierv1beta1.Permission{
485452
Id: testPermissions[testPermissionIdx].ID,
486-
Name: testPermissions[testPermissionIdx].Name,
487-
Namespace: testPermissions[testPermissionIdx].NamespaceID,
488453
Key: schema.PermissionKeyFromNamespaceAndName(testPermissions[testPermissionIdx].NamespaceID, testPermissions[testPermissionIdx].Name),
489454
CreatedAt: timestamppb.New(testPermissions[testPermissionIdx].CreatedAt),
490455
UpdatedAt: timestamppb.New(testPermissions[testPermissionIdx].UpdatedAt),
@@ -537,24 +502,18 @@ func TestHandler_ListPermissions(t *testing.T) {
537502
Permissions: []*frontierv1beta1.Permission{
538503
{
539504
Id: testPermissions[0].ID,
540-
Name: testPermissions[0].Name,
541-
Namespace: testPermissions[0].NamespaceID,
542505
Key: schema.PermissionKeyFromNamespaceAndName(testPermissions[0].NamespaceID, testPermissions[0].Name),
543506
CreatedAt: timestamppb.New(testPermissions[0].CreatedAt),
544507
UpdatedAt: timestamppb.New(testPermissions[0].UpdatedAt),
545508
},
546509
{
547510
Id: testPermissions[1].ID,
548-
Name: testPermissions[1].Name,
549-
Namespace: testPermissions[1].NamespaceID,
550511
Key: schema.PermissionKeyFromNamespaceAndName(testPermissions[1].NamespaceID, testPermissions[1].Name),
551512
CreatedAt: timestamppb.New(testPermissions[1].CreatedAt),
552513
UpdatedAt: timestamppb.New(testPermissions[1].UpdatedAt),
553514
},
554515
{
555516
Id: testPermissions[2].ID,
556-
Name: testPermissions[2].Name,
557-
Namespace: testPermissions[2].NamespaceID,
558517
Key: schema.PermissionKeyFromNamespaceAndName(testPermissions[2].NamespaceID, testPermissions[2].Name),
559518
CreatedAt: timestamppb.New(testPermissions[2].CreatedAt),
560519
UpdatedAt: timestamppb.New(testPermissions[2].UpdatedAt),
@@ -630,8 +589,6 @@ func TestHandler_GetPermission(t *testing.T) {
630589
want: connect.NewResponse(&frontierv1beta1.GetPermissionResponse{
631590
Permission: &frontierv1beta1.Permission{
632591
Id: testPermissions[testPermissionIdx].ID,
633-
Name: testPermissions[testPermissionIdx].Name,
634-
Namespace: testPermissions[testPermissionIdx].NamespaceID,
635592
Key: schema.PermissionKeyFromNamespaceAndName(testPermissions[testPermissionIdx].NamespaceID, testPermissions[testPermissionIdx].Name),
636593
CreatedAt: timestamppb.New(testPermissions[testPermissionIdx].CreatedAt),
637594
UpdatedAt: timestamppb.New(testPermissions[testPermissionIdx].UpdatedAt),

0 commit comments

Comments
 (0)