@backstage/config-loader
Advanced tools
Comparing version 0.1.1-alpha.23 to 0.1.1-alpha.24
@@ -44,2 +44,3 @@ 'use strict'; | ||
const config2 = yaml2.parse(configYaml); | ||
const context = path.basename(filePath); | ||
async function transform(obj, path2) { | ||
@@ -64,2 +65,3 @@ if (ctx.skip(path2)) { | ||
if ("$secret" in obj) { | ||
console.warn(`Deprecated secret declaration at '${path2}' in '${context}', use $env, $file, etc. instead`); | ||
if (!isObject(obj.$secret)) { | ||
@@ -74,2 +76,15 @@ throw TypeError(`Expected object at secret ${path2}.$secret`); | ||
} | ||
const [secretKey] = Object.keys(obj).filter((key) => key.startsWith("$")); | ||
if (secretKey) { | ||
if (Object.keys(obj).length !== 1) { | ||
throw new Error(`Secret key '${secretKey}' has adjacent keys at ${path2}`); | ||
} | ||
try { | ||
return await ctx.readSecret(path2, { | ||
[secretKey.slice(1)]: obj[secretKey] | ||
}); | ||
} catch (error) { | ||
throw new Error(`Invalid secret at ${path2}: ${error.message}`); | ||
} | ||
} | ||
const out = {}; | ||
@@ -90,3 +105,3 @@ for (const [key, value] of Object.entries(obj)) { | ||
} | ||
return {data: finalConfig, context: path.basename(filePath)}; | ||
return {data: finalConfig, context}; | ||
} | ||
@@ -152,9 +167,3 @@ | ||
data: yup.object({ | ||
data: yup.string().required(), | ||
path: yup.lazy((value) => { | ||
if (typeof value === "string") { | ||
return yup.string().required(); | ||
} | ||
return yup.array().of(yup.string().required()).required(); | ||
}) | ||
data: yup.string().required() | ||
}) | ||
@@ -188,3 +197,8 @@ }; | ||
if ("data" in secret) { | ||
const ext = path.extname(secret.data); | ||
const url = "path" in secret ? `${secret.data}#${secret.path}` : secret.data; | ||
const [filePath, dataPath] = url.split(/#(.*)/); | ||
if (!dataPath) { | ||
throw new Error(`Invalid format for data secret value, must be of the form <filepath>#<datapath>, got '${url}'`); | ||
} | ||
const ext = path.extname(filePath); | ||
const parser = dataSecretParser[ext]; | ||
@@ -194,5 +208,4 @@ if (!parser) { | ||
} | ||
const content = await ctx.readFile(secret.data); | ||
const {path: path2} = secret; | ||
const parts = typeof path2 === "string" ? path2.split(".") : path2; | ||
const content = await ctx.readFile(filePath); | ||
const parts = dataPath.split("."); | ||
let value = await parser(content); | ||
@@ -202,3 +215,3 @@ for (const [index, part] of parts.entries()) { | ||
const errPath = parts.slice(0, index).join("."); | ||
throw new Error(`Value is not an object at ${errPath} in ${secret.data}`); | ||
throw new Error(`Value is not an object at ${errPath} in ${filePath}`); | ||
} | ||
@@ -205,0 +218,0 @@ value = value[part]; |
import { resolve, basename, extname, dirname } from 'path'; | ||
import fs, { pathExists } from 'fs-extra'; | ||
import yaml2 from 'yaml'; | ||
import { object, string, lazy, array, ValidationError } from 'yup'; | ||
import { object, string, lazy, ValidationError } from 'yup'; | ||
@@ -37,2 +37,3 @@ async function resolveStaticConfig(options) { | ||
const config2 = yaml2.parse(configYaml); | ||
const context = basename(filePath); | ||
async function transform(obj, path2) { | ||
@@ -57,2 +58,3 @@ if (ctx.skip(path2)) { | ||
if ("$secret" in obj) { | ||
console.warn(`Deprecated secret declaration at '${path2}' in '${context}', use $env, $file, etc. instead`); | ||
if (!isObject(obj.$secret)) { | ||
@@ -67,2 +69,15 @@ throw TypeError(`Expected object at secret ${path2}.$secret`); | ||
} | ||
const [secretKey] = Object.keys(obj).filter((key) => key.startsWith("$")); | ||
if (secretKey) { | ||
if (Object.keys(obj).length !== 1) { | ||
throw new Error(`Secret key '${secretKey}' has adjacent keys at ${path2}`); | ||
} | ||
try { | ||
return await ctx.readSecret(path2, { | ||
[secretKey.slice(1)]: obj[secretKey] | ||
}); | ||
} catch (error) { | ||
throw new Error(`Invalid secret at ${path2}: ${error.message}`); | ||
} | ||
} | ||
const out = {}; | ||
@@ -83,3 +98,3 @@ for (const [key, value] of Object.entries(obj)) { | ||
} | ||
return {data: finalConfig, context: basename(filePath)}; | ||
return {data: finalConfig, context}; | ||
} | ||
@@ -145,9 +160,3 @@ | ||
data: object({ | ||
data: string().required(), | ||
path: lazy((value) => { | ||
if (typeof value === "string") { | ||
return string().required(); | ||
} | ||
return array().of(string().required()).required(); | ||
}) | ||
data: string().required() | ||
}) | ||
@@ -181,3 +190,8 @@ }; | ||
if ("data" in secret) { | ||
const ext = extname(secret.data); | ||
const url = "path" in secret ? `${secret.data}#${secret.path}` : secret.data; | ||
const [filePath, dataPath] = url.split(/#(.*)/); | ||
if (!dataPath) { | ||
throw new Error(`Invalid format for data secret value, must be of the form <filepath>#<datapath>, got '${url}'`); | ||
} | ||
const ext = extname(filePath); | ||
const parser = dataSecretParser[ext]; | ||
@@ -187,5 +201,4 @@ if (!parser) { | ||
} | ||
const content = await ctx.readFile(secret.data); | ||
const {path: path2} = secret; | ||
const parts = typeof path2 === "string" ? path2.split(".") : path2; | ||
const content = await ctx.readFile(filePath); | ||
const parts = dataPath.split("."); | ||
let value = await parser(content); | ||
@@ -195,3 +208,3 @@ for (const [index, part] of parts.entries()) { | ||
const errPath = parts.slice(0, index).join("."); | ||
throw new Error(`Value is not an object at ${errPath} in ${secret.data}`); | ||
throw new Error(`Value is not an object at ${errPath} in ${filePath}`); | ||
} | ||
@@ -198,0 +211,0 @@ value = value[part]; |
{ | ||
"name": "@backstage/config-loader", | ||
"description": "Config loading functionality used by Backstage backend, and CLI", | ||
"version": "0.1.1-alpha.23", | ||
"version": "0.1.1-alpha.24", | ||
"private": false, | ||
@@ -33,3 +33,3 @@ "publishConfig": { | ||
"dependencies": { | ||
"@backstage/config": "^0.1.1-alpha.23", | ||
"@backstage/config": "^0.1.1-alpha.24", | ||
"fs-extra": "^9.0.0", | ||
@@ -49,4 +49,4 @@ "yaml": "^1.9.2", | ||
], | ||
"gitHead": "b5e6051959b76b69a0f99aeb9d84da82d1023687", | ||
"gitHead": "730f9a768c4a855cbf4ee38a41c0bc0c48081918", | ||
"module": "dist/index.esm.js" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29624
530