-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create fromServiceAtrributes, remove ImportedBaseService. Some tests
- Loading branch information
1 parent
fba4573
commit 6e1d696
Showing
8 changed files
with
325 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
packages/@aws-cdk/aws-ecs/lib/base/from-service-attributes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Construct, Resource, Stack } from '@aws-cdk/core'; | ||
import { IBaseService } from '../base/base-service'; | ||
import { ICluster } from '../cluster'; | ||
|
||
/** | ||
* The properties to import from the service. | ||
*/ | ||
export interface ServiceAttributes { | ||
/** | ||
* The cluster that hosts the service. | ||
*/ | ||
readonly cluster: ICluster; | ||
|
||
/** | ||
* The service ARN. | ||
* | ||
* @default - generated from serviceName | ||
*/ | ||
readonly serviceArn?: string; | ||
|
||
/** | ||
* The name of the service. | ||
* | ||
* @default - generated from serviceArn | ||
*/ | ||
readonly serviceName?: string; | ||
} | ||
|
||
export function fromServiceAtrributes(scope: Construct, id: string, attrs: ServiceAttributes): IBaseService { | ||
if ((attrs.serviceArn && attrs.serviceName) || (!attrs.serviceArn && !attrs.serviceName)) { | ||
throw new Error('You can only specify either serviceArn or serviceName.'); | ||
} | ||
|
||
const stack = Stack.of(scope); | ||
let name: string; | ||
let arn: string; | ||
if (attrs.serviceName) { | ||
name = attrs.serviceName as string; | ||
arn = stack.formatArn({ | ||
partition: stack.partition, | ||
service: 'ecs', | ||
region: stack.region, | ||
account: stack.account, | ||
resource: 'service', | ||
resourceName: name, | ||
}); | ||
} else { | ||
arn = attrs.serviceArn as string; | ||
name = stack.parseArn(arn).resourceName as string; | ||
} | ||
class Import extends Resource implements IBaseService { | ||
public readonly serviceArn = arn; | ||
public readonly serviceName = name; | ||
public readonly cluster = attrs.cluster; | ||
} | ||
return new Import(scope, id); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.