@@ -2,8 +2,8 @@ import { ApigwRemoveInputs } from './../apigw/interface';
2
2
import { ActionType } from './apis' ;
3
3
import { RegionType , ApiServiceType , CapiCredentials } from './../interface' ;
4
4
import { Capi } from '@tencent-sdk/capi' ;
5
- import { ApiTypeError } from '../../utils/error' ;
6
- import { deepClone , strip } from '../../utils' ;
5
+ import { ApiError , ApiTypeError } from '../../utils/error' ;
6
+ import { deepClone , getQcsResourceId , isAddedYunTiTags , strip } from '../../utils' ;
7
7
import TagsUtils from '../tag/index' ;
8
8
import ApigwUtils from '../apigw' ;
9
9
import CONFIGS from './config' ;
@@ -25,6 +25,9 @@ import ScfEntity from './entities/scf';
25
25
import AliasEntity from './entities/alias' ;
26
26
import VersionEntity from './entities/version' ;
27
27
import { ConcurrencyEntity } from './entities/concurrency' ;
28
+ import { default as Cam } from '../cam' ;
29
+ import { YunTiTagDocHref } from './constants' ;
30
+ import { checkYunTi } from '../../utils/api' ;
28
31
29
32
/** 云函数组件 */
30
33
export default class Scf {
@@ -262,6 +265,29 @@ export default class Scf {
262
265
} ,
263
266
} ) ;
264
267
268
+ // 如果触发器类型为 API 网关触发器 且当前账号是自研账号,则需要为 API 网关触发器添加函数标签
269
+ if ( trigger . Type === ApiServiceType . apigw ) {
270
+ try {
271
+ const cam = new Cam ( this . credentials , this . region ) ;
272
+ const userInfo = await cam . GetUserAppId ( ) ;
273
+ const isYunTi = await checkYunTi ( userInfo ?. OwnerUin ) ;
274
+ if ( isYunTi ) {
275
+ await this . tagClient . deployResourceTags ( {
276
+ tags : funcInfo . Tags . map ( ( { Key, Value } ) => ( { TagKey : Key , TagValue : Value } ) ) ,
277
+ resourceId : getQcsResourceId (
278
+ ApiServiceType . apigw ,
279
+ this . region ,
280
+ userInfo . OwnerUin ,
281
+ `service/${ triggerOutput ?. serviceId } ` ,
282
+ ) ,
283
+ serviceType : ApiServiceType . apigw ,
284
+ resourcePrefix : 'service' ,
285
+ } ) ;
286
+ }
287
+ } catch ( error ) {
288
+ console . log ( 'adding tags for trigger resource error:' , error ?. message )
289
+ }
290
+ }
265
291
deployList [ i ] = {
266
292
NeedCreate : trigger ?. NeedCreate ,
267
293
...triggerOutput ,
@@ -278,6 +304,23 @@ export default class Scf {
278
304
const functionName = inputs . name ;
279
305
const { ignoreTriggers = false } = inputs ;
280
306
307
+ // 自研账号,需要检查函数标签是否配置云梯标签(运营部门、运营产品、负责人); 非自研账号,不需要检查
308
+ const cam = new Cam ( this . credentials , this . region ) ;
309
+ const userInfo = await cam . GetUserAppId ( ) ;
310
+ const isYunTi = await checkYunTi ( userInfo ?. OwnerUin ) ;
311
+ if ( isYunTi ) {
312
+ if (
313
+ ! isAddedYunTiTags (
314
+ Object . entries ( inputs . tags || { } ) . map ( ( [ TagKey , TagValue ] ) => ( { TagKey, TagValue } ) ) ,
315
+ )
316
+ ) {
317
+ throw new ApiError ( {
318
+ type : 'API_SCF_DeployFunction' ,
319
+ message : `部署失败:自研用户请按照运营部门、运营产品、负责人正确配置函数标签,标签配置指南请参考:${ YunTiTagDocHref } ` ,
320
+ } ) ;
321
+ }
322
+ }
323
+
281
324
// 在部署前,检查函数初始状态,如果初始为 CreateFailed,尝试先删除,再重新创建
282
325
let funcInfo = await this . scf . getInitialStatus ( { namespace, functionName } ) ;
283
326
0 commit comments