Skip to content

Commit b8a2ee9

Browse files
authored
support edit access keys attributes (#406)
* allow nil permitted IPs * more
1 parent ad2676f commit b8a2ee9

File tree

3 files changed

+58
-8
lines changed

3 files changed

+58
-8
lines changed

examples/managementCli/src/index.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ program
289289
.description('Create a new access key')
290290
.argument('<name>', 'Access key name')
291291
.argument('<expire-time>', 'Access key expiration time')
292+
.option('--description <value>', 'Access key description')
293+
.option('--permitted-ips <ips>', 'Permitted IPs', (val) => val?.split(','))
292294
.option(
293295
'-t, --tenants <t1,t2>',
294296
`Access key's tenant IDs`,
@@ -305,6 +307,10 @@ program
305307
expireTime,
306308
undefined,
307309
options.tenants?.map((tenantId: string) => ({ tenantId })),
310+
undefined,
311+
undefined,
312+
options.description,
313+
options.permittedIps,
308314
),
309315
);
310316
});
@@ -315,8 +321,20 @@ program
315321
.description('Update an access key')
316322
.argument('<id>', 'Access key ID')
317323
.argument('<name>', 'Access key name')
318-
.action(async (id, name) => {
319-
handleSdkRes(await sdk.management.accessKey.update(id, name));
324+
.option('--description <value>', 'Access key description')
325+
.option('--permitted-ips <ips>', 'Permitted IPs', (val) => val?.split(','))
326+
.action(async (id, name, options) => {
327+
handleSdkRes(
328+
await sdk.management.accessKey.update(
329+
id,
330+
name,
331+
options.description,
332+
undefined,
333+
undefined,
334+
undefined,
335+
options.permittedIps,
336+
),
337+
);
320338
});
321339

322340
// access-key-delete

lib/management/accesskey.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,23 @@ describe('Management Access Keys', () => {
150150
'id',
151151
'name',
152152
'description',
153+
['r1', 'r2'],
154+
undefined,
155+
{ k1: 'v1' },
156+
['1.2.3.4'],
153157
);
154158

155159
expect(mockHttpClient.post).toHaveBeenCalledWith(
156160
apiPaths.accessKey.update,
157-
{ id: 'id', name: 'name', description: 'description' },
161+
{
162+
id: 'id',
163+
name: 'name',
164+
description: 'description',
165+
roleNames: ['r1', 'r2'],
166+
keyTenants: undefined,
167+
customClaims: { k1: 'v1' },
168+
permittedIps: ['1.2.3.4'],
169+
},
158170
{ token: 'key' },
159171
);
160172

lib/management/accesskey.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const withAccessKey = (sdk: CoreSdk, managementKey?: string) => ({
1717
* @param name Access key name
1818
* @param expireTime When the access key expires. Keep at 0 to make it indefinite.
1919
* @param roles Optional roles in the project. Does not apply for multi-tenants
20-
* @param keyTenants Optional associated tenants for this key and its roles for each.
20+
* @param tenants Optional associated tenants for this key and its roles for each.
2121
* @param userId Optional bind this access key to a specific user.
2222
* @param customClaims Optional map of claims and their values that will be present in the JWT.
2323
* @param description Optional free text description
@@ -28,7 +28,7 @@ const withAccessKey = (sdk: CoreSdk, managementKey?: string) => ({
2828
name: string,
2929
expireTime: number,
3030
roles?: string[],
31-
keyTenants?: AssociatedTenant[],
31+
tenants?: AssociatedTenant[],
3232
userId?: string,
3333
customClaims?: Record<string, any>,
3434
description?: string,
@@ -41,7 +41,7 @@ const withAccessKey = (sdk: CoreSdk, managementKey?: string) => ({
4141
name,
4242
expireTime,
4343
roleNames: roles,
44-
keyTenants,
44+
keyTenants: tenants,
4545
userId,
4646
customClaims,
4747
description,
@@ -78,13 +78,33 @@ const withAccessKey = (sdk: CoreSdk, managementKey?: string) => ({
7878
* @param id Access key ID to load
7979
* @param name The updated access key name
8080
* @param description Optional updated access key description
81+
* @param roles Optional roles in the project. Does not apply for multi-tenants
82+
* @param tenants Optional associated tenants for this key and its roles for each.
83+
* @param customClaims Optional map of claims and their values that will be present in the JWT.
84+
* @param permittedIps Optional list of IP addresses or CIDR ranges that are allowed to use this access key.
8185
* @returns The updated access key
8286
*/
83-
update: (id: string, name: string, description?: string): Promise<SdkResponse<AccessKey>> =>
87+
update: (
88+
id: string,
89+
name: string,
90+
description?: string,
91+
roles?: string[],
92+
tenants?: AssociatedTenant[],
93+
customClaims?: Record<string, any>,
94+
permittedIps?: string[],
95+
): Promise<SdkResponse<AccessKey>> =>
8496
transformResponse<SingleKeyResponse, AccessKey>(
8597
sdk.httpClient.post(
8698
apiPaths.accessKey.update,
87-
{ id, name, description },
99+
{
100+
id,
101+
name,
102+
description,
103+
roleNames: roles,
104+
keyTenants: tenants,
105+
customClaims,
106+
permittedIps,
107+
},
88108
{ token: managementKey },
89109
),
90110
(data) => data.key,

0 commit comments

Comments
 (0)