@@ -210,7 +210,7 @@ class Apigw {
210
210
}
211
211
}
212
212
213
- async createOrUpdateApi ( { serviceId, endpoint } ) {
213
+ async createOrUpdateApi ( { serviceId, endpoint, created } ) {
214
214
const output = {
215
215
path : endpoint . path ,
216
216
method : endpoint . method ,
@@ -298,6 +298,7 @@ class Apigw {
298
298
apiId : endpoint . apiId ,
299
299
...apiInputs ,
300
300
} ) ;
301
+ output . created = ! ! created ;
301
302
output . apiId = endpoint . apiId ;
302
303
output . internalDomain = apiDetail . InternalDomain ;
303
304
console . log ( `Service with id ${ output . apiId } updated.` ) ;
@@ -307,9 +308,9 @@ class Apigw {
307
308
return output ;
308
309
}
309
310
310
- async setupUsagePlanSecret ( { secretName, secretIds } ) {
311
+ async setupUsagePlanSecret ( { secretName, secretIds, created } ) {
311
312
const secretIdsOutput = {
312
- created : false ,
313
+ created : ! ! created ,
313
314
secretIds,
314
315
} ;
315
316
@@ -321,7 +322,7 @@ class Apigw {
321
322
SecretName : secretName ,
322
323
AccessKeyType : 'auto' ,
323
324
} ) ;
324
- console . log ( `Secret key with ID ${ AccessKeyId } and key ${ AccessKeySecret } updated. ` ) ;
325
+ console . log ( `Secret key with ID ${ AccessKeyId } and key ${ AccessKeySecret } created ` ) ;
325
326
secretIdsOutput . secretIds = [ AccessKeyId ] ;
326
327
secretIdsOutput . created = true ;
327
328
} else {
@@ -614,14 +615,13 @@ class Apigw {
614
615
615
616
if ( exist ) {
616
617
endpoint . apiId = exist . apiId ;
618
+ endpoint . created = exist . created ;
617
619
}
618
620
const curApi = await this . createOrUpdateApi ( {
619
621
serviceId,
620
622
endpoint,
623
+ created : exist && exist . created ,
621
624
} ) ;
622
- if ( exist ) {
623
- curApi . created = true ;
624
- }
625
625
626
626
// set api auth and use plan
627
627
if ( endpoint . auth ) {
@@ -636,10 +636,16 @@ class Apigw {
636
636
// store in api list
637
637
curApi . usagePlan = usagePlan ;
638
638
639
- const { secretIds = [ ] } = endpoint . auth ;
639
+ let secretCreated = false ;
640
+ let { secretIds = [ ] } = endpoint . auth ;
641
+ if ( exist && exist . usagePlan && exist . usagePlan . secrets ) {
642
+ secretIds = secretIds . concat ( exist . usagePlan . secrets . secretIds ) ;
643
+ secretCreated = exist . usagePlan . secrets . created ;
644
+ }
640
645
const secrets = await this . setupUsagePlanSecret ( {
641
646
secretName : endpoint . auth . secretName ,
642
647
secretIds,
648
+ created : secretCreated ,
643
649
} ) ;
644
650
645
651
const unboundSecretIds = await this . getUnboundSecretIds ( {
@@ -688,7 +694,7 @@ class Apigw {
688
694
console . log ( `Deploy service with id ${ serviceId } successfully.` ) ;
689
695
690
696
const outputs = {
691
- created : serviceCreated ,
697
+ created : serviceCreated || oldState . created ,
692
698
serviceId,
693
699
serviceName,
694
700
subDomain,
@@ -810,16 +816,16 @@ class Apigw {
810
816
}
811
817
}
812
818
813
- // 3. unrelease service
814
- console . log ( `Unreleasing service: ${ serviceId } , environment: ${ environment } ` ) ;
815
- await this . removeOrUnbindRequest ( {
816
- Action : 'UnReleaseService' ,
817
- serviceId,
818
- environmentName : environment ,
819
- } ) ;
820
- console . log ( `Unrelease service: ${ serviceId } , environment: ${ environment } success` ) ;
821
-
822
819
if ( created === true ) {
820
+ // unrelease service
821
+ console . log ( `Unreleasing service: ${ serviceId } , environment: ${ environment } ` ) ;
822
+ await this . removeOrUnbindRequest ( {
823
+ Action : 'UnReleaseService' ,
824
+ serviceId,
825
+ environmentName : environment ,
826
+ } ) ;
827
+ console . log ( `Unrelease service: ${ serviceId } , environment: ${ environment } success` ) ;
828
+
823
829
// delete service
824
830
console . log ( `Removing service: ${ serviceId } ` ) ;
825
831
await this . removeOrUnbindRequest ( {
0 commit comments