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

fix(location): underscores are not allowed in the name #32046

Merged
merged 5 commits into from
Nov 21, 2024
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
10 changes: 8 additions & 2 deletions packages/@aws-cdk/aws-location-alpha/lib/geofence-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,14 @@ export class GeofenceCollection extends Resource implements IGeofenceCollection
throw new Error(`\`description\` must be between 0 and 1000 characters. Received: ${props.description.length} characters`);
}

if (props.geofenceCollectionName && !Token.isUnresolved(props.geofenceCollectionName) && !/^[-.\w]{1,100}$/.test(props.geofenceCollectionName)) {
throw new Error(`Invalid geofence collection name. The geofence collection name must be between 1 and 100 characters and contain only alphanumeric characters, hyphens, periods and underscores. Received: ${props.geofenceCollectionName}`);
if (props.geofenceCollectionName !== undefined && !Token.isUnresolved(props.geofenceCollectionName)) {
if (props.geofenceCollectionName.length < 1 || props.geofenceCollectionName.length > 100) {
throw new Error(`\`geofenceCollectionName\` must be between 1 and 100 characters, got: ${props.geofenceCollectionName.length} characters.`);
}

if (!/^[-._\w]+$/.test(props.geofenceCollectionName)) {
throw new Error(`\`geofenceCollectionName\` must contain only alphanumeric characters, hyphens, periods and underscores, got: ${props.geofenceCollectionName}.`);
}
}

super(scope, id, {
Expand Down
10 changes: 8 additions & 2 deletions packages/@aws-cdk/aws-location-alpha/lib/place-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,14 @@ export class PlaceIndex extends Resource implements IPlaceIndex {
throw new Error(`\`description\` must be between 0 and 1000 characters. Received: ${props.description.length} characters`);
}

if (props.placeIndexName && !Token.isUnresolved(props.placeIndexName) && !/^[-.\w]{1,100}$/.test(props.placeIndexName)) {
throw new Error(`Invalid place index name. The place index name must be between 1 and 100 characters and contain only alphanumeric characters, hyphens, periods and underscores. Received: ${props.placeIndexName}`);
if (props.placeIndexName !== undefined && !Token.isUnresolved(props.placeIndexName)) {
if (props.placeIndexName.length < 1 || props.placeIndexName.length > 100) {
throw new Error(`\`placeIndexName\` must be between 1 and 100 characters, got: ${props.placeIndexName.length} characters.`);
}

if (!/^[-._\w]+$/.test(props.placeIndexName)) {
throw new Error(`\`placeIndexName\` must contain only alphanumeric characters, hyphens, periods and underscores, got: ${props.placeIndexName}.`);
}
}

super(scope, id, {
Expand Down
10 changes: 8 additions & 2 deletions packages/@aws-cdk/aws-location-alpha/lib/route-calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,14 @@ export class RouteCalculator extends Resource implements IRouteCalculator {
throw new Error(`\`description\` must be between 0 and 1000 characters. Received: ${props.description.length} characters`);
}

if (props.routeCalculatorName && !Token.isUnresolved(props.routeCalculatorName) && !/^[-.\w]{1,100}$/.test(props.routeCalculatorName)) {
throw new Error(`Invalid route calculator name. The route calculator name must be between 1 and 100 characters and contain only alphanumeric characters, hyphens, periods and underscores. Received: ${props.routeCalculatorName}`);
if (props.routeCalculatorName !== undefined && !Token.isUnresolved(props.routeCalculatorName)) {
if (props.routeCalculatorName.length < 1 || props.routeCalculatorName.length > 100) {
throw new Error(`\`routeCalculatorName\` must be between 1 and 100 characters, got: ${props.routeCalculatorName.length} characters.`);
}

if (!/^[-._\w]+$/.test(props.routeCalculatorName)) {
throw new Error(`\`routeCalculatorName\` must contain only alphanumeric characters, hyphens, periods and underscores, got: ${props.routeCalculatorName}.`);
}
}

super(scope, id, {
Expand Down
10 changes: 8 additions & 2 deletions packages/@aws-cdk/aws-location-alpha/lib/tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,14 @@ export class Tracker extends Resource implements ITracker {
throw new Error(`\`description\` must be between 0 and 1000 characters. Received: ${props.description.length} characters`);
}

if (props.trackerName && !Token.isUnresolved(props.trackerName) && !/^[-.\w]{1,100}$/.test(props.trackerName)) {
throw new Error(`Invalid tracker name. The tracker name must be between 1 and 100 characters and contain only alphanumeric characters, hyphens, periods and underscores. Received: ${props.trackerName}`);
if (props.trackerName !== undefined && !Token.isUnresolved(props.trackerName)) {
if (props.trackerName.length < 1 || props.trackerName.length > 100) {
throw new Error(`\`trackerName\` must be between 1 and 100 characters, got: ${props.trackerName.length} characters.`);
}

if (!/^[-._\w]+$/.test(props.trackerName)) {
throw new Error(`\`trackerName\` must contain only alphanumeric characters, hyphens, periods and underscores, got: ${props.trackerName}.`);
}
}

if (!Token.isUnresolved(props.kmsKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,26 @@ test('throws with invalid description', () => {
})).toThrow('`description` must be between 0 and 1000 characters. Received: 1001 characters');
});

test('create a geofence collection with name', () => {
new GeofenceCollection(stack, 'GeofenceCollection', {
geofenceCollectionName: 'my_geofence_collection',
});

Template.fromStack(stack).hasResourceProperties('AWS::Location::GeofenceCollection', {
CollectionName: 'my_geofence_collection',
});
});

test.each(['', 'a'.repeat(101)])('throws with invalid name, got: %s', (geofenceCollectionName) => {
expect(() => new GeofenceCollection(stack, 'GeofenceCollection', {
geofenceCollectionName,
})).toThrow(`\`geofenceCollectionName\` must be between 1 and 100 characters, got: ${geofenceCollectionName.length} characters.`);
});

test('throws with invalid name', () => {
expect(() => new GeofenceCollection(stack, 'GeofenceCollection', {
geofenceCollectionName: 'inv@lid',
})).toThrow('Invalid geofence collection name. The geofence collection name must be between 1 and 100 characters and contain only alphanumeric characters, hyphens, periods and underscores. Received: inv@lid');
})).toThrow('`geofenceCollectionName` must contain only alphanumeric characters, hyphens, periods and underscores, got: inv@lid.');
});

test('grant read actions', () => {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"GeofenceCollection6FAC681F": {
"Type": "AWS::Location::GeofenceCollection",
"Properties": {
"CollectionName": "MyGeofenceCollection",
"CollectionName": "my_geofence_collection",
"Description": "test",
"KmsKeyId": {
"Fn::GetAtt": [
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class TestStack extends Stack {
});

new GeofenceCollection(this, 'GeofenceCollection', {
geofenceCollectionName: 'MyGeofenceCollection',
geofenceCollectionName: 'my_geofence_collection',
description: 'test',
kmsKey,
});
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Type": "AWS::Location::PlaceIndex",
"Properties": {
"DataSource": "Esri",
"IndexName": "cdkinteglocationplaceindexPlaceIndex21A03EAC"
"IndexName": "my_place_index"
}
}
},
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading