@backstage/config-loader
Advanced tools
Comparing version 0.1.1-alpha.18 to 0.1.1-alpha.19
@@ -7,3 +7,4 @@ 'use strict'; | ||
var fs = _interopDefault(require('fs-extra')); | ||
var fs = require('fs-extra'); | ||
var fs__default = _interopDefault(fs); | ||
var path = require('path'); | ||
@@ -14,4 +15,18 @@ var yaml2 = _interopDefault(require('yaml')); | ||
async function resolveStaticConfig(options) { | ||
const configPath = path.resolve(options.rootPath, "app-config.yaml"); | ||
return [configPath]; | ||
const filePaths = [ | ||
`app-config.yaml`, | ||
`app-config.local.yaml`, | ||
`app-config.${options.env}.yaml`, | ||
`app-config.${options.env}.local.yaml` | ||
]; | ||
const resolvedPaths = []; | ||
for (const rootPath of options.rootPaths) { | ||
for (const filePath of filePaths) { | ||
const path2 = path.resolve(rootPath, filePath); | ||
if (await fs.pathExists(path2)) { | ||
resolvedPaths.push(path2); | ||
} | ||
} | ||
} | ||
return resolvedPaths; | ||
} | ||
@@ -32,2 +47,5 @@ | ||
async function transform(obj, path2) { | ||
if (ctx.skip(path2)) { | ||
return void 0; | ||
} | ||
if (typeof obj !== "object") { | ||
@@ -52,3 +70,3 @@ return obj; | ||
try { | ||
return await ctx.readSecret(obj.$secret); | ||
return await ctx.readSecret(path2, obj.$secret); | ||
} catch (error) { | ||
@@ -197,6 +215,13 @@ throw new Error(`Invalid secret at ${path2}: ${error.message}`); | ||
} | ||
skip(path2) { | ||
if (this.options.shouldReadSecrets) { | ||
return false; | ||
} | ||
return this.options.secretPaths.has(path2); | ||
} | ||
async readFile(path2) { | ||
return fs.readFile(path.resolve(this.options.rootPath, path2), "utf8"); | ||
return fs__default.readFile(path.resolve(this.options.rootPath, path2), "utf8"); | ||
} | ||
async readSecret(desc) { | ||
async readSecret(path2, desc) { | ||
this.options.secretPaths.add(path2); | ||
if (!this.options.shouldReadSecrets) { | ||
@@ -210,7 +235,8 @@ return void 0; | ||
const configs = []; | ||
configs.push(...readEnv(process.env)); | ||
const configPaths = await resolveStaticConfig(options); | ||
try { | ||
const secretPaths = new Set(); | ||
for (const configPath of configPaths) { | ||
const config2 = await readConfigFile(configPath, new Context({ | ||
secretPaths, | ||
env: process.env, | ||
@@ -225,2 +251,3 @@ rootPath: path.dirname(configPath), | ||
} | ||
configs.push(...readEnv(process.env)); | ||
return configs; | ||
@@ -227,0 +254,0 @@ } |
import { AppConfig } from '@backstage/config'; | ||
declare type LoadConfigOptions = { | ||
rootPath: string; | ||
rootPaths: string[]; | ||
env: string; | ||
shouldReadSecrets?: boolean; | ||
@@ -6,0 +7,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
import fs from 'fs-extra'; | ||
import fs, { pathExists } from 'fs-extra'; | ||
import { resolve, basename, extname, dirname } from 'path'; | ||
@@ -7,4 +7,18 @@ import yaml2 from 'yaml'; | ||
async function resolveStaticConfig(options) { | ||
const configPath = resolve(options.rootPath, "app-config.yaml"); | ||
return [configPath]; | ||
const filePaths = [ | ||
`app-config.yaml`, | ||
`app-config.local.yaml`, | ||
`app-config.${options.env}.yaml`, | ||
`app-config.${options.env}.local.yaml` | ||
]; | ||
const resolvedPaths = []; | ||
for (const rootPath of options.rootPaths) { | ||
for (const filePath of filePaths) { | ||
const path2 = resolve(rootPath, filePath); | ||
if (await pathExists(path2)) { | ||
resolvedPaths.push(path2); | ||
} | ||
} | ||
} | ||
return resolvedPaths; | ||
} | ||
@@ -25,2 +39,5 @@ | ||
async function transform(obj, path2) { | ||
if (ctx.skip(path2)) { | ||
return void 0; | ||
} | ||
if (typeof obj !== "object") { | ||
@@ -45,3 +62,3 @@ return obj; | ||
try { | ||
return await ctx.readSecret(obj.$secret); | ||
return await ctx.readSecret(path2, obj.$secret); | ||
} catch (error) { | ||
@@ -190,6 +207,13 @@ throw new Error(`Invalid secret at ${path2}: ${error.message}`); | ||
} | ||
skip(path2) { | ||
if (this.options.shouldReadSecrets) { | ||
return false; | ||
} | ||
return this.options.secretPaths.has(path2); | ||
} | ||
async readFile(path2) { | ||
return fs.readFile(resolve(this.options.rootPath, path2), "utf8"); | ||
} | ||
async readSecret(desc) { | ||
async readSecret(path2, desc) { | ||
this.options.secretPaths.add(path2); | ||
if (!this.options.shouldReadSecrets) { | ||
@@ -203,7 +227,8 @@ return void 0; | ||
const configs = []; | ||
configs.push(...readEnv(process.env)); | ||
const configPaths = await resolveStaticConfig(options); | ||
try { | ||
const secretPaths = new Set(); | ||
for (const configPath of configPaths) { | ||
const config2 = await readConfigFile(configPath, new Context({ | ||
secretPaths, | ||
env: process.env, | ||
@@ -218,2 +243,3 @@ rootPath: dirname(configPath), | ||
} | ||
configs.push(...readEnv(process.env)); | ||
return configs; | ||
@@ -220,0 +246,0 @@ } |
{ | ||
"name": "@backstage/config-loader", | ||
"description": "Config loading functionality used by Backstage backend, and CLI", | ||
"version": "0.1.1-alpha.18", | ||
"version": "0.1.1-alpha.19", | ||
"private": false, | ||
@@ -33,3 +33,3 @@ "publishConfig": { | ||
"dependencies": { | ||
"@backstage/config": "^0.1.1-alpha.18", | ||
"@backstage/config": "^0.1.1-alpha.19", | ||
"fs-extra": "^9.0.0", | ||
@@ -47,4 +47,4 @@ "yaml": "^1.9.2", | ||
], | ||
"gitHead": "b270fe5de99a8921abc488665ba457122163dcb5", | ||
"gitHead": "7fd6ab60b8d18de92e8484801d4932a50b08ddbb", | ||
"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
27440
482