diff --git a/app-config.yaml b/app-config.yaml index e49e29c45a..b025064c74 100644 --- a/app-config.yaml +++ b/app-config.yaml @@ -464,6 +464,3 @@ apacheAirflow: gocd: baseUrl: https://your.gocd.instance.com - -airbrake: - apiKey: ${AIRBRAKE_API_KEY} diff --git a/plugins/airbrake-backend/README.md b/plugins/airbrake-backend/README.md index 7ded50c85a..9c9b56ade4 100644 --- a/plugins/airbrake-backend/README.md +++ b/plugins/airbrake-backend/README.md @@ -10,8 +10,19 @@ See the [Airbrake plugin instructions](../airbrake/README.md#how-to-use). This method of serving the plugin provides quicker iteration speed and a faster startup and hot reloads. -1. Set the environment variable `AIRBRAKE_API_KEY` with your [API key](https://airbrake.io/docs/api/#authentication). -2. Run this plugin in standalone mode by running `yarn start`. The configuration is already setup in the root [`app-config.yaml`](../../app-config.yaml) to pick up your API key from the environment variable above. +1. Add the required config to your `app-config.local.yaml`: + + ```yaml + airbrake: + apiKey: ${AIRBRAKE_API_KEY} + ``` + +2. Set the environment variable `AIRBRAKE_API_KEY` with your [API + key](https://airbrake.io/docs/api/#authentication). You can also write it + directly into the config file above for convenience - but beware of + accidentally leaking the key. + +3. Go into the plugin's directory and run it in standalone mode by running `yarn start`. Access it from http://localhost:7007/api/airbrake. Or use the Airbrake plugin which will talk to it automatically. diff --git a/plugins/airbrake-backend/api-report.md b/plugins/airbrake-backend/api-report.md index 58f299fb4c..b9e9a50e0b 100644 --- a/plugins/airbrake-backend/api-report.md +++ b/plugins/airbrake-backend/api-report.md @@ -6,7 +6,6 @@ import { Config } from '@backstage/config'; import express from 'express'; import { Logger as Logger_2 } from 'winston'; -import * as winston from 'winston'; // @public export interface AirbrakeConfig { @@ -17,10 +16,7 @@ export interface AirbrakeConfig { export function createRouter(options: RouterOptions): Promise; // @public -export function extractAirbrakeConfig( - config: Config, - logger: winston.Logger, -): AirbrakeConfig; +export function extractAirbrakeConfig(config: Config): AirbrakeConfig; // @public export interface RouterOptions { diff --git a/plugins/airbrake-backend/config.d.ts b/plugins/airbrake-backend/config.d.ts index 9563121127..a21f609550 100644 --- a/plugins/airbrake-backend/config.d.ts +++ b/plugins/airbrake-backend/config.d.ts @@ -18,7 +18,9 @@ export interface Config { /** Configuration options for the Airbrake plugin */ airbrake?: { /** - * The API Key to authenticate requests. More details on how to get this here: https://airbrake.io/docs/api/#authentication + * The API Key to authenticate requests. More details on how to get this + * here: https://airbrake.io/docs/api/#authentication + * * @visibility secret */ apiKey: string; diff --git a/plugins/airbrake-backend/src/config/ExtractAirbrakeConfig.test.ts b/plugins/airbrake-backend/src/config/ExtractAirbrakeConfig.test.ts index d94746c8ef..53d744b9ee 100644 --- a/plugins/airbrake-backend/src/config/ExtractAirbrakeConfig.test.ts +++ b/plugins/airbrake-backend/src/config/ExtractAirbrakeConfig.test.ts @@ -13,20 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { getVoidLogger } from '@backstage/backend-common'; + import { ConfigReader } from '@backstage/config'; import { extractAirbrakeConfig } from './ExtractAirbrakeConfig'; -import * as winston from 'winston'; describe('ExtractAirbrakeConfig', () => { - let oldProcessEnv: NodeJS.ProcessEnv; - let voidLogger: winston.Logger; - - beforeEach(() => { - oldProcessEnv = process.env; - voidLogger = getVoidLogger(); - }); - it('gets the API key', () => { const config = new ConfigReader({ airbrake: { @@ -34,34 +25,14 @@ describe('ExtractAirbrakeConfig', () => { }, }); - const airbrakeConfig = extractAirbrakeConfig(config, voidLogger); + const airbrakeConfig = extractAirbrakeConfig(config); expect(airbrakeConfig.apiKey).toStrictEqual('fakeApiKey'); }); - it('does not fail in development', () => { - process.env = { - ...oldProcessEnv, - NODE_ENV: 'development', - }; - - const config = new ConfigReader({}); - - expect(() => extractAirbrakeConfig(config, voidLogger)).not.toThrow(); - const airbrakeConfig = extractAirbrakeConfig(config, voidLogger); - expect(airbrakeConfig.apiKey).toStrictEqual(''); - }); - - it('fails in production', () => { - process.env = { - ...oldProcessEnv, - NODE_ENV: 'production', - }; - - const config = new ConfigReader({}); - expect(() => extractAirbrakeConfig(config, voidLogger)).toThrow(); - }); - - afterEach(() => { - process.env = { ...oldProcessEnv }; + it('fails for missing keys', () => { + expect(() => extractAirbrakeConfig(new ConfigReader({}))).toThrow(); + expect(() => + extractAirbrakeConfig(new ConfigReader({ airbrake: {} })), + ).toThrow(); }); }); diff --git a/plugins/airbrake-backend/src/config/ExtractAirbrakeConfig.ts b/plugins/airbrake-backend/src/config/ExtractAirbrakeConfig.ts index 20542ccbde..de6a31feec 100644 --- a/plugins/airbrake-backend/src/config/ExtractAirbrakeConfig.ts +++ b/plugins/airbrake-backend/src/config/ExtractAirbrakeConfig.ts @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import { Config } from '@backstage/config'; -import * as winston from 'winston'; /** * The configuration needed for the airbrake-backend plugin @@ -34,27 +34,9 @@ export interface AirbrakeConfig { * @public * * @param config - The config object to extract from - * @param logger - THe logger object */ -export function extractAirbrakeConfig( - config: Config, - logger: winston.Logger, -): AirbrakeConfig { - try { - return { - apiKey: config.getString('airbrake.apiKey'), - }; - } catch (e) { - if (process.env.NODE_ENV !== 'development') { - throw e; - } else { - logger.warn( - 'Airbrake config missing, Airbrake plugin will probably not work', - e, - ); - return { - apiKey: '', - }; - } - } +export function extractAirbrakeConfig(config: Config): AirbrakeConfig { + return { + apiKey: config.getString('airbrake.apiKey'), + }; } diff --git a/plugins/airbrake-backend/src/service/router.test.ts b/plugins/airbrake-backend/src/service/router.test.ts index 05c9308d7f..7ccafd7eba 100644 --- a/plugins/airbrake-backend/src/service/router.test.ts +++ b/plugins/airbrake-backend/src/service/router.test.ts @@ -40,7 +40,7 @@ describe('createRouter', () => { apiKey: 'fakeApiKey', }, }); - airbrakeConfig = extractAirbrakeConfig(config, voidLogger); + airbrakeConfig = extractAirbrakeConfig(config); const router = await createRouter({ logger: voidLogger, diff --git a/plugins/airbrake-backend/src/service/standaloneServer.ts b/plugins/airbrake-backend/src/service/standaloneServer.ts index 2f2de71fa1..6825e60a0a 100644 --- a/plugins/airbrake-backend/src/service/standaloneServer.ts +++ b/plugins/airbrake-backend/src/service/standaloneServer.ts @@ -34,7 +34,7 @@ export async function startStandaloneServer( ): Promise { const logger = options.logger.child({ service: 'airbrake-backend' }); const config = await loadBackendConfig({ logger, argv: process.argv }); - const airbrakeConfig = extractAirbrakeConfig(config, logger); + const airbrakeConfig = extractAirbrakeConfig(config); logger.debug('Starting application server...'); const router = await createRouter({ logger, diff --git a/plugins/airbrake/README.md b/plugins/airbrake/README.md index 2fb5dbd2fc..d5ea9bb006 100644 --- a/plugins/airbrake/README.md +++ b/plugins/airbrake/README.md @@ -68,7 +68,7 @@ The Airbrake plugin provides connectivity between Backstage and Airbrake (https: ## Local Development -Start this plugin in standalone mode by running `yarn start`. This method of serving the plugin provides quicker +Start this plugin in standalone mode by running `yarn start` inside the plugin directory. This method of serving the plugin provides quicker iteration speed and a faster startup and hot reloads. It is only meant for local development, and the setup for it can be found inside the [/dev](./dev) directory.