Skip to content

Commit 8208774

Browse files
authored
feat(efs): allow AccessPoint to set client token (#31184)
### Reason for this change The [CfnAccessPoint](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_efs.CfnAccessPoint.html) construct supports client token specification. However, the current L2 implementation of [AccessPoint](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_efs.AccessPoint.html) does not support this property. The `disable-update-workflow` option was needed when running the updated integration test. ### Description of changes Added the `clientToken` prop to the existing props of AccessPoint. ### Description of how you validated changes Validated with unit and integration testing. ### Checklist - [X] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 4aa117b commit 8208774

File tree

11 files changed

+68
-13
lines changed

11 files changed

+68
-13
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-efs/test/integ.efs.js.snapshot/cdk.out

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-efs/test/integ.efs.js.snapshot/integ.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-efs/test/integ.efs.js.snapshot/manifest.json

+8-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-efs/test/integ.efs.js.snapshot/test-efs-integ.assets.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-efs/test/integ.efs.js.snapshot/test-efs-integ.template.json

+1
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@
458458
"Value": "test-efs-integ/FileSystem/AccessPoint"
459459
}
460460
],
461+
"ClientToken": "client-token",
461462
"FileSystemId": {
462463
"Ref": "FileSystem8A8E25C0"
463464
},

packages/@aws-cdk-testing/framework-integ/test/aws-efs/test/integ.efs.js.snapshot/testefsintegtestDefaultTestDeployAssert7E1529D5.assets.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-efs/test/integ.efs.js.snapshot/tree.json

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-efs/test/integ.efs.ts

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ fileSystem.addAccessPoint('AccessPoint', {
2424
gid: '1000',
2525
uid: '1000',
2626
},
27+
clientToken: 'client-token',
2728
});
2829

2930
new integ.IntegTest(app, 'test-efs-integ-test', {

packages/aws-cdk-lib/aws-efs/README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,10 @@ the access point can only access data in its own directory and below. To learn m
217217
Use the `addAccessPoint` API to create an access point from a fileSystem.
218218

219219
```ts fixture=with-filesystem-instance
220-
fileSystem.addAccessPoint('AccessPoint');
220+
fileSystem.addAccessPoint('MyAccessPoint', {
221+
// create a unique access point via an optional client token
222+
clientToken: 'client-token',
223+
});
221224
```
222225

223226
By default, when you create an access point, the root(`/`) directory is exposed to the client

packages/aws-cdk-lib/aws-efs/lib/access-point.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Construct } from 'constructs';
22
import { IFileSystem } from './efs-file-system';
33
import { CfnAccessPoint } from './efs.generated';
4-
import { ArnFormat, IResource, Resource, Stack, Tags } from '../../core';
4+
import { ArnFormat, IResource, Resource, Stack, Tags, Token } from '../../core';
55

66
/**
77
* Represents an EFS AccessPoint
@@ -102,6 +102,15 @@ export interface AccessPointOptions {
102102
* @default - user identity not enforced
103103
*/
104104
readonly posixUser?: PosixUser;
105+
106+
/**
107+
* The opaque string specified in the request to ensure idempotent creation.
108+
*
109+
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-efs-accesspoint.html#cfn-efs-accesspoint-clienttoken
110+
*
111+
* @default - No client token
112+
*/
113+
readonly clientToken?: string;
105114
}
106115

107116
/**
@@ -201,6 +210,11 @@ export class AccessPoint extends AccessPointBase {
201210
constructor(scope: Construct, id: string, props: AccessPointProps) {
202211
super(scope, id);
203212

213+
const clientToken = props.clientToken;
214+
if ((clientToken?.length === 0 || (clientToken && clientToken.length > 64)) && !Token.isUnresolved(clientToken)) {
215+
throw new Error(`The length of \'clientToken\' must range from 1 to 64 characters, got: ${clientToken.length} characters`);
216+
}
217+
204218
const resource = new CfnAccessPoint(this, 'Resource', {
205219
fileSystemId: props.fileSystem.fileSystemId,
206220
rootDirectory: {
@@ -216,6 +230,7 @@ export class AccessPoint extends AccessPointBase {
216230
gid: props.posixUser.gid,
217231
secondaryGids: props.posixUser.secondaryGids,
218232
} : undefined,
233+
clientToken,
219234
});
220235

221236
Tags.of(this).add('Name', this.node.path);

packages/aws-cdk-lib/aws-efs/test/access-point.test.ts

+29
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,35 @@ test('support tags for AccessPoint', () => {
5050
});
5151
});
5252

53+
test('allow client token to be set for AccessPoint', () => {
54+
// WHEN
55+
new AccessPoint(stack, 'MyAccessPoint', {
56+
fileSystem,
57+
clientToken: 'client-token',
58+
});
59+
60+
// THEN
61+
Template.fromStack(stack).hasResourceProperties('AWS::EFS::AccessPoint', {
62+
ClientToken: 'client-token',
63+
});
64+
});
65+
66+
test('throw when client token has a length that is less than 1', () => {
67+
expect(() => new AccessPoint(stack, 'MyAccessPoint', {
68+
fileSystem,
69+
clientToken: '',
70+
},
71+
)).toThrow(/The length of \'clientToken\' must range from 1 to 64 characters, got: 0 characters/);
72+
});
73+
74+
test('throw when client token has a length that is greater than 64', () => {
75+
expect(() => new AccessPoint(stack, 'MyAccessPoint', {
76+
fileSystem,
77+
clientToken: 'a'.repeat(65),
78+
},
79+
)).toThrow(/The length of \'clientToken\' must range from 1 to 64 characters, got: 65 characters/);
80+
});
81+
5382
test('import an AccessPoint using fromAccessPointId', () => {
5483
// WHEN
5584
const ap = new AccessPoint(stack, 'MyAccessPoint', {

0 commit comments

Comments
 (0)