Skip to content

Commit 3f440ad

Browse files
committed
Refactor RBAC to use new CRUD roles actions, update CI
1 parent 1b67dbf commit 3f440ad

File tree

6 files changed

+33
-11
lines changed

6 files changed

+33
-11
lines changed

.github/workflows/main.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ env:
1212
WEAVIATE_126: 1.26.14
1313
WEAVIATE_127: 1.27.11
1414
WEAVIATE_128: 1.28.4
15-
WEAVIATE_129: 1.29.0-rc.0-a8c0bce
15+
WEAVIATE_129: 1.29.0-rc.1
1616

1717
jobs:
1818
checks:

src/openapi/schema.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,10 @@ export interface definitions {
340340
| 'update_data'
341341
| 'delete_data'
342342
| 'read_nodes'
343-
| 'manage_roles'
343+
| 'create_roles'
344344
| 'read_roles'
345+
| 'update_roles'
346+
| 'delete_roles'
345347
| 'create_collections'
346348
| 'read_collections'
347349
| 'update_collections'
@@ -1933,7 +1935,9 @@ export interface operations {
19331935
schema: definitions['ErrorResponse'];
19341936
};
19351937
/** role or user is not found. */
1936-
404: unknown;
1938+
404: {
1939+
schema: definitions['ErrorResponse'];
1940+
};
19371941
/** An error has occurred while trying to fulfill the request. Most likely the ErrorResponse will contain more information about the error. */
19381942
500: {
19391943
schema: definitions['ErrorResponse'];
@@ -1967,7 +1971,9 @@ export interface operations {
19671971
schema: definitions['ErrorResponse'];
19681972
};
19691973
/** role or user is not found. */
1970-
404: unknown;
1974+
404: {
1975+
schema: definitions['ErrorResponse'];
1976+
};
19711977
/** An error has occurred while trying to fulfill the request. Most likely the ErrorResponse will contain more information about the error. */
19721978
500: {
19731979
schema: definitions['ErrorResponse'];

src/roles/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,20 @@ export const permissions = {
182182
return out;
183183
});
184184
},
185-
roles: (args: { role: string | string[]; read?: boolean; manage?: boolean }): RolesPermission[] => {
185+
roles: (args: {
186+
role: string | string[];
187+
create?: boolean;
188+
read?: boolean;
189+
update?: boolean;
190+
delete?: boolean;
191+
}): RolesPermission[] => {
186192
const roles = Array.isArray(args.role) ? args.role : [args.role];
187193
return roles.flatMap((role) => {
188194
const out: RolesPermission = { role, actions: [] };
195+
if (args.create) out.actions.push('create_roles');
189196
if (args.read) out.actions.push('read_roles');
190-
if (args.manage) out.actions.push('manage_roles');
197+
if (args.update) out.actions.push('update_roles');
198+
if (args.delete) out.actions.push('delete_roles');
191199
return out;
192200
});
193201
},

src/roles/integration.test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,23 @@ only('Integration testing of the roles namespace', () => {
157157
},
158158
{
159159
roleName: 'roles',
160-
permissions: weaviate.permissions.roles({ role: 'some-role', manage: true }),
160+
permissions: weaviate.permissions.roles({
161+
role: 'some-role',
162+
create: true,
163+
read: true,
164+
update: true,
165+
delete: true,
166+
}),
161167
expected: {
162168
name: 'roles',
163169
backupsPermissions: [],
164170
clusterPermissions: [],
165171
collectionsPermissions: [],
166172
dataPermissions: [],
167173
nodesPermissions: [],
168-
rolesPermissions: [{ role: 'some-role', actions: ['manage_roles'] }],
174+
rolesPermissions: [
175+
{ role: 'some-role', actions: ['create_roles', 'read_roles', 'update_roles', 'delete_roles'] },
176+
],
169177
},
170178
},
171179
];

src/roles/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export type DataAction = Extract<
1515
'create_data' | 'delete_data' | 'read_data' | 'update_data' | 'manage_data'
1616
>;
1717
export type NodesAction = Extract<Action, 'read_nodes'>;
18-
export type RolesAction = Extract<Action, 'manage_roles' | 'read_roles'>;
18+
export type RolesAction = Extract<Action, 'create_roles' | 'read_roles' | 'update_roles' | 'delete_roles'>;
1919

2020
export type BackupsPermission = {
2121
collection: string;

src/roles/util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class PermissionGuards {
4545
static isNodes = (permission: Permission): permission is NodesPermission =>
4646
PermissionGuards.includes(permission, 'read_nodes');
4747
static isRoles = (permission: Permission): permission is RolesPermission =>
48-
PermissionGuards.includes(permission, 'manage_roles');
48+
PermissionGuards.includes(permission, 'create_role', 'read_roles', 'update_roles', 'delete_roles');
4949
static isPermission = (permissions: PermissionsInput): permissions is Permission =>
5050
!Array.isArray(permissions);
5151
static isPermissionArray = (permissions: PermissionsInput): permissions is Permission[] =>
@@ -90,7 +90,7 @@ export class Map {
9090
} else if (PermissionGuards.isRoles(permission)) {
9191
return Array.from(permission.actions).map((action) => ({ roles: { role: permission.role }, action }));
9292
} else {
93-
throw new Error(`Unknown permission type: ${permission}`);
93+
throw new Error(`Unknown permission type: ${JSON.stringify(permission, null, 2)}`);
9494
}
9595
};
9696

0 commit comments

Comments
 (0)