address comments

This commit is contained in:
Fredrik Adelöw
2020-06-18 11:54:12 +02:00
parent 8d961027a9
commit 3bff1d6a68
9 changed files with 83 additions and 79 deletions
+9 -6
View File
@@ -14,11 +14,11 @@
* limitations under the License.
*/
import yaml from 'yaml';
import { AppConfig, JsonObject, JsonValue } from '@backstage/config';
import { basename } from 'path';
import { isObject } from './utils';
import { JsonValue, JsonObject, AppConfig } from '@backstage/config';
import yaml from 'yaml';
import { ReaderContext } from './types';
import { isObject } from './utils';
/**
* Reads and parses, and validates, and transforms a single config file.
@@ -67,9 +67,12 @@ export async function readConfigFile(
const out: JsonObject = {};
for (const [key, value] of Object.entries(obj)) {
const result = await transform(value, `${path}.${key}`);
if (result !== undefined) {
out[key] = result;
// undefined covers optional fields
if (value !== undefined) {
const result = await transform(value, `${path}.${key}`);
if (result !== undefined) {
out[key] = result;
}
}
}
+2 -1
View File
@@ -122,7 +122,7 @@ export async function readSecret(
const { path } = secret;
const parts = typeof path === 'string' ? path.split('.') : path;
let value: JsonValue = await parser(content);
let value: JsonValue | undefined = await parser(content);
for (const [index, part] of parts.entries()) {
if (!isObject(value)) {
const errPath = parts.slice(0, index).join('.');
@@ -132,6 +132,7 @@ export async function readSecret(
}
value = value[part];
}
return String(value);
}