From bc67866f579c401556d427eb150bcd118d69bd17 Mon Sep 17 00:00:00 2001 From: Matsuda Date: Wed, 30 Oct 2024 23:38:23 +0900 Subject: [PATCH] fix(location): remove base class from PlaceIndex class (#31287) ### Issue # (if applicable) None ### Reason for this change I implemented the location resources in #30711 and #30682. During the review, it was suggested that it would be better not to have a base class. As a result, the `GeofenceCollection` class and `RouteCalculator` class do not have a base class. https://github.com/aws/aws-cdk/pull/30711#discussion_r1734937879 On the other hand, the `PlaceIndex `class has already been implemented with a base class, which is inconsistent with the current approach. ### Description of changes Remove a unnecessary base class from `PlaceIndex` class. ### Description of how you validated changes Re-run unit tests and integ tests. ### 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* --- .../aws-location-alpha/lib/place-index.ts | 52 ++++++++----------- 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/packages/@aws-cdk/aws-location-alpha/lib/place-index.ts b/packages/@aws-cdk/aws-location-alpha/lib/place-index.ts index 026d8c5268a68..c1554300c33aa 100644 --- a/packages/@aws-cdk/aws-location-alpha/lib/place-index.ts +++ b/packages/@aws-cdk/aws-location-alpha/lib/place-index.ts @@ -74,39 +74,12 @@ export enum IntendedUse { STORAGE = 'Storage', } -abstract class PlaceIndexBase extends Resource implements IPlaceIndex { - public abstract readonly placeIndexName: string; - public abstract readonly placeIndexArn: string; - - /** - * Grant the given principal identity permissions to perform the actions on this place index. - */ - public grant(grantee: iam.IGrantable, ...actions: string[]): iam.Grant { - return iam.Grant.addToPrincipal({ - grantee: grantee, - actions: actions, - resourceArns: [this.placeIndexArn], - }); - } - - /** - * Grant the given identity permissions to search using this index - */ - public grantSearch(grantee: iam.IGrantable): iam.Grant { - return this.grant(grantee, - 'geo:SearchPlaceIndexForPosition', - 'geo:SearchPlaceIndexForSuggestions', - 'geo:SearchPlaceIndexForText', - ); - } -} - /** * A Place Index * * @see https://docs.aws.amazon.com/location/latest/developerguide/places-concepts.html */ -export class PlaceIndex extends PlaceIndexBase { +export class PlaceIndex extends Resource implements IPlaceIndex { /** * Use an existing place index by name */ @@ -130,7 +103,7 @@ export class PlaceIndex extends PlaceIndexBase { throw new Error(`Place Index Arn ${placeIndexArn} does not have a resource name.`); } - class Import extends PlaceIndexBase { + class Import extends Resource implements IPlaceIndex { public readonly placeIndexName = parsedArn.resourceName!; public readonly placeIndexArn = placeIndexArn; } @@ -187,4 +160,25 @@ export class PlaceIndex extends PlaceIndexBase { this.placeIndexUpdateTime = placeIndex.attrUpdateTime; } + /** + * Grant the given principal identity permissions to perform the actions on this place index. + */ + public grant(grantee: iam.IGrantable, ...actions: string[]): iam.Grant { + return iam.Grant.addToPrincipal({ + grantee: grantee, + actions: actions, + resourceArns: [this.placeIndexArn], + }); + } + + /** + * Grant the given identity permissions to search using this index + */ + public grantSearch(grantee: iam.IGrantable): iam.Grant { + return this.grant(grantee, + 'geo:SearchPlaceIndexForPosition', + 'geo:SearchPlaceIndexForSuggestions', + 'geo:SearchPlaceIndexForText', + ); + } }