Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support edit access keys attributes #406

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
14 changes: 12 additions & 2 deletions examples/managementCli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ program
.description('Create a new access key')
.argument('<name>', 'Access key name')
.argument('<expire-time>', 'Access key expiration time')
.option('--description <value>', 'Access key description')
.option('--permitted-ips <ips>', 'Permitted IPs', (val) => val?.split(','))
.option(
'-t, --tenants <t1,t2>',
`Access key's tenant IDs`,
Expand All @@ -304,6 +306,10 @@ program
expireTime,
undefined,
options.tenants?.map((tenantId: string) => ({ tenantId })),
undefined,
undefined,
options.description,
options.permittedIps,
),
);
});
Expand All @@ -314,8 +320,12 @@ program
.description('Update an access key')
.argument('<id>', 'Access key ID')
.argument('<name>', 'Access key name')
.action(async (id, name) => {
handleSdkRes(await sdk.management.accessKey.update(id, name));
.option('--description <value>', 'Access key description')
.option('--permitted-ips <ips>', 'Permitted IPs', (val) => val?.split(','))
.action(async (id, name, options) => {
handleSdkRes(
await sdk.management.accessKey.update(id, name, options.description, options.permittedIps),
);
});

// access-key-delete
Expand Down
14 changes: 13 additions & 1 deletion lib/management/accesskey.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,23 @@ describe('Management Access Keys', () => {
'id',
'name',
'description',
['r1', 'r2'],
undefined,
{ k1: 'v1' },
['1.2.3.4'],
);

expect(mockHttpClient.post).toHaveBeenCalledWith(
apiPaths.accessKey.update,
{ id: 'id', name: 'name', description: 'description' },
{
id: 'id',
name: 'name',
description: 'description',
roleNames: ['r1', 'r2'],
keyTenants: undefined,
customClaims: { k1: 'v1' },
permittedIps: ['1.2.3.4'],
},
{ token: 'key' },
);

Expand Down
30 changes: 25 additions & 5 deletions lib/management/accesskey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const withAccessKey = (sdk: CoreSdk, managementKey?: string) => ({
* @param name Access key name
* @param expireTime When the access key expires. Keep at 0 to make it indefinite.
* @param roles Optional roles in the project. Does not apply for multi-tenants
* @param keyTenants Optional associated tenants for this key and its roles for each.
* @param tenants Optional associated tenants for this key and its roles for each.
* @param userId Optional bind this access key to a specific user.
* @param customClaims Optional map of claims and their values that will be present in the JWT.
* @param description Optional free text description
Expand All @@ -28,7 +28,7 @@ const withAccessKey = (sdk: CoreSdk, managementKey?: string) => ({
name: string,
expireTime: number,
roles?: string[],
keyTenants?: AssociatedTenant[],
tenants?: AssociatedTenant[],
userId?: string,
customClaims?: Record<string, any>,
description?: string,
Expand All @@ -41,7 +41,7 @@ const withAccessKey = (sdk: CoreSdk, managementKey?: string) => ({
name,
expireTime,
roleNames: roles,
keyTenants,
keyTenants: tenants,
userId,
customClaims,
description,
Expand Down Expand Up @@ -78,13 +78,33 @@ const withAccessKey = (sdk: CoreSdk, managementKey?: string) => ({
* @param id Access key ID to load
* @param name The updated access key name
* @param description Optional updated access key description
* @param roles Optional roles in the project. Does not apply for multi-tenants
* @param tenants Optional associated tenants for this key and its roles for each.
* @param customClaims Optional map of claims and their values that will be present in the JWT.
* @param permittedIps Optional list of IP addresses or CIDR ranges that are allowed to use this access key.
* @returns The updated access key
*/
update: (id: string, name: string, description?: string): Promise<SdkResponse<AccessKey>> =>
update: (
id: string,
name: string,
description?: string,
roles?: string[],
tenants?: AssociatedTenant[],
customClaims?: Record<string, any>,
permittedIps?: string[],
): Promise<SdkResponse<AccessKey>> =>
transformResponse<SingleKeyResponse, AccessKey>(
sdk.httpClient.post(
apiPaths.accessKey.update,
{ id, name, description },
{
id,
name,
description,
roleNames: roles,
keyTenants: tenants,
customClaims,
permittedIps,
},
{ token: managementKey },
),
(data) => data.key,
Expand Down
Loading