@@ -3,6 +3,7 @@ import path from 'path';
3
3
import camelCase from 'camelcase' ;
4
4
import { PascalCase } from 'type-fest' ;
5
5
import { CamelCasedProps , PascalCasedProps } from '../modules/interface' ;
6
+ import crypto from 'crypto' ;
6
7
7
8
// TODO: 将一些库换成 lodash
8
9
@@ -273,3 +274,54 @@ export const getQcsResourceId = (service: string, region: string, uin: string, s
273
274
// 云资源六段式
274
275
return `qcs::${ service } :${ region } :uin/${ uin } :${ suffix } ` ;
275
276
} ;
277
+
278
+ /**
279
+ * hmacSha1 加密HmacSHA1
280
+ * @param text 加密文本
281
+ * @param key 加密密钥
282
+ * @returns
283
+ */
284
+ export const hmacSha1 = ( text : string , key : string ) => {
285
+ return crypto . createHmac ( 'sha1' , key ) . update ( text ) . digest ( 'hex' ) ;
286
+ } ;
287
+
288
+ /**
289
+ * getYunTiApiUrl 查询云梯API地址
290
+ * @returns 云梯API地址
291
+ */
292
+ export const getYunTiApiUrl = ( ) : string => {
293
+ const apiKey = process . env . SLS_YUNTI_API_KEY || '' ;
294
+ const apiSecret = process . env . SLS_YUNTI_API_SECRET || '' ;
295
+ const apiUrl = process . env . SLS_YUNTI_API_URL ;
296
+ const timeStamp = Math . floor ( Date . now ( ) / 1000 ) ;
297
+ const apiSign = hmacSha1 ( `${ timeStamp } ${ apiKey } ` , apiSecret ) ;
298
+ const url = `${ apiUrl } ?api_key=${ apiKey } &api_ts=${ timeStamp } &api_sign=${ apiSign } ` ;
299
+ return url ;
300
+ } ;
301
+
302
+ /**
303
+ * formatInputTags 格式化输入标签
304
+ */
305
+ export const formatInputTags = (
306
+ input : Array < any > | { [ key : string ] : string } ,
307
+ ) : { key : string ; value : string } [ ] => {
308
+ let tags : { key : string ; value : string } [ ] ;
309
+ if ( Array . isArray ( input ) ) {
310
+ tags = input . map ( ( item ) => {
311
+ return {
312
+ key : item ?. key ?? item ?. Key ?? '' ,
313
+ value : item ?. value ?? item ?. Value ?? '' ,
314
+ } ;
315
+ } ) ;
316
+ } else if ( typeof input === 'object' && input ) {
317
+ tags = Object . entries ( input ) . map ( ( [ key , value ] ) => {
318
+ return {
319
+ key : ( key ?? '' ) . toString ( ) ,
320
+ value : ( value ?? '' ) . toString ( ) ,
321
+ } ;
322
+ } ) ;
323
+ } else {
324
+ tags = undefined as any ;
325
+ }
326
+ return tags ;
327
+ } ;
0 commit comments