@@ -21,6 +21,7 @@ import ApiEntity from './entities/api';
2121import UsagePlanEntity from './entities/usage-plan' ;
2222import CustomDomainEntity from './entities/custom-domain' ;
2323import { ApiError } from '../../utils/error' ;
24+ import TagClient from '../tag' ;
2425
2526export default class Apigw {
2627 credentials : CapiCredentials ;
@@ -31,6 +32,7 @@ export default class Apigw {
3132 api : ApiEntity ;
3233 customDomain : CustomDomainEntity ;
3334 usagePlan : UsagePlanEntity ;
35+ tagClient : TagClient ;
3436
3537 constructor ( credentials : CapiCredentials , region : RegionType = 'ap-guangzhou' ) {
3638 this . credentials = credentials ;
@@ -48,6 +50,8 @@ export default class Apigw {
4850 this . api = new ApiEntity ( this . capi , this . trigger ) ;
4951 this . usagePlan = new UsagePlanEntity ( this . capi ) ;
5052 this . customDomain = new CustomDomainEntity ( this . capi ) ;
53+
54+ this . tagClient = new TagClient ( this . credentials , this . region ) ;
5155 }
5256
5357 async request ( { Action, ...data } : { Action : ActionType ; [ key : string ] : any } ) {
@@ -119,6 +123,21 @@ export default class Apigw {
119123 outputs . usagePlan = usagePlan ;
120124 }
121125
126+ const { tags = [ ] } = inputs ;
127+ if ( tags . length > 0 ) {
128+ const deployedTags = await this . tagClient . deployResourceTags ( {
129+ tags : tags . map ( ( { key, value } ) => ( { TagKey : key , TagValue : value } ) ) ,
130+ resourceId : serviceId ,
131+ serviceType : ApiServiceType . apigw ,
132+ resourcePrefix : 'service' ,
133+ } ) ;
134+
135+ outputs . tags = deployedTags . map ( ( item ) => ( {
136+ key : item . TagKey ,
137+ value : item . TagValue ! ,
138+ } ) ) ;
139+ }
140+
122141 return outputs ;
123142 }
124143
@@ -188,6 +207,16 @@ export default class Apigw {
188207 } ) ;
189208 console . log ( `Unrelease service ${ serviceId } , environment ${ environment } success` ) ;
190209
210+ // 在删除之前,如果关联了标签,需要先删除标签关联
211+ if ( detail . Tags && detail . Tags . length > 0 ) {
212+ await this . tagClient . deployResourceTags ( {
213+ tags : [ ] ,
214+ resourceId : serviceId ,
215+ serviceType : ApiServiceType . apigw ,
216+ resourcePrefix : 'service' ,
217+ } ) ;
218+ }
219+
191220 // delete service
192221 console . log ( `Removing service ${ serviceId } ` ) ;
193222 await this . removeRequest ( {
@@ -233,6 +262,21 @@ export default class Apigw {
233262 apiList,
234263 } ;
235264
265+ const { tags = [ ] } = inputs ;
266+ if ( tags . length > 0 ) {
267+ const deployedTags = await this . tagClient . deployResourceTags ( {
268+ tags : tags . map ( ( { key, value } ) => ( { TagKey : key , TagValue : value } ) ) ,
269+ resourceId : serviceId ,
270+ serviceType : ApiServiceType . apigw ,
271+ resourcePrefix : 'service' ,
272+ } ) ;
273+
274+ outputs . tags = deployedTags . map ( ( item ) => ( {
275+ key : item . TagKey ,
276+ value : item . TagValue ! ,
277+ } ) ) ;
278+ }
279+
236280 return outputs ;
237281 }
238282 throw new ApiError ( {
0 commit comments