Skip to content

Commit

Permalink
fix(location): remove base class from PlaceIndex class (#31287)
Browse files Browse the repository at this point in the history
### 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. 

#30711 (comment)

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*
  • Loading branch information
mazyu36 authored Oct 30, 2024
1 parent 157c37d commit bc67866
Showing 1 changed file with 23 additions and 29 deletions.
52 changes: 23 additions & 29 deletions packages/@aws-cdk/aws-location-alpha/lib/place-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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;
}
Expand Down Expand Up @@ -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',
);
}
}

0 comments on commit bc67866

Please sign in to comment.