@@ -155,16 +155,35 @@ class GoogleProvider {
155
155
cloudfunctions : google . cloudfunctions ( 'v1' ) ,
156
156
} ;
157
157
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
158
176
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
+ } ,
160
183
} ;
161
184
}
162
185
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 } ) {
168
187
return this . serverless
169
188
. getProvider ( 'google' )
170
189
. request ( 'storage' , 'objects' , 'get' , {
@@ -173,7 +192,7 @@ class GoogleProvider {
173
192
alt : 'media' ,
174
193
} )
175
194
. 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 } ` ) ;
177
196
} ) ;
178
197
}
179
198
0 commit comments