Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1945,13 +1945,29 @@ searchRes.data.keys.forEach((key) => {
});

// Update an existing management key.
// IMPORTANT: All parameters will override whatever values are currently set in the existing key.
// IMPORTANT: All parameters will override whatever values are currently set in the existing key,
// except reBac: when it is omitted, the key keeps its current roles.
await descopeClient.management.managementKey.update(
'key-id',
'updated-key-name',
'Updated description',
['1.2.3.4'], // updated permitted IPs
'active', // status: 'active' or 'inactive'
['1.2.3.4'], // updated permitted IPs
);

// Update the roles of an existing management key.
// When reBac is provided it replaces the key's current roles. The key secret is not rotated.
await descopeClient.management.managementKey.update(
'key-id',
'updated-key-name',
'Updated description',
'active',
['1.2.3.4'],
{
companyRoles: ['Admin'],
projectRoles: [{ projectIds: ['project-id'], roles: ['Project Admin'] }],
tagRoles: [{ tags: ['production'], roles: ['Read Only'] }],
},
);

// Delete management keys by IDs.
Expand Down
37 changes: 37 additions & 0 deletions lib/management/managementKey.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,43 @@ describe('Management Management Keys', () => {
permittedIps: ['1.1.1.1'],
status: 'inactive',
});
expect(mockHttpClient.patch.mock.calls[0][1]).not.toHaveProperty('reBac');
expect(resp.data).toEqual(mockMgmtKey);
});

it('should send reBac when provided', async () => {
const httpResponse = {
ok: true,
json: () => ({ key: mockMgmtKey }),
clone: () => ({
json: () => Promise.resolve({ key: mockMgmtKey }),
}),
status: 200,
};
mockHttpClient.patch.mockResolvedValue(httpResponse);

const reBac = {
companyRoles: ['role1'],
projectRoles: [{ projectIds: ['p1'], roles: ['role2'] }],
tagRoles: [{ tags: ['t1'], roles: ['role3'] }],
};
const resp = await management.managementKey.update(
'mk1',
'updated-key',
'updated-desc',
'active',
['1.1.1.1'],
reBac,
);

expect(mockHttpClient.patch).toHaveBeenCalledWith(apiPaths.managementKey.update, {
id: 'mk1',
name: 'updated-key',
description: 'updated-desc',
permittedIps: ['1.1.1.1'],
status: 'active',
reBac,
});
expect(resp.data).toEqual(mockMgmtKey);
});
});
Expand Down
3 changes: 3 additions & 0 deletions lib/management/managementKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const withManagementKey = (httpClient: HttpClient) => ({
description: string,
status: MgmtKeyStatus,
permittedIps?: string[],
reBac?: MgmtKeyReBac,
): Promise<SdkResponse<MgmtKey>> =>
transformResponse(
httpClient.patch(apiPaths.managementKey.update, {
Expand All @@ -34,6 +35,8 @@ const withManagementKey = (httpClient: HttpClient) => ({
description,
permittedIps,
status,
// reBac is sent only when provided, so omitting it keeps the key's current roles
...(reBac !== undefined ? { reBac } : {}),
}),
(data) => data.key,
),
Expand Down
Loading