@@ -155,16 +155,35 @@ class GoogleProvider {
155155 cloudfunctions : google . cloudfunctions ( 'v1' ) ,
156156 } ;
157157
158+ this . configurationVariablesSources = {
159+ gs : {
160+ async resolve ( { address } ) {
161+ if ( ! address ) {
162+ throw new serverless . classes . Error (
163+ 'Missing address argument in variable "gs" source' ,
164+ 'GOOGLE_CLOUD_MISSING_GS_VAR ADDRESS'
165+ ) ;
166+ }
167+ const groups = address . split ( '/' ) ;
168+ const bucket = groups . shift ( ) ;
169+ const object = groups . join ( '/' ) ;
170+ return { value : await this . gsValue ( { bucket, object } ) } ;
171+ } ,
172+ } ,
173+ } ;
174+
175+ // TODO: Remove with next major
158176 this . variableResolvers = {
159- gs : this . getGsValue ,
177+ gs : ( variableString ) => {
178+ const groups = variableString . split ( ':' ) [ 1 ] . split ( '/' ) ;
179+ const bucket = groups . shift ( ) ;
180+ const object = groups . join ( '/' ) ;
181+ return this . gsValue ( { bucket, object } ) ;
182+ } ,
160183 } ;
161184 }
162185
163- getGsValue ( variableString ) {
164- const groups = variableString . split ( ':' ) [ 1 ] . split ( '/' ) ;
165- const bucket = groups . shift ( ) ;
166- const object = groups . join ( '/' ) ;
167-
186+ async getGsValue ( { bucket, object } ) {
168187 return this . serverless
169188 . getProvider ( 'google' )
170189 . request ( 'storage' , 'objects' , 'get' , {
@@ -173,7 +192,7 @@ class GoogleProvider {
173192 alt : 'media' ,
174193 } )
175194 . catch ( ( err ) => {
176- throw new Error ( `Error getting value for ${ variableString } . ${ err . message } ` ) ;
195+ throw new Error ( `Error getting value for ${ bucket } / ${ object } . ${ err . message } ` ) ;
177196 } ) ;
178197 }
179198
0 commit comments