@@ -166,6 +166,33 @@ export class Configs {
166166 return this . functionConfig ;
167167 }
168168
169+ /**
170+ * Returns the map of data values if functionConfig is of kind ConfigMap.
171+ *
172+ * Throws a FunctionConfigError if functionConfig is undefined OR
173+ * if the kind is not a v1/ConfigMap.
174+ */
175+ getFunctionConfigMap ( ) {
176+ const cm = this . getFunctionConfig ( ) ;
177+ if ( cm === undefined ) {
178+ throw new FunctionConfigError (
179+ `functionConfig expected, instead undefined`
180+ ) ;
181+ }
182+ if ( ! isConfigMap ( cm ) ) {
183+ throw new FunctionConfigError (
184+ `functionConfig expected to be of kind ConfigMap, instead got: ${ cm . kind } `
185+ ) ;
186+ }
187+ const configMap = new Map < string , string > ( ) ;
188+ for ( const key in cm . data ) {
189+ if ( cm . data . hasOwnProperty ( key ) ) {
190+ configMap . set ( key , cm . data [ key ] ) ;
191+ }
192+ }
193+ return configMap ;
194+ }
195+
169196 /**
170197 * Returns the value for the given key if functionConfig is of kind ConfigMap.
171198 *
@@ -177,16 +204,7 @@ export class Configs {
177204 * @key key The key in the 'data' field in the ConfigMap object given as the functionConfig.
178205 */
179206 getFunctionConfigValue ( key : string ) : string | undefined {
180- const cm = this . functionConfig ;
181- if ( ! cm ) {
182- return undefined ;
183- }
184- if ( ! isConfigMap ( cm ) ) {
185- throw new FunctionConfigError (
186- `functionConfig expected to be of kind ConfigMap, instead got: ${ cm . kind } `
187- ) ;
188- }
189- return cm . data && cm . data [ key ] ;
207+ return this . getFunctionConfigMap ( ) . get ( key ) ;
190208 }
191209
192210 /**
0 commit comments