@@ -13,10 +13,13 @@ const scfService = new utils_1.CloudService('scf', '2018-04-16', {
1313 Stamp : 'MINI_QCBASE'
1414} ) ;
1515async function createFunction ( options ) {
16- const { func, functionRootPath = '' , envId, force = false , base64Code = '' } = options ;
16+ const { func, functionRootPath = '' , envId, force = false , base64Code = '' , codeSecret } = options ;
1717 let base64 ;
1818 let packer ;
1919 const funcName = func . name ;
20+ if ( codeSecret && ! / ^ [ A - Z a - z 0 - 9 + = / ] { 1 , 160 } $ / . test ( codeSecret ) ) {
21+ throw new error_1 . CloudBaseError ( 'CodeSecret 格式错误,格式为 1-160 位大小字母,数字+=/' ) ;
22+ }
2023 const validRuntime = [ 'Nodejs8.9' , 'Php7' , 'Java8' ] ;
2124 if ( func . config . runtime && ! validRuntime . includes ( func . config . runtime ) ) {
2225 throw new error_1 . CloudBaseError ( `${ funcName } Invalid runtime value:${ func . config . runtime } . Now only support: ${ validRuntime . join ( ', ' ) } ` ) ;
@@ -42,6 +45,7 @@ async function createFunction(options) {
4245 Code : {
4346 ZipFile : base64
4447 } ,
48+ CodeSecret : codeSecret ,
4549 MemorySize : 256
4650 } ;
4751 const { config } = func ;
@@ -83,16 +87,17 @@ async function createFunction(options) {
8387}
8488exports . createFunction = createFunction ;
8589async function batchCreateFunctions ( options ) {
86- const { functions, functionRootPath = '' , envId, force, log = false } = options ;
90+ const { functions, functionRootPath = '' , envId, force, codeSecret , log = false } = options ;
8791 const promises = functions . map ( func => ( async ( ) => {
8892 const spinner = ora_1 . default ( `[${ func . name } ] 函数部署中...` ) ;
8993 try {
9094 log && spinner . start ( ) ;
9195 await createFunction ( {
9296 func,
93- functionRootPath,
9497 envId,
95- force
98+ force,
99+ codeSecret,
100+ functionRootPath
96101 } ) ;
97102 log && spinner . succeed ( `[${ func . name } ] 函数部署成功` ) ;
98103 }
@@ -105,10 +110,13 @@ async function batchCreateFunctions(options) {
105110}
106111exports . batchCreateFunctions = batchCreateFunctions ;
107112async function updateFunctionCode ( options ) {
108- const { func, functionRootPath = '' , envId, base64Code = '' } = options ;
113+ const { func, functionRootPath = '' , envId, base64Code = '' , codeSecret } = options ;
109114 let base64 ;
110115 let packer ;
111116 const funcName = func . name ;
117+ if ( codeSecret && ! / ^ [ A - Z a - z 0 - 9 + = / ] { 1 , 160 } $ / . test ( codeSecret ) ) {
118+ throw new error_1 . CloudBaseError ( 'CodeSecret 格式错误,格式为 1-160 位大小字母,数字+=/' ) ;
119+ }
112120 const validRuntime = [ 'Nodejs8.9' , 'Php7' , 'Java8' ] ;
113121 if ( func . config . runtime && ! validRuntime . includes ( func . config . runtime ) ) {
114122 throw new error_1 . CloudBaseError ( `${ funcName } 非法的运行环境:${ func . config . runtime } ,当前支持环境:${ validRuntime . join ( ', ' ) } ` ) ;
@@ -128,6 +136,7 @@ async function updateFunctionCode(options) {
128136 FunctionName : funcName ,
129137 Namespace : envId ,
130138 ZipFile : base64 ,
139+ CodeSecret : codeSecret ,
131140 Handler : func . handler || 'index.main'
132141 } ;
133142 try {
0 commit comments