1
1
import * as ros from '@alicloud/ros-cdk-core' ;
2
2
import { Context , EventDomain , EventTypes , ServerlessIac } from '../../types' ;
3
3
import * as ram from '@alicloud/ros-cdk-ram' ;
4
- import { encodeBase64ForRosId , calcRefs , splitDomain } from '../../common' ;
4
+ import { calcRefs , calcValue , formatRosId , splitDomain } from '../../common' ;
5
5
import * as agw from '@alicloud/ros-cdk-apigateway' ;
6
6
import { isEmpty } from 'lodash' ;
7
7
import * as dns from '@alicloud/ros-cdk-dns' ;
@@ -22,9 +22,9 @@ export const resolveEvents = (
22
22
apiGateway . forEach ( ( event ) => {
23
23
const gatewayAccessRole = new ram . RosRole (
24
24
scope ,
25
- calcRefs ( `${ event . key } _role` , context ) ,
25
+ formatRosId ( `${ event . key } _agw_role` ) ,
26
26
{
27
- roleName : calcRefs ( `${ service } - ${ event . name } -agw-access-role` , context ) ,
27
+ roleName : calcRefs ( `${ event . name } -agw-access-role` , context ) ,
28
28
description : calcRefs ( `${ service } role` , context ) ,
29
29
assumeRolePolicyDocument : {
30
30
version : '1' ,
@@ -60,20 +60,20 @@ export const resolveEvents = (
60
60
61
61
const apiGatewayGroup = new agw . RosGroup (
62
62
scope ,
63
- calcRefs ( `${ service } _apigroup` , context ) ,
63
+ formatRosId ( `${ event . key } _agw_group` ) ,
64
64
{
65
- groupName : calcRefs ( `${ service } _apigroup ` , context ) ,
65
+ groupName : calcRefs ( `${ service } -agw-group ` , context ) ,
66
66
tags : calcRefs ( tags , context ) ,
67
67
passthroughHeaders : 'host' ,
68
68
} ,
69
69
true ,
70
70
) ;
71
71
72
72
if ( event . domain ) {
73
- const dnsRecordRosId = `${ event . key } _custom_domain_record_ ${ encodeBase64ForRosId ( event . domain . domain_name ) } ` ;
73
+ const dnsRecordId = formatRosId ( `${ event . key } _agw_custom_domain_record` ) ;
74
74
const { domainName, rr } = splitDomain ( event . domain ?. domain_name ) ;
75
75
76
- new dns . DomainRecord ( scope , dnsRecordRosId , {
76
+ new dns . DomainRecord ( scope , dnsRecordId , {
77
77
domainName,
78
78
rr,
79
79
type : 'CNAME' ,
@@ -82,7 +82,7 @@ export const resolveEvents = (
82
82
83
83
const agwCustomDomain = new agw . RosCustomDomain (
84
84
scope ,
85
- `${ event . key } _custom_domain_ ${ encodeBase64ForRosId ( event . domain . domain_name ) } ` ,
85
+ formatRosId ( `${ event . key } _agw_custom_domain` ) ,
86
86
{
87
87
groupId : apiGatewayGroup . attrGroupId ,
88
88
domainName : event . domain . domain_name ,
@@ -92,17 +92,16 @@ export const resolveEvents = (
92
92
} ,
93
93
true ,
94
94
) ;
95
- agwCustomDomain . addRosDependency ( dnsRecordRosId ) ;
95
+ agwCustomDomain . addRosDependency ( dnsRecordId ) ;
96
96
}
97
97
98
98
event . triggers . forEach ( ( trigger ) => {
99
- const key = encodeBase64ForRosId ( calcRefs ( `${ trigger . method } _${ trigger . path } ` , context ) ) ;
100
-
99
+ const key = formatRosId ( calcValue ( `${ trigger . method } _${ trigger . path } ` , context ) ) ;
101
100
const api = new agw . RosApi (
102
101
scope ,
103
- `${ event . key } _api_ ${ key } ` ,
102
+ formatRosId ( `${ event . key } _agw_api_ ${ key } ` ) ,
104
103
{
105
- apiName : calcRefs ( `${ event . name } _api_ ${ key } ` , context ) ,
104
+ apiName : calcRefs ( `${ event . name } -agw-api- ${ key . replace ( / _ / g , '-' ) } ` , context ) ,
106
105
groupId : apiGatewayGroup . attrGroupId ,
107
106
visibility : 'PRIVATE' ,
108
107
authType : 'ANONYMOUS' ,
@@ -130,11 +129,14 @@ export const resolveEvents = (
130
129
) ;
131
130
api . addDependsOn ( apiGatewayGroup ) ;
132
131
133
- new agw . Deployment ( scope , `${ service } _deployment` , {
132
+ new agw . Deployment ( scope , formatRosId ( `${ event . key } _agw_api_deployment_ ${ key } ` ) , {
134
133
apiId : api . attrApiId ,
135
134
groupId : apiGatewayGroup . attrGroupId ,
136
135
stageName : 'RELEASE' ,
137
- description : `${ service } Api Gateway deployment` ,
136
+ description : calcRefs (
137
+ `${ service } Api Gateway deployment for api: ${ trigger . method } ${ trigger . path } ` ,
138
+ context ,
139
+ ) ,
138
140
} ) ;
139
141
} ) ;
140
142
} ) ;
0 commit comments