diff --git a/CHANGELOG.md b/CHANGELOG.md index e795e01f..7bf8a60d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [2.25.1](https://github.com/serverless-tencent/tencent-component-toolkit/compare/v2.25.0...v2.25.1) (2024-04-28) + + +### Bug Fixes + +* multi-scf support yunti tag issue fix ([#299](https://github.com/serverless-tencent/tencent-component-toolkit/issues/299)) ([837b943](https://github.com/serverless-tencent/tencent-component-toolkit/commit/837b943f9ff582c219a21edfa7c29f259cc5c860)) + # [2.25.0](https://github.com/serverless-tencent/tencent-component-toolkit/compare/v2.24.2...v2.25.0) (2024-04-24) diff --git a/package.json b/package.json index 2e9e9717..9a6dda8e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tencent-component-toolkit", - "version": "2.25.0", + "version": "2.25.1", "description": "Tencent component toolkit", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/modules/apigw/index.ts b/src/modules/apigw/index.ts index 48852235..b421f723 100644 --- a/src/modules/apigw/index.ts +++ b/src/modules/apigw/index.ts @@ -152,7 +152,7 @@ export default class Apigw { } try { - const { tags } = inputs; + const tags = this.tagClient.formatInputTags(inputs?.tags as any); if (tags) { await this.tagClient.deployResourceTags({ tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })), @@ -301,7 +301,7 @@ export default class Apigw { apiList, }; - const { tags } = inputs; + const tags = this.tagClient.formatInputTags(inputs?.tags as any); if (tags) { await this.tagClient.deployResourceTags({ tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })), diff --git a/src/modules/cdn/index.ts b/src/modules/cdn/index.ts index 01f58af1..d828954b 100644 --- a/src/modules/cdn/index.ts +++ b/src/modules/cdn/index.ts @@ -240,7 +240,7 @@ export default class Cdn { } try { - const { tags } = inputs; + const tags = this.tagClient.formatInputTags(inputs?.tags as any); if (tags) { await this.tagClient.deployResourceTags({ tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })), diff --git a/src/modules/cfs/index.ts b/src/modules/cfs/index.ts index ec4e8fc4..416c0d52 100644 --- a/src/modules/cfs/index.ts +++ b/src/modules/cfs/index.ts @@ -102,7 +102,7 @@ export default class CFS { } try { - const { tags } = inputs; + const tags = this.tagClient.formatInputTags(inputs?.tags as any); if (tags) { await this.tagClient.deployResourceTags({ tags: tags.map((item) => ({ TagKey: item.key, TagValue: item.value })), diff --git a/src/modules/cynosdb/index.ts b/src/modules/cynosdb/index.ts index 0b9a4cbd..33997563 100644 --- a/src/modules/cynosdb/index.ts +++ b/src/modules/cynosdb/index.ts @@ -160,7 +160,7 @@ export default class Cynosdb { })); try { - const { tags } = inputs; + const tags = this.tagClient.formatInputTags(inputs?.tags as any); if (tags) { await this.tagClient.deployResourceTags({ tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })), diff --git a/src/modules/postgresql/index.ts b/src/modules/postgresql/index.ts index ffeb70cb..3917245d 100644 --- a/src/modules/postgresql/index.ts +++ b/src/modules/postgresql/index.ts @@ -131,7 +131,7 @@ export default class Postgresql { } try { - const { tags } = inputs; + const tags = this.tagClient.formatInputTags(inputs?.tags as any); if (tags) { await this.tagClient.deployResourceTags({ tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })), diff --git a/src/modules/scf/index.ts b/src/modules/scf/index.ts index 2813f2ab..660be779 100644 --- a/src/modules/scf/index.ts +++ b/src/modules/scf/index.ts @@ -3,7 +3,7 @@ import { ActionType } from './apis'; import { RegionType, ApiServiceType, CapiCredentials } from './../interface'; import { Capi } from '@tencent-sdk/capi'; import { ApiTypeError } from '../../utils/error'; -import { deepClone, formatInputTags, strip } from '../../utils'; +import { deepClone, strip } from '../../utils'; import TagsUtils from '../tag/index'; import ApigwUtils from '../apigw'; import CONFIGS from './config'; @@ -260,7 +260,7 @@ export default class Scf { namespace: funcInfo.Namespace, functionName: funcInfo.FunctionName, ...trigger, - tags: formatInputTags(tags), + tags: this.tagClient.formatInputTags(tags), }, }); @@ -371,9 +371,10 @@ export default class Scf { } // create/update tags - if (inputs.tags) { + const tags = this.tagClient.formatInputTags(inputs?.tags as any); + if (tags) { const deployedTags = await this.tagClient.deployResourceTags({ - tags: Object.entries(inputs.tags).map(([TagKey, TagValue]) => ({ TagKey, TagValue })), + tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })), resourceId: `${funcInfo!.Namespace}/function/${funcInfo!.FunctionName}`, serviceType: ApiServiceType.scf, resourcePrefix: 'namespace', @@ -461,7 +462,7 @@ export default class Scf { } checkAddedYunTiTags(tags: Array<{ [key: string]: string }>): boolean { - const formatTags = formatInputTags(tags); + const formatTags = this.tagClient.formatInputTags(tags); const result = formatTags?.length > 0 && ['运营部门', '运营产品', '负责人'].every((tagKey) => diff --git a/src/modules/tag/index.ts b/src/modules/tag/index.ts index 3907f06b..d2faa6d6 100644 --- a/src/modules/tag/index.ts +++ b/src/modules/tag/index.ts @@ -1,5 +1,5 @@ import { ActionType } from './apis'; -import { RegionType, CapiCredentials, ApiServiceType } from './../interface'; +import { RegionType, CapiCredentials, ApiServiceType, TagInput } from './../interface'; import { Capi } from '@tencent-sdk/capi'; import APIS from './apis'; import { @@ -274,4 +274,34 @@ export default class Tag { return leftTags.concat(attachTags); } + + /** + * 格式化输入标签 + * @param inputs 输入标签 + * @returns 格式化后的标签列表 + */ + formatInputTags(inputs: Array | { [key: string]: string }): TagInput[] { + let tags: TagInput[]; + if (Array.isArray(inputs)) { + tags = inputs.map((item) => { + return { + key: item?.key ?? item?.Key ?? '', + value: item?.value ?? item?.Value ?? '', + }; + }); + } else if (typeof inputs === 'object' && inputs) { + tags = Object.entries(inputs).map(([key, value]) => { + return { + key: (key ?? '').toString(), + value: (value ?? '').toString(), + }; + }); + } else if (typeof inputs !== 'object' && inputs) { + // 非数组或者对象key-value类型的数据,需要返回原始输入数据 + tags = inputs; + } else { + tags = undefined as any; + } + return tags; + } } diff --git a/src/modules/vpc/index.ts b/src/modules/vpc/index.ts index 11d36edf..1e658c0c 100644 --- a/src/modules/vpc/index.ts +++ b/src/modules/vpc/index.ts @@ -78,10 +78,11 @@ export default class Vpc { vId = res.VpcId; } - if (tags) { + const formateTags = this.tagClient.formatInputTags(tags as any); + if (formateTags) { try { await this.tagClient.deployResourceTags({ - tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })), + tags: formateTags.map(({ key, value }) => ({ TagKey: key, TagValue: value })), resourceId: vId, serviceType: ApiServiceType.vpc, resourcePrefix: 'vpc', @@ -141,7 +142,7 @@ export default class Vpc { } } - const subnetTagList = subnetTags ? subnetTags : tags; + const subnetTagList = this.tagClient.formatInputTags((subnetTags ? subnetTags : tags) as any); if (subnetTagList) { try { await this.tagClient.deployResourceTags({ diff --git a/src/utils/index.ts b/src/utils/index.ts index f7907476..7677a34a 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -298,30 +298,3 @@ export const getYunTiApiUrl = (): string => { const url = `${apiUrl}?api_key=${apiKey}&api_ts=${timeStamp}&api_sign=${apiSign}`; return url; }; - -/** - * formatInputTags 格式化输入标签 - */ -export const formatInputTags = ( - input: Array | { [key: string]: string }, -): { key: string; value: string }[] => { - let tags: { key: string; value: string }[]; - if (Array.isArray(input)) { - tags = input.map((item) => { - return { - key: item?.key ?? item?.Key ?? '', - value: item?.value ?? item?.Value ?? '', - }; - }); - } else if (typeof input === 'object' && input) { - tags = Object.entries(input).map(([key, value]) => { - return { - key: (key ?? '').toString(), - value: (value ?? '').toString(), - }; - }); - } else { - tags = undefined as any; - } - return tags; -};