Skip to content

Commit

Permalink
Merge pull request #26951 from backstage/patch-release-pr-26950
Browse files Browse the repository at this point in the history
Patch release of #26950
  • Loading branch information
Rugvip authored Oct 3, 2024
2 parents 576b02f + f05c8cf commit 568fefe
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "root",
"version": "1.31.2",
"version": "1.31.3",
"private": true,
"repository": {
"type": "git",
Expand Down
7 changes: 7 additions & 0 deletions packages/backend-legacy/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# example-backend-legacy

## 0.2.104

### Patch Changes

- Updated dependencies
- @backstage/plugin-app-backend@0.3.75

## 0.2.103

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/backend-legacy/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "example-backend-legacy",
"version": "0.2.103",
"version": "0.2.104",
"backstage": {
"role": "backend"
},
Expand Down
7 changes: 7 additions & 0 deletions packages/backend/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# example-backend

## 0.0.32

### Patch Changes

- Updated dependencies
- @backstage/plugin-app-backend@0.3.75

## 0.0.31

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "example-backend",
"version": "0.0.31",
"version": "0.0.32",
"main": "dist/index.cjs.js",
"types": "src/index.ts",
"license": "Apache-2.0",
Expand Down
6 changes: 6 additions & 0 deletions plugins/app-backend/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @backstage/plugin-app-backend

## 0.3.75

### Patch Changes

- 9206a12: Fixed unexpected behaviour where configuration supplied with `APP_CONFIG_*` environment variables where not filtered by the configuration schema.

## 0.3.74

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion plugins/app-backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@backstage/plugin-app-backend",
"version": "0.3.74",
"version": "0.3.75",
"description": "A Backstage backend plugin that serves the Backstage frontend app",
"backstage": {
"role": "backend-plugin",
Expand Down
99 changes: 99 additions & 0 deletions plugins/app-backend/src/lib/config/readFrontendConfig.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright 2024 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { createMockDirectory } from '@backstage/backend-test-utils';
import { readFrontendConfig } from './readFrontendConfig';
import { ConfigReader } from '@backstage/config';

describe('readFrontendConfig', () => {
const mockDir = createMockDirectory();

afterEach(() => {
mockDir.clear();
});

it('should validate env config', async () => {
mockDir.setContent({
'appDir/.config-schema.json': JSON.stringify({
schemas: [
{
value: {
type: 'object',

properties: {
app: {
type: 'object',
properties: {
secretOfLife: {
type: 'string',
visibility: 'secret',
},
backendConfig: {
type: 'string',
visibility: 'backend',
},
publicValue: {
type: 'string',
visibility: 'frontend',
},
},
},
},
},
},
],
backstageConfigSchemaVersion: 1,
}),
});

const config = new ConfigReader({
app: {
secretOfLife: '42',
backendConfig: 'backend',
publicValue: 'public',
},
});

const frontendConfig = await readFrontendConfig({
env: {
APP_CONFIG_app_secretOfLife: 'ignored',
APP_CONFIG_app_backendConfig: 'ignored',
APP_CONFIG_app_publicValue: 'injected',
},
appDistDir: `${mockDir.path}/appDir`,
config,
});

expect(frontendConfig).toEqual([
{
context: 'env',
data: {
app: {
publicValue: 'injected',
},
},
deprecatedKeys: [],
filteredKeys: undefined,
},
{
context: 'app',
data: { app: { publicValue: 'public' } },
deprecatedKeys: [],
filteredKeys: undefined,
},
]);
});
});
10 changes: 4 additions & 6 deletions plugins/app-backend/src/lib/config/readFrontendConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ export async function readFrontendConfig(options: {
}): Promise<AppConfig[]> {
const { env, appDistDir, config } = options;

const appConfigs = readEnvConfig(env);

const schemaPath = resolvePath(appDistDir, '.config-schema.json');
if (await fs.pathExists(schemaPath)) {
const envConfigs = readEnvConfig(env);
const serializedSchema = await fs.readJson(schemaPath);

try {
Expand All @@ -49,11 +48,10 @@ export async function readFrontendConfig(options: {
serialized: serializedSchema,
}));

const frontendConfigs = await schema.process(
[{ data: config.get() as JsonObject, context: 'app' }],
return await schema.process(
[...envConfigs, { data: config.get() as JsonObject, context: 'app' }],
{ visibility: ['frontend'], withDeprecatedKeys: true },
);
appConfigs.push(...frontendConfigs);
} catch (error) {
throw new Error(
'Invalid app bundle schema. If this error is unexpected you need to run `yarn build` in the app. ' +
Expand All @@ -63,5 +61,5 @@ export async function readFrontendConfig(options: {
}
}

return appConfigs;
return [];
}

0 comments on commit 568fefe

Please sign in to comment.