From 09a37042643341a4f6f001554748e438573fb67f Mon Sep 17 00:00:00 2001
From: Patrik Oldsberg
Date: Wed, 30 Dec 2020 13:52:48 +0100
Subject: [PATCH 001/144] backend-common: remove deprecated HTTPS config
---
.changeset/wise-mice-invite.md | 5 +
packages/backend-common/config.d.ts | 35 ++----
.../backend-common/src/service/lib/config.ts | 36 +-----
.../src/service/lib/hostFactory.ts | 117 +++++++++---------
4 files changed, 82 insertions(+), 111 deletions(-)
create mode 100644 .changeset/wise-mice-invite.md
diff --git a/.changeset/wise-mice-invite.md b/.changeset/wise-mice-invite.md
new file mode 100644
index 0000000000..9021336c07
--- /dev/null
+++ b/.changeset/wise-mice-invite.md
@@ -0,0 +1,5 @@
+---
+'@backstage/backend-common': minor
+---
+
+Remove support for HTTPS certificate generation parameters. Use `backend.https = true` instead.
diff --git a/packages/backend-common/config.d.ts b/packages/backend-common/config.d.ts
index b7241bcc03..96dd71d41b 100644
--- a/packages/backend-common/config.d.ts
+++ b/packages/backend-common/config.d.ts
@@ -41,31 +41,16 @@ export interface Config {
https?:
| true
| {
- /**
- * Certificate configuration or parameters for generating a self-signed certificate
- *
- * Setting parameters for self-signed certificates is deprecated and will be removed in
- * the future, set `backend.https = true` instead.
- */
- certificate?:
- | {
- /** Algorithm to use to generate a self-signed certificate */
- algorithm?: string;
- keySize?: number;
- days?: number;
- attributes: {
- commonName: string;
- };
- }
- | {
- /** PEM encoded certificate. Use $file to load in a file */
- cert: string;
- /**
- * PEM encoded certificate key. Use $file to load in a file.
- * @visibility secret
- */
- key: string;
- };
+ /** Certificate configuration */
+ certificate?: {
+ /** PEM encoded certificate. Use $file to load in a file */
+ cert: string;
+ /**
+ * PEM encoded certificate key. Use $file to load in a file.
+ * @visibility secret
+ */
+ key: string;
+ };
};
/** Database connection configuration, select database type using the `client` field */
diff --git a/packages/backend-common/src/service/lib/config.ts b/packages/backend-common/src/service/lib/config.ts
index 6abea97454..5d9d12658d 100644
--- a/packages/backend-common/src/service/lib/config.ts
+++ b/packages/backend-common/src/service/lib/config.ts
@@ -22,23 +22,8 @@ export type BaseOptions = {
listenHost?: string;
};
-export type CertificateOptions = {
- key?: CertificateKeyOptions;
- attributes?: CertificateAttributeOptions;
-};
-
-export type CertificateKeyOptions = {
- size?: number;
- algorithm?: string;
- days?: number;
-};
-
-export type CertificateAttributeOptions = {
- commonName?: string;
-};
-
export type HttpsSettings = {
- certificate: CertificateSigningOptions | CertificateReferenceOptions;
+ certificate: CertificateGenerationOptions | CertificateReferenceOptions;
};
export type CertificateReferenceOptions = {
@@ -46,11 +31,8 @@ export type CertificateReferenceOptions = {
cert: string;
};
-export type CertificateSigningOptions = {
- algorithm?: string;
- size?: number;
- days?: number;
- attributes: CertificateAttributes;
+export type CertificateGenerationOptions = {
+ hostname: string;
};
export type CertificateAttributes = {
@@ -196,20 +178,14 @@ export function readHttpsSettings(config: Config): HttpsSettings | undefined {
const https = config.get('https');
if (https === true) {
const baseUrl = config.getString('baseUrl');
- let commonName;
+ let hostname;
try {
- commonName = new URL(baseUrl).hostname;
+ hostname = new URL(baseUrl).hostname;
} catch (error) {
throw new Error(`Invalid backend.baseUrl "${baseUrl}"`);
}
- return {
- certificate: {
- attributes: {
- commonName,
- },
- },
- };
+ return { certificate: { hostname } };
}
const cc = config.getOptionalConfig('https');
diff --git a/packages/backend-common/src/service/lib/hostFactory.ts b/packages/backend-common/src/service/lib/hostFactory.ts
index 656f160c31..db202a84ab 100644
--- a/packages/backend-common/src/service/lib/hostFactory.ts
+++ b/packages/backend-common/src/service/lib/hostFactory.ts
@@ -20,10 +20,12 @@ import express from 'express';
import * as http from 'http';
import * as https from 'https';
import { Logger } from 'winston';
-import { CertificateSigningOptions, HttpsSettings } from './config';
+import { HttpsSettings } from './config';
const ALMOST_MONTH_IN_MS = 25 * 24 * 60 * 60 * 1000;
+const IP_HOSTNAME_REGEX = /:|^\d+\.\d+\.\d+\.\d+$/;
+
/**
* Creates a Http server instance based on an Express application.
*
@@ -59,17 +61,17 @@ export async function createHttpsServer(
let credentials: { key: string | Buffer; cert: string | Buffer };
- const signingOptions: any = httpsSettings?.certificate;
-
- // TODO(Rugvip): remove support for generated certificate params and make this a more straightforward check
- if (signingOptions?.attributes) {
- credentials = await getGeneratedCertificate(signingOptions, logger);
+ if ('hostname' in httpsSettings?.certificate) {
+ credentials = await getGeneratedCertificate(
+ httpsSettings.certificate.hostname,
+ logger,
+ );
} else {
logger?.info('Loading certificate from config');
credentials = {
- key: signingOptions?.key,
- cert: signingOptions?.cert,
+ key: httpsSettings?.certificate?.key,
+ cert: httpsSettings?.certificate?.cert,
};
}
@@ -80,16 +82,7 @@ export async function createHttpsServer(
return https.createServer(credentials, app) as http.Server;
}
-async function getGeneratedCertificate(
- options: CertificateSigningOptions,
- logger?: Logger,
-) {
- if (options?.algorithm) {
- logger?.warn(
- 'Certificate generation configuration with parameters in backend.https.certificate is deprecated, set backend.https = true instead',
- );
- }
-
+async function getGeneratedCertificate(hostname: string, logger?: Logger) {
const hasModules = await fs.pathExists('node_modules');
let certPath;
if (hasModules) {
@@ -119,20 +112,61 @@ async function getGeneratedCertificate(
}
logger?.info('Generating new self-signed certificate');
- const newCert = await createCertificate(options);
+ const newCert = await createCertificate(hostname);
await fs.writeFile(certPath, newCert.cert + newCert.key, 'utf8');
return newCert;
}
-async function createCertificate(options: CertificateSigningOptions) {
- const attributes: Array = Object.entries(
- options.attributes,
- ).map(([name, value]) => ({ name, value }));
+async function createCertificate(hostname: string) {
+ const attributes = [
+ {
+ name: 'commonName',
+ value: 'dev-cert',
+ },
+ ];
+
+ const sans = [
+ {
+ type: 2, // DNS
+ value: 'localhost',
+ },
+ {
+ type: 2,
+ value: 'localhost.localdomain',
+ },
+ {
+ type: 2,
+ value: '[::1]',
+ },
+ {
+ type: 7, // IP
+ ip: '127.0.0.1',
+ },
+ {
+ type: 7,
+ ip: 'fe80::1',
+ },
+ ];
+
+ // Add hostname from backend.baseUrl if it doesn't already exist in our list of SANs
+ if (!sans.find(({ value, ip }) => value === hostname || ip === hostname)) {
+ sans.push(
+ IP_HOSTNAME_REGEX.test(hostname)
+ ? {
+ type: 7,
+ ip: hostname,
+ }
+ : {
+ type: 2,
+ value: hostname,
+ },
+ );
+ }
const params = {
- algorithm: options?.algorithm || 'sha256',
- keySize: options?.size || 2048,
- days: options?.days || 30,
+ algorithm: 'sha256',
+ keySize: 2048,
+ days: 30,
extensions: [
{
name: 'keyUsage',
@@ -151,36 +185,7 @@ async function createCertificate(options: CertificateSigningOptions) {
},
{
name: 'subjectAltName',
- altNames: [
- {
- type: 2, // DNS
- value: 'localhost',
- },
- {
- type: 2,
- value: 'localhost.localdomain',
- },
- {
- type: 2,
- value: '[::1]',
- },
- {
- type: 7, // IP
- ip: '127.0.0.1',
- },
- {
- type: 7,
- ip: 'fe80::1',
- },
- ...(options.attributes.commonName
- ? [
- {
- type: 2, // DNS
- value: options.attributes.commonName,
- },
- ]
- : []),
- ],
+ altNames: sans,
},
],
};
From c2386e9e860325f43775d700a016b91ecd7053d0 Mon Sep 17 00:00:00 2001
From: Jussi Hallila
Date: Mon, 11 Jan 2021 08:57:15 +0100
Subject: [PATCH 002/144] Modifying auth tutorial to contain different
providers. Adding a better example repo link.
---
docs/tutorials/quickstart-app-auth.md | 265 +++++++++++++++++++++++---
1 file changed, 239 insertions(+), 26 deletions(-)
diff --git a/docs/tutorials/quickstart-app-auth.md b/docs/tutorials/quickstart-app-auth.md
index 1dcca9d7e0..ecafd47b8c 100644
--- a/docs/tutorials/quickstart-app-auth.md
+++ b/docs/tutorials/quickstart-app-auth.md
@@ -3,20 +3,17 @@ id: quickstart-app-auth
title: Monorepo App Setup With Authentication
---
-###### September 15th 2020 - @backstage/create-app - v0.1.1-alpha.21
+###### January 8th 2021 - @backstage/create-app - v0.4.5
> This document takes you through setting up a Backstage app that runs in your
> own environment. It starts with a skeleton install and verifying of the
-> monorepo's functionality. Next, GitHub authentication is added and tested.
+> monorepo's functionality. Next, authentication is added and tested.
>
> This document assumes you have Node.js 12 active along with Yarn and Python.
-> Please note, that at the time of this writing, the current version is
-> 0.1.1-alpha.21. This guide can still be used with future versions, just,
-> verify as you go. If you run into issues, you can compare your setup with mine
-> here >
-> [simple-backstage-app](https://github.com/johnson-jesse/simple-backstage-app).
+> Please note, that at the time of this writing, the current version is v0.4.5
+> This guide can still be used with future versions, just, verify as you go.
# The Skeleton Application
@@ -55,6 +52,16 @@ guest. Let's fix that now and add auth.
# The Auth Configuration
+Default Backstage installation includes multiple authentication providers out of
+the box. The steps to enable new authentication provider in Backstage are very
+similar to each other, the biggest difference is usually configuring the
+external authentication provider. Please see a subset of possible providers and
+instructions to integrate them below. Steps 1 & 2 are described separately for
+each provider and steps beyond that are common for all.
+
+Github
+
+
1. Open `app-config.yaml` and change it as follows
_from:_
@@ -75,23 +82,224 @@ auth:
$env: AUTH_GITHUB_CLIENT_ID
clientSecret:
$env: AUTH_GITHUB_CLIENT_SECRET
- ## uncomment the following three lines if using enterprise
+ ## uncomment the following two lines if using enterprise
# enterpriseInstanceUrl:
# $env: AUTH_GITHUB_ENTERPRISE_INSTANCE_URL
```
-2. Set environment variables in whatever fashion is easiest for you. I chose to
+2. Generate Github client id and secret
+
+- Log into http://github.com
+- Navigate to (Settings > Developer Settings > OAuth Apps > New OAuth
+ App)[https://github.com/settings/applications/new]
+- Set Homepage URL = http://localhost:3000
+- Set Callback URL = http://localhost:7000/api/auth/github
+- Click [Register application]
+- On the next page, copy and paste your new Client ID and Client Secret to
+ environment variables defined in the `app-config.yaml` file,
+ `AUTH_GITHUB_CLIENT_ID` & `AUTH_GITHUB_CLIENT_SECRET`
+
+
+
+
+Gitlab
+
+
+1. Open `app-config.yaml` and change it as follows
+
+_from:_
+
+```yaml
+auth:
+ providers: {}
+```
+
+_to:_
+
+```yaml
+auth:
+ providers:
+ gitlab:
+ development:
+ clientId:
+ $env: AUTH_GITLAB_CLIENT_ID
+ clientSecret:
+ $env: AUTH_GITLAB_CLIENT_SECRET
+ audience: https://gitlab.com # Or your self-hosted Gitlab instance URL
+```
+
+2. Generate Gitlab Application for client id and secret
+
+- Log into Gitlab
+- Navigate to (Profile > Settings >
+ Applications)[https://gitlab.com/-/profile/applications]
+- Name your application
+- Set Callback URL = http://localhost:7000/api/auth/gitlab/handler/frame
+- Select the following values:
+ - `read_user (Read the authenticated user's personal information)`
+ - `read_repository (Allows read-only access to the repository)`
+ - `write_repository (Allows read-write access to the repository)`
+ - `openid (Authenticate using OpenID Connect)`
+ - `profile (Allows read-only access to the user's personal information using OpenID Connect)`
+ - `email (Allows read-only access to the user's primary email address using OpenID Connect)`
+- Click [Save application]
+- On the next page, copy and paste your new Application ID and Secret to
+ environment variables defined in the `app-config.yaml` file,
+ `AUTH_GITLAB_CLIENT_ID` & `AUTH_GITLAB_CLIENT_SECRET`
+
+
+
+
+Google
+
+
+1. Open `app-config.yaml` and change it as follows
+
+_from:_
+
+```yaml
+auth:
+ providers: {}
+```
+
+_to:_
+
+```yaml
+auth:
+ providers:
+ google:
+ development:
+ clientId:
+ $env: AUTH_GOOGLE_CLIENT_ID
+ clientSecret:
+ $env: AUTH_GOOGLE_CLIENT_SECRET
+```
+
+2. Generate Google Application in Google Cloud console
+
+- Log into https://console.cloud.google.com
+- Select or create a new project from the dropdown on the top bar
+- Navigate to (APIs & Services - >
+ Credentials)[https://console.cloud.google.com/apis/credentials]
+- Add new Authorised JavaScript origin = `http://localhost:3000`
+- Add new Authorised redirect URI =
+ `http://localhost:7000/api/auth/google/handler/frame`
+- Click [Save application]
+- Google should display a modal with your Client ID and Secret. Copy and paste
+ those to environment variables defined in the `app-config.yaml` file,
+ `AUTH_GOOGLE_CLIENT_ID` & `AUTH_GOOGLE_CLIENT_SECRET`
+
+
+
+
+Microsoft
+
+
+1. Open `app-config.yaml` and change it as follows
+
+_from:_
+
+```yaml
+auth:
+ providers: {}
+```
+
+_to:_
+
+```yaml
+auth:
+ providers:
+ microsoft:
+ development:
+ clientId:
+ $env: AUTH_MICROSOFT_CLIENT_ID
+ clientSecret:
+ $env: AUTH_MICROSOFT_CLIENT_SECRET
+ tenantId:
+ $env: AUTH_MICROSOFT_TENANT_ID
+```
+
+2. Create Microsoft Directory in Microsoft Portal
+
+- Log into https://portal.azure.com
+- Navigate to (Azure Active Directory -> App
+ Registrations)[https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/RegisteredApps]
+- Create a New Registration
+- Add new Redirect URI = `http://localhost:3000`
+- Add new Authorised redirect URI =
+ `http://localhost:7000/api/auth/microsoft/handler/frame`
+- Click [Save application]
+- Set environment variable `AUTH_MICROSOFT_CLIENT_ID` from
+ `Application (client) Id` displayed on the directory page
+- Set environment variable `AUTH_MICROSOFT_TENANT_ID` from
+ `Directory (tenant) ID` displayed on the directory page
+- Navigate to Certificates & Secrets section and click [Create a new secret]
+- Set environment variable `AUTH_MICROSOFT_CLIENT_SECRET` from the `value` field
+ created.
+
+
+
+
+Auth0
+
+
+1. Open `app-config.yaml` and change it as follows
+
+_from:_
+
+```yaml
+auth:
+ providers: {}
+```
+
+_to:_
+
+```yaml
+auth:
+ providers:
+ auth0:
+ development:
+ clientId:
+ $env: AUTH_AUTH0_CLIENT_ID
+ clientSecret:
+ $env: AUTH_AUTH0_CLIENT_SECRET
+ domain:
+ $env: AUTH_AUTH0_DOMAIN_ID
+```
+
+2. Create Auth0 application in Auth0 management console
+
+- Log into https://manage.auth0.com/dashboard/
+- Navigate to Applications
+- Create a New Application
+ - Select Single Page Web Application
+- Go to Settings tab
+- Add new line to Allowed Callback URLs =
+ `http://localhost:7000/api/auth/auth0/handler/frame`
+- Click [Save Changes]
+- Set environment variables displayed on the Basic Information page
+ - `AUTH_AUTH0_CLIENT_ID` from `Client ID` displayed on Auth0 application page
+ - `AUTH_AUTH0_CLIENT_SECRET` from `Client Secret` displayed on Auth0
+ application page
+ - `AUTH_AUTH0_DOMAIN_ID` from `Domain` displayed on Auth0 application page
+
+
+
+
+3. Set environment variables in whatever fashion is easiest for you. I chose to
add mine to my `.zshrc` profile.
```zsh
# For macOS Catalina & Z Shell
# ------ simple-backstage-app GitHub
+#
+# (Change the name of the environment variables based on your auth setup above
export AUTH_GITHUB_CLIENT_ID=xxx
export AUTH_GITHUB_CLIENT_SECRET=xxx
# export AUTH_GITHUB_ENTERPRISE_INSTANCE_URL=https://github.{MY_BIZ}.com
```
-3. And of course I need to source that file.
+4. And of course I need to source that file.
```zsh
# Loading the new variables
@@ -107,26 +315,26 @@ export AUTH_GITHUB_CLIENT_SECRET=xxx
> ...
```
-4. The values to replace `xxx` above come from your oauth app setup.
-
-```
-> Log into http://github.com
-> Navigate to (Settings > Developer Settings > OAuth Apps > New OAuth App)[https://github.com/settings/applications/new]
-> Set Homepage URL = http://localhost:3000
-> Set Callback URL = http://localhost:7000/api/auth/github
-> Click [Register application]
-> On the next page, copy and paste your new Client ID and Client Secret to the environment variables above, `AUTH_GITHUB_CLIENT_ID` & `AUTH_GITHUB_CLIENT_SECRET`
-> Don't forget to `source` that profile file again if necessary.
-```
-
-5. Open and change _root > packages > app > src >_`App.tsx` as follows
+6. Open and change _root > packages > app > src >_`App.tsx` to use correct
+ authentication provider reference
```tsx
-// Add the following imports to the existing list from core
import { githubAuthApiRef, SignInPage } from '@backstage/core';
```
-6. In the same file, change the createApp function as follows
+Modify the imported reference based on authentication method selected above
+
+| Auth Provider | Import Name |
+| ------------- | ------------------- |
+| Github | githubAuthApiRef |
+| Gitlab | gitlabAuthApiRef |
+| Google | googleAuthApiRef |
+| Microsoft | microsoftAuthApiRef |
+| Auth0 | googleAuthApiRef |
+
+7. In the same file, modify createApp
+
+Remeber to modify the provider information based on the table above.
```tsx
const app = createApp({
@@ -153,12 +361,17 @@ const app = createApp({
});
```
-7. Start the backend and frontend as before
+After finishing setting up one (or multiple) authentication providers defined
+above you can start the backend and frontend as before
When the browser loads, you should be presented with a login page for GitHub.
Login as usual with your GitHub account. If this is your first time, you will be
asked to authorize and then are redirected to the catalog page if all is well.
+For more information you can clone the repository:
+https://github.com/RoadieHQ/backstage-auth-example Each authentication setting
+is set up there on a branch named after the authentication provider.
+
# Where to go from here
> You're probably eager to write your first custom plugin. Follow this next
From e9c75d64a3aff49109d8f5851d17c0f7d02455df Mon Sep 17 00:00:00 2001
From: Jussi Hallila
Date: Mon, 11 Jan 2021 09:02:26 +0100
Subject: [PATCH 003/144] Fix typos.
---
docs/tutorials/quickstart-app-auth.md | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/docs/tutorials/quickstart-app-auth.md b/docs/tutorials/quickstart-app-auth.md
index ecafd47b8c..5991f626e7 100644
--- a/docs/tutorials/quickstart-app-auth.md
+++ b/docs/tutorials/quickstart-app-auth.md
@@ -293,7 +293,7 @@ auth:
# For macOS Catalina & Z Shell
# ------ simple-backstage-app GitHub
#
-# (Change the name of the environment variables based on your auth setup above
+# (Change the name of the environment variables based on your auth setup above)
export AUTH_GITHUB_CLIENT_ID=xxx
export AUTH_GITHUB_CLIENT_SECRET=xxx
# export AUTH_GITHUB_ENTERPRISE_INSTANCE_URL=https://github.{MY_BIZ}.com
@@ -315,7 +315,7 @@ export AUTH_GITHUB_CLIENT_SECRET=xxx
> ...
```
-6. Open and change _root > packages > app > src >_`App.tsx` to use correct
+5. Open and change _root > packages > app > src >`App.tsx` to use correct
authentication provider reference
```tsx
@@ -332,9 +332,9 @@ Modify the imported reference based on authentication method selected above
| Microsoft | microsoftAuthApiRef |
| Auth0 | googleAuthApiRef |
-7. In the same file, modify createApp
+6. In the same file, modify createApp
-Remeber to modify the provider information based on the table above.
+Remember to modify the provider information based on the table above.
```tsx
const app = createApp({
From b62bc928de9693d2af8e7cd131018f6d522021ed Mon Sep 17 00:00:00 2001
From: Jussi Hallila
Date: Mon, 11 Jan 2021 09:41:06 +0100
Subject: [PATCH 004/144] Run prettier.
---
docs/tutorials/quickstart-app-auth.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/tutorials/quickstart-app-auth.md b/docs/tutorials/quickstart-app-auth.md
index 5991f626e7..b6370fd1f9 100644
--- a/docs/tutorials/quickstart-app-auth.md
+++ b/docs/tutorials/quickstart-app-auth.md
@@ -315,7 +315,7 @@ export AUTH_GITHUB_CLIENT_SECRET=xxx
> ...
```
-5. Open and change _root > packages > app > src >`App.tsx` to use correct
+5. Open and change \_root > packages > app > src >`App.tsx` to use correct
authentication provider reference
```tsx
From 34206f81f05459a675c40e0351cdd0b0de8b97ed Mon Sep 17 00:00:00 2001
From: Jussi Hallila
Date: Mon, 11 Jan 2021 13:47:47 +0100
Subject: [PATCH 005/144] Adding reference to latest node LTS as well.
Resolves:
* https://github.com/backstage/backstage/pull/4003#discussion_r554920635
---
docs/tutorials/quickstart-app-auth.md | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/docs/tutorials/quickstart-app-auth.md b/docs/tutorials/quickstart-app-auth.md
index b6370fd1f9..48b5d2b3a7 100644
--- a/docs/tutorials/quickstart-app-auth.md
+++ b/docs/tutorials/quickstart-app-auth.md
@@ -11,9 +11,10 @@ title: Monorepo App Setup With Authentication
> own environment. It starts with a skeleton install and verifying of the
> monorepo's functionality. Next, authentication is added and tested.
>
-> This document assumes you have Node.js 12 active along with Yarn and Python.
-> Please note, that at the time of this writing, the current version is v0.4.5
-> This guide can still be used with future versions, just, verify as you go.
+> This document assumes you have Node.js 12 or 14 active along with Yarn and
+> Python. Please note, that at the time of this writing, the current version is
+> v0.4.5 This guide can still be used with future versions, just, verify as you
+> go.
# The Skeleton Application
From 82e35cd6531b9b62d4b264dd831a5585fc2e24b0 Mon Sep 17 00:00:00 2001
From: Jussi Hallila
Date: Mon, 11 Jan 2021 16:57:58 +0100
Subject: [PATCH 006/144] Update docs/tutorials/quickstart-app-auth.md
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Fredrik Adelöw
---
docs/tutorials/quickstart-app-auth.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/tutorials/quickstart-app-auth.md b/docs/tutorials/quickstart-app-auth.md
index 48b5d2b3a7..88ccce6ae5 100644
--- a/docs/tutorials/quickstart-app-auth.md
+++ b/docs/tutorials/quickstart-app-auth.md
@@ -13,7 +13,7 @@ title: Monorepo App Setup With Authentication
>
> This document assumes you have Node.js 12 or 14 active along with Yarn and
> Python. Please note, that at the time of this writing, the current version is
-> v0.4.5 This guide can still be used with future versions, just, verify as you
+> v0.4.5. This guide can still be used with future versions, just, verify as you
> go.
# The Skeleton Application
From ff4e53bd4ebb257732b0374cc6b2d19988e1cfe7 Mon Sep 17 00:00:00 2001
From: Jussi Hallila
Date: Mon, 11 Jan 2021 16:58:08 +0100
Subject: [PATCH 007/144] Update docs/tutorials/quickstart-app-auth.md
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Fredrik Adelöw
---
docs/tutorials/quickstart-app-auth.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/tutorials/quickstart-app-auth.md b/docs/tutorials/quickstart-app-auth.md
index 88ccce6ae5..2affcec7fc 100644
--- a/docs/tutorials/quickstart-app-auth.md
+++ b/docs/tutorials/quickstart-app-auth.md
@@ -53,7 +53,7 @@ guest. Let's fix that now and add auth.
# The Auth Configuration
-Default Backstage installation includes multiple authentication providers out of
+A default Backstage installation includes multiple authentication providers out of
the box. The steps to enable new authentication provider in Backstage are very
similar to each other, the biggest difference is usually configuring the
external authentication provider. Please see a subset of possible providers and
From 322b04bff7191e0f31591a9306888e140b48f7fb Mon Sep 17 00:00:00 2001
From: Jussi Hallila
Date: Mon, 11 Jan 2021 16:58:14 +0100
Subject: [PATCH 008/144] Update docs/tutorials/quickstart-app-auth.md
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Fredrik Adelöw
---
docs/tutorials/quickstart-app-auth.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/tutorials/quickstart-app-auth.md b/docs/tutorials/quickstart-app-auth.md
index 2affcec7fc..12d3767791 100644
--- a/docs/tutorials/quickstart-app-auth.md
+++ b/docs/tutorials/quickstart-app-auth.md
@@ -54,7 +54,7 @@ guest. Let's fix that now and add auth.
# The Auth Configuration
A default Backstage installation includes multiple authentication providers out of
-the box. The steps to enable new authentication provider in Backstage are very
+the box. The steps to enable new authentication providers in Backstage are very
similar to each other, the biggest difference is usually configuring the
external authentication provider. Please see a subset of possible providers and
instructions to integrate them below. Steps 1 & 2 are described separately for
From f3165cce9535a17d7698a584c90397d8ba351dfe Mon Sep 17 00:00:00 2001
From: Jussi Hallila
Date: Mon, 11 Jan 2021 16:58:24 +0100
Subject: [PATCH 009/144] Update docs/tutorials/quickstart-app-auth.md
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Fredrik Adelöw
---
docs/tutorials/quickstart-app-auth.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/tutorials/quickstart-app-auth.md b/docs/tutorials/quickstart-app-auth.md
index 12d3767791..7e05a5a63d 100644
--- a/docs/tutorials/quickstart-app-auth.md
+++ b/docs/tutorials/quickstart-app-auth.md
@@ -88,7 +88,7 @@ auth:
# $env: AUTH_GITHUB_ENTERPRISE_INSTANCE_URL
```
-2. Generate Github client id and secret
+2. Generate a GitHub client ID and secret
- Log into http://github.com
- Navigate to (Settings > Developer Settings > OAuth Apps > New OAuth
From 642bf0be1a47df153704e32e8304fe98ef94ce65 Mon Sep 17 00:00:00 2001
From: Jussi Hallila
Date: Mon, 11 Jan 2021 16:59:17 +0100
Subject: [PATCH 010/144] Update docs/tutorials/quickstart-app-auth.md
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Fredrik Adelöw
---
docs/tutorials/quickstart-app-auth.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/tutorials/quickstart-app-auth.md b/docs/tutorials/quickstart-app-auth.md
index 7e05a5a63d..0f5e452aa5 100644
--- a/docs/tutorials/quickstart-app-auth.md
+++ b/docs/tutorials/quickstart-app-auth.md
@@ -103,7 +103,7 @@ auth:
-Gitlab
+GitLab
1. Open `app-config.yaml` and change it as follows
From 72399d57e5612b6198bce30efd2910ab67effef4 Mon Sep 17 00:00:00 2001
From: Jussi Hallila
Date: Mon, 11 Jan 2021 16:59:38 +0100
Subject: [PATCH 011/144] Update docs/tutorials/quickstart-app-auth.md
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Fredrik Adelöw
---
docs/tutorials/quickstart-app-auth.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/tutorials/quickstart-app-auth.md b/docs/tutorials/quickstart-app-auth.md
index 0f5e452aa5..2d23402edd 100644
--- a/docs/tutorials/quickstart-app-auth.md
+++ b/docs/tutorials/quickstart-app-auth.md
@@ -129,7 +129,7 @@ auth:
audience: https://gitlab.com # Or your self-hosted Gitlab instance URL
```
-2. Generate Gitlab Application for client id and secret
+2. Generate a GitLab Application client ID and secret
- Log into Gitlab
- Navigate to (Profile > Settings >
From cc64069374adea4d24e4781f2ca64cb4fb8d0da5 Mon Sep 17 00:00:00 2001
From: Jussi Hallila
Date: Mon, 11 Jan 2021 16:59:51 +0100
Subject: [PATCH 012/144] Update docs/tutorials/quickstart-app-auth.md
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Fredrik Adelöw
---
docs/tutorials/quickstart-app-auth.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/tutorials/quickstart-app-auth.md b/docs/tutorials/quickstart-app-auth.md
index 2d23402edd..b58596b434 100644
--- a/docs/tutorials/quickstart-app-auth.md
+++ b/docs/tutorials/quickstart-app-auth.md
@@ -131,7 +131,7 @@ auth:
2. Generate a GitLab Application client ID and secret
-- Log into Gitlab
+- Log into GitLab
- Navigate to (Profile > Settings >
Applications)[https://gitlab.com/-/profile/applications]
- Name your application
From 163e263d8eb8e06868f7d464ba86b3adfaf76a23 Mon Sep 17 00:00:00 2001
From: Jussi Hallila
Date: Mon, 11 Jan 2021 17:00:35 +0100
Subject: [PATCH 013/144] Update docs/tutorials/quickstart-app-auth.md
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Fredrik Adelöw
---
docs/tutorials/quickstart-app-auth.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/tutorials/quickstart-app-auth.md b/docs/tutorials/quickstart-app-auth.md
index b58596b434..00c97cfe4b 100644
--- a/docs/tutorials/quickstart-app-auth.md
+++ b/docs/tutorials/quickstart-app-auth.md
@@ -180,7 +180,7 @@ auth:
- Log into https://console.cloud.google.com
- Select or create a new project from the dropdown on the top bar
-- Navigate to (APIs & Services - >
+- Navigate to (APIs & Services >
Credentials)[https://console.cloud.google.com/apis/credentials]
- Add new Authorised JavaScript origin = `http://localhost:3000`
- Add new Authorised redirect URI =
From ecba810c98a37c72a915061f5822eec338db62a2 Mon Sep 17 00:00:00 2001
From: Jussi Hallila
Date: Mon, 11 Jan 2021 17:01:32 +0100
Subject: [PATCH 014/144] Update docs/tutorials/quickstart-app-auth.md
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Fredrik Adelöw
---
docs/tutorials/quickstart-app-auth.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/tutorials/quickstart-app-auth.md b/docs/tutorials/quickstart-app-auth.md
index 00c97cfe4b..1cae03469d 100644
--- a/docs/tutorials/quickstart-app-auth.md
+++ b/docs/tutorials/quickstart-app-auth.md
@@ -323,7 +323,7 @@ export AUTH_GITHUB_CLIENT_SECRET=xxx
import { githubAuthApiRef, SignInPage } from '@backstage/core';
```
-Modify the imported reference based on authentication method selected above
+Modify the imported reference based on the authentication method you selected above:
| Auth Provider | Import Name |
| ------------- | ------------------- |
From 33267d1cb9f398153634a2dfb0851b5edfc488c8 Mon Sep 17 00:00:00 2001
From: Jussi Hallila
Date: Mon, 11 Jan 2021 17:01:39 +0100
Subject: [PATCH 015/144] Update docs/tutorials/quickstart-app-auth.md
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Fredrik Adelöw
---
docs/tutorials/quickstart-app-auth.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/tutorials/quickstart-app-auth.md b/docs/tutorials/quickstart-app-auth.md
index 1cae03469d..900c52c484 100644
--- a/docs/tutorials/quickstart-app-auth.md
+++ b/docs/tutorials/quickstart-app-auth.md
@@ -331,7 +331,7 @@ Modify the imported reference based on the authentication method you selected ab
| Gitlab | gitlabAuthApiRef |
| Google | googleAuthApiRef |
| Microsoft | microsoftAuthApiRef |
-| Auth0 | googleAuthApiRef |
+| Auth0 | auth0AuthApiRef |
6. In the same file, modify createApp
From 39b45b62b4889953dcf8676cf61b75d5f3a51876 Mon Sep 17 00:00:00 2001
From: Jussi Hallila
Date: Mon, 11 Jan 2021 17:01:49 +0100
Subject: [PATCH 016/144] Update docs/tutorials/quickstart-app-auth.md
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Fredrik Adelöw
---
docs/tutorials/quickstart-app-auth.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/docs/tutorials/quickstart-app-auth.md b/docs/tutorials/quickstart-app-auth.md
index 900c52c484..db97ae5ed4 100644
--- a/docs/tutorials/quickstart-app-auth.md
+++ b/docs/tutorials/quickstart-app-auth.md
@@ -369,8 +369,8 @@ When the browser loads, you should be presented with a login page for GitHub.
Login as usual with your GitHub account. If this is your first time, you will be
asked to authorize and then are redirected to the catalog page if all is well.
-For more information you can clone the repository:
-https://github.com/RoadieHQ/backstage-auth-example Each authentication setting
+For more information you can clone [the backstage-auth-example repository](https://github.com/RoadieHQ/backstage-auth-example).
+ Each authentication setting
is set up there on a branch named after the authentication provider.
# Where to go from here
From dc48cfc9f2d862f8ec805ffc4fc67d0ae33b0e27 Mon Sep 17 00:00:00 2001
From: Jussi Hallila
Date: Tue, 12 Jan 2021 08:27:31 +0100
Subject: [PATCH 017/144] Update docs/tutorials/quickstart-app-auth.md
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Fredrik Adelöw
---
docs/tutorials/quickstart-app-auth.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/tutorials/quickstart-app-auth.md b/docs/tutorials/quickstart-app-auth.md
index db97ae5ed4..364e4a434a 100644
--- a/docs/tutorials/quickstart-app-auth.md
+++ b/docs/tutorials/quickstart-app-auth.md
@@ -268,7 +268,7 @@ auth:
$env: AUTH_AUTH0_DOMAIN_ID
```
-2. Create Auth0 application in Auth0 management console
+2. Create an Auth0 application in the Auth0 management console
- Log into https://manage.auth0.com/dashboard/
- Navigate to Applications
From 4f0993407b406037d0468a77638d82da6993ed51 Mon Sep 17 00:00:00 2001
From: Jussi Hallila
Date: Tue, 12 Jan 2021 08:31:32 +0100
Subject: [PATCH 018/144] Update docs/tutorials/quickstart-app-auth.md
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Fredrik Adelöw
---
docs/tutorials/quickstart-app-auth.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/tutorials/quickstart-app-auth.md b/docs/tutorials/quickstart-app-auth.md
index 364e4a434a..0fd48dc7bf 100644
--- a/docs/tutorials/quickstart-app-auth.md
+++ b/docs/tutorials/quickstart-app-auth.md
@@ -223,7 +223,7 @@ auth:
2. Create Microsoft Directory in Microsoft Portal
- Log into https://portal.azure.com
-- Navigate to (Azure Active Directory -> App
+- Navigate to (Azure Active Directory > App
Registrations)[https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/RegisteredApps]
- Create a New Registration
- Add new Redirect URI = `http://localhost:3000`
From 80619474d854e3f1e1f8205920fa43cae513fc28 Mon Sep 17 00:00:00 2001
From: Jussi Hallila
Date: Tue, 12 Jan 2021 08:46:22 +0100
Subject: [PATCH 019/144] Update docs/tutorials/quickstart-app-auth.md
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Fredrik Adelöw
---
docs/tutorials/quickstart-app-auth.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/tutorials/quickstart-app-auth.md b/docs/tutorials/quickstart-app-auth.md
index 0fd48dc7bf..2ad2d7c900 100644
--- a/docs/tutorials/quickstart-app-auth.md
+++ b/docs/tutorials/quickstart-app-auth.md
@@ -220,7 +220,7 @@ auth:
$env: AUTH_MICROSOFT_TENANT_ID
```
-2. Create Microsoft Directory in Microsoft Portal
+2. Create a Microsoft App Registration in Microsoft Portal
- Log into https://portal.azure.com
- Navigate to (Azure Active Directory > App
From 0fed686aed8791e0ce24911df04193bb44b34e3e Mon Sep 17 00:00:00 2001
From: Jussi Hallila
Date: Tue, 12 Jan 2021 08:47:27 +0100
Subject: [PATCH 020/144] Update docs/tutorials/quickstart-app-auth.md
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Fredrik Adelöw
---
docs/tutorials/quickstart-app-auth.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/tutorials/quickstart-app-auth.md b/docs/tutorials/quickstart-app-auth.md
index 2ad2d7c900..7475061b9e 100644
--- a/docs/tutorials/quickstart-app-auth.md
+++ b/docs/tutorials/quickstart-app-auth.md
@@ -176,7 +176,7 @@ auth:
$env: AUTH_GOOGLE_CLIENT_SECRET
```
-2. Generate Google Application in Google Cloud console
+2. Generate Google Credentials in Google Cloud console
- Log into https://console.cloud.google.com
- Select or create a new project from the dropdown on the top bar
From 6d74776e1214f1e9ffe187f89cf909cbfdd027f1 Mon Sep 17 00:00:00 2001
From: Jussi Hallila
Date: Tue, 12 Jan 2021 08:55:45 +0100
Subject: [PATCH 021/144] Adds in more modifications based on PR comments
Run prettier.
Add heading level for list items.
Fix styling and nomenclature.
---
docs/tutorials/quickstart-app-auth.md | 68 +++++++++++++++------------
1 file changed, 38 insertions(+), 30 deletions(-)
diff --git a/docs/tutorials/quickstart-app-auth.md b/docs/tutorials/quickstart-app-auth.md
index 7475061b9e..205fcddb65 100644
--- a/docs/tutorials/quickstart-app-auth.md
+++ b/docs/tutorials/quickstart-app-auth.md
@@ -53,9 +53,9 @@ guest. Let's fix that now and add auth.
# The Auth Configuration
-A default Backstage installation includes multiple authentication providers out of
-the box. The steps to enable new authentication providers in Backstage are very
-similar to each other, the biggest difference is usually configuring the
+A default Backstage installation includes multiple authentication providers out
+of the box. The steps to enable new authentication providers in Backstage are
+very similar to each other, the biggest difference is usually configuring the
external authentication provider. Please see a subset of possible providers and
instructions to integrate them below. Steps 1 & 2 are described separately for
each provider and steps beyond that are common for all.
@@ -63,7 +63,7 @@ each provider and steps beyond that are common for all.
Github
-1. Open `app-config.yaml` and change it as follows
+### 1. Open `app-config.yaml` and change it as follows
_from:_
@@ -88,7 +88,7 @@ auth:
# $env: AUTH_GITHUB_ENTERPRISE_INSTANCE_URL
```
-2. Generate a GitHub client ID and secret
+### 2. Generate a GitHub client ID and secret
- Log into http://github.com
- Navigate to (Settings > Developer Settings > OAuth Apps > New OAuth
@@ -106,7 +106,7 @@ auth:
GitLab
-1. Open `app-config.yaml` and change it as follows
+### 1. Open `app-config.yaml` and change it as follows
_from:_
@@ -129,7 +129,7 @@ auth:
audience: https://gitlab.com # Or your self-hosted Gitlab instance URL
```
-2. Generate a GitLab Application client ID and secret
+### 2. Generate a Gitlab Application client ID and secret
- Log into GitLab
- Navigate to (Profile > Settings >
@@ -137,12 +137,14 @@ auth:
- Name your application
- Set Callback URL = http://localhost:7000/api/auth/gitlab/handler/frame
- Select the following values:
- - `read_user (Read the authenticated user's personal information)`
- - `read_repository (Allows read-only access to the repository)`
- - `write_repository (Allows read-write access to the repository)`
- - `openid (Authenticate using OpenID Connect)`
- - `profile (Allows read-only access to the user's personal information using OpenID Connect)`
- - `email (Allows read-only access to the user's primary email address using OpenID Connect)`
+ - `read_user` (Read the authenticated user's personal information)
+ - `read_repository` (Allows read-only access to the repository)
+ - `write_repository` (Allows read-write access to the repository)
+ - `openid` (Authenticate using OpenID Connect)
+ - `profile` (Allows read-only access to the user's personal information using
+ OpenID Connect)
+ - `email` (Allows read-only access to the user's primary email address using
+ OpenID Connect)
- Click [Save application]
- On the next page, copy and paste your new Application ID and Secret to
environment variables defined in the `app-config.yaml` file,
@@ -154,7 +156,7 @@ auth:
Google
-1. Open `app-config.yaml` and change it as follows
+### 1. Open `app-config.yaml` and change it as follows
_from:_
@@ -176,12 +178,14 @@ auth:
$env: AUTH_GOOGLE_CLIENT_SECRET
```
-2. Generate Google Credentials in Google Cloud console
+### 2. Generate Google Credentials in Google Cloud console
- Log into https://console.cloud.google.com
- Select or create a new project from the dropdown on the top bar
- Navigate to (APIs & Services >
Credentials)[https://console.cloud.google.com/apis/credentials]
+- Click Create Credentials and select [OAuth client ID]
+- Select Web Application as the application type
- Add new Authorised JavaScript origin = `http://localhost:3000`
- Add new Authorised redirect URI =
`http://localhost:7000/api/auth/google/handler/frame`
@@ -196,7 +200,7 @@ auth:
Microsoft
-1. Open `app-config.yaml` and change it as follows
+### 1. Open `app-config.yaml` and change it as follows
_from:_
@@ -220,7 +224,7 @@ auth:
$env: AUTH_MICROSOFT_TENANT_ID
```
-2. Create a Microsoft App Registration in Microsoft Portal
+### 2. Create a Microsoft App Registration in Microsoft Portal
- Log into https://portal.azure.com
- Navigate to (Azure Active Directory > App
@@ -244,7 +248,7 @@ auth:
Auth0
-1. Open `app-config.yaml` and change it as follows
+### 1. Open `app-config.yaml` and change it as follows
_from:_
@@ -268,7 +272,7 @@ auth:
$env: AUTH_AUTH0_DOMAIN_ID
```
-2. Create an Auth0 application in the Auth0 management console
+### 2. Create an Auth0 application in the Auth0 management console
- Log into https://manage.auth0.com/dashboard/
- Navigate to Applications
@@ -287,8 +291,9 @@ auth:
-3. Set environment variables in whatever fashion is easiest for you. I chose to
- add mine to my `.zshrc` profile.
+### 3. Set environment variables in whatever fashion is easiest for you. I chose to
+
+add mine to my `.zshrc` profile.
```zsh
# For macOS Catalina & Z Shell
@@ -300,7 +305,7 @@ export AUTH_GITHUB_CLIENT_SECRET=xxx
# export AUTH_GITHUB_ENTERPRISE_INSTANCE_URL=https://github.{MY_BIZ}.com
```
-4. And of course I need to source that file.
+### 4. And of course I need to source that file.
```zsh
# Loading the new variables
@@ -316,14 +321,16 @@ export AUTH_GITHUB_CLIENT_SECRET=xxx
> ...
```
-5. Open and change \_root > packages > app > src >`App.tsx` to use correct
- authentication provider reference
+### 5. Open and change _root > packages > app > src >_ `App.tsx` to use correct
+
+authentication provider reference
```tsx
import { githubAuthApiRef, SignInPage } from '@backstage/core';
```
-Modify the imported reference based on the authentication method you selected above:
+Modify the imported reference based on the authentication method you selected
+above:
| Auth Provider | Import Name |
| ------------- | ------------------- |
@@ -331,9 +338,9 @@ Modify the imported reference based on the authentication method you selected ab
| Gitlab | gitlabAuthApiRef |
| Google | googleAuthApiRef |
| Microsoft | microsoftAuthApiRef |
-| Auth0 | auth0AuthApiRef |
+| Auth0 | auth0AuthApiRef |
-6. In the same file, modify createApp
+### 6. In the same file, modify createApp
Remember to modify the provider information based on the table above.
@@ -369,9 +376,10 @@ When the browser loads, you should be presented with a login page for GitHub.
Login as usual with your GitHub account. If this is your first time, you will be
asked to authorize and then are redirected to the catalog page if all is well.
-For more information you can clone [the backstage-auth-example repository](https://github.com/RoadieHQ/backstage-auth-example).
- Each authentication setting
-is set up there on a branch named after the authentication provider.
+For more information you can clone
+[the backstage-auth-example repository](https://github.com/RoadieHQ/backstage-auth-example).
+Each authentication setting is set up there on a branch named after the
+authentication provider.
# Where to go from here
From 4e4dc71b2c2dd68a1ba54db1a9da85fdeb1a70ca Mon Sep 17 00:00:00 2001
From: Himanshu Mishra
Date: Tue, 12 Jan 2021 21:33:33 +0100
Subject: [PATCH 022/144] microsite: set UR redirects for core features
We already have a redirect in place i.e. /docs to /docs/overview/what-is-backstage/
This PR adds 3 new redirects
/docs/features/software-catalog -> /docs/features/software-catalog/software-catalog-overview
/docs/features/techdocs -> /docs/features/techdocs/techdocs-overview
/docs/features/software-templates -> /docs/features/software-templates/software-templates-index
---
.../pages/en/docs/features/software-catalog/index.js | 12 ++++++++++++
.../en/docs/features/software-templates/index.js | 12 ++++++++++++
microsite/pages/en/docs/features/techdocs/index.js | 12 ++++++++++++
3 files changed, 36 insertions(+)
create mode 100644 microsite/pages/en/docs/features/software-catalog/index.js
create mode 100644 microsite/pages/en/docs/features/software-templates/index.js
create mode 100644 microsite/pages/en/docs/features/techdocs/index.js
diff --git a/microsite/pages/en/docs/features/software-catalog/index.js b/microsite/pages/en/docs/features/software-catalog/index.js
new file mode 100644
index 0000000000..619641ced1
--- /dev/null
+++ b/microsite/pages/en/docs/features/software-catalog/index.js
@@ -0,0 +1,12 @@
+const React = require('react');
+const Redirect = require('../../../../../core/Redirect.js');
+
+const siteConfig = require(process.cwd() + '/siteConfig.js');
+
+function Docs() {
+ return (
+
+ );
+}
+
+module.exports = Docs;
diff --git a/microsite/pages/en/docs/features/software-templates/index.js b/microsite/pages/en/docs/features/software-templates/index.js
new file mode 100644
index 0000000000..c5592844e5
--- /dev/null
+++ b/microsite/pages/en/docs/features/software-templates/index.js
@@ -0,0 +1,12 @@
+const React = require('react');
+const Redirect = require('../../../../../core/Redirect.js');
+
+const siteConfig = require(process.cwd() + '/siteConfig.js');
+
+function Docs() {
+ return (
+
+ );
+}
+
+module.exports = Docs;
diff --git a/microsite/pages/en/docs/features/techdocs/index.js b/microsite/pages/en/docs/features/techdocs/index.js
new file mode 100644
index 0000000000..e92f6bf82e
--- /dev/null
+++ b/microsite/pages/en/docs/features/techdocs/index.js
@@ -0,0 +1,12 @@
+const React = require('react');
+const Redirect = require('../../../../../core/Redirect.js');
+
+const siteConfig = require(process.cwd() + '/siteConfig.js');
+
+function Docs() {
+ return (
+
+ );
+}
+
+module.exports = Docs;
From 50e063f4955715f2f5af75ddc55e72614b778c3f Mon Sep 17 00:00:00 2001
From: Himanshu Mishra
Date: Tue, 12 Jan 2021 21:44:47 +0100
Subject: [PATCH 023/144] microsite prettier has a different version than
backstage root package.json
---
microsite/pages/en/docs/features/software-catalog/index.js | 5 ++++-
microsite/pages/en/docs/features/software-templates/index.js | 5 ++++-
microsite/pages/en/docs/features/techdocs/index.js | 5 ++++-
3 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/microsite/pages/en/docs/features/software-catalog/index.js b/microsite/pages/en/docs/features/software-catalog/index.js
index 619641ced1..cffc91af21 100644
--- a/microsite/pages/en/docs/features/software-catalog/index.js
+++ b/microsite/pages/en/docs/features/software-catalog/index.js
@@ -5,7 +5,10 @@ const siteConfig = require(process.cwd() + '/siteConfig.js');
function Docs() {
return (
-
+
);
}
diff --git a/microsite/pages/en/docs/features/software-templates/index.js b/microsite/pages/en/docs/features/software-templates/index.js
index c5592844e5..79d3f0659e 100644
--- a/microsite/pages/en/docs/features/software-templates/index.js
+++ b/microsite/pages/en/docs/features/software-templates/index.js
@@ -5,7 +5,10 @@ const siteConfig = require(process.cwd() + '/siteConfig.js');
function Docs() {
return (
-
+
);
}
diff --git a/microsite/pages/en/docs/features/techdocs/index.js b/microsite/pages/en/docs/features/techdocs/index.js
index e92f6bf82e..c45cde24f5 100644
--- a/microsite/pages/en/docs/features/techdocs/index.js
+++ b/microsite/pages/en/docs/features/techdocs/index.js
@@ -5,7 +5,10 @@ const siteConfig = require(process.cwd() + '/siteConfig.js');
function Docs() {
return (
-
+
);
}
From abbee6fff46a6ffc866df086063a4bf41877999f Mon Sep 17 00:00:00 2001
From: Oliver Sand
Date: Tue, 12 Jan 2021 17:05:49 +0100
Subject: [PATCH 024/144] Add system, domain and resource entity kinds
---
.changeset/thin-icons-kick.md | 6 +
app-config.yaml | 2 +-
.../src/kinds/ApiEntityV1alpha1.test.ts | 16 ++
.../src/kinds/ApiEntityV1alpha1.ts | 2 +
.../src/kinds/ComponentEntityV1alpha1.test.ts | 16 ++
.../src/kinds/ComponentEntityV1alpha1.ts | 2 +
.../src/kinds/DomainEntityV1alpha1.test.ts | 71 ++++++++
.../src/kinds/DomainEntityV1alpha1.ts | 46 +++++
.../src/kinds/ResourceEntityV1alpha1.test.ts | 103 +++++++++++
.../src/kinds/ResourceEntityV1alpha1.ts | 50 ++++++
.../src/kinds/SystemEntityV1alpha1.test.ts | 87 +++++++++
.../src/kinds/SystemEntityV1alpha1.ts | 48 +++++
packages/catalog-model/src/kinds/index.ts | 15 ++
packages/catalog-model/src/kinds/relations.ts | 7 +-
.../BuiltinKindsEntityProcessor.test.ts | 169 +++++++++++++++++-
.../processors/BuiltinKindsEntityProcessor.ts | 79 +++++++-
16 files changed, 713 insertions(+), 6 deletions(-)
create mode 100644 .changeset/thin-icons-kick.md
create mode 100644 packages/catalog-model/src/kinds/DomainEntityV1alpha1.test.ts
create mode 100644 packages/catalog-model/src/kinds/DomainEntityV1alpha1.ts
create mode 100644 packages/catalog-model/src/kinds/ResourceEntityV1alpha1.test.ts
create mode 100644 packages/catalog-model/src/kinds/ResourceEntityV1alpha1.ts
create mode 100644 packages/catalog-model/src/kinds/SystemEntityV1alpha1.test.ts
create mode 100644 packages/catalog-model/src/kinds/SystemEntityV1alpha1.ts
diff --git a/.changeset/thin-icons-kick.md b/.changeset/thin-icons-kick.md
new file mode 100644
index 0000000000..348f55a8ad
--- /dev/null
+++ b/.changeset/thin-icons-kick.md
@@ -0,0 +1,6 @@
+---
+'@backstage/catalog-model': patch
+'@backstage/plugin-catalog-backend': patch
+---
+
+Implement System, Domain and Resource entity kinds.
diff --git a/app-config.yaml b/app-config.yaml
index 48869cc0a0..b67e9525bf 100644
--- a/app-config.yaml
+++ b/app-config.yaml
@@ -127,7 +127,7 @@ integrations:
catalog:
rules:
- - allow: [Component, API, Group, User, Template, Location]
+ - allow: [Component, API, Resource, Group, User, Template, System, Domain, Location]
processors:
githubOrg:
diff --git a/packages/catalog-model/src/kinds/ApiEntityV1alpha1.test.ts b/packages/catalog-model/src/kinds/ApiEntityV1alpha1.test.ts
index a5d5152fab..a4d7d904cd 100644
--- a/packages/catalog-model/src/kinds/ApiEntityV1alpha1.test.ts
+++ b/packages/catalog-model/src/kinds/ApiEntityV1alpha1.test.ts
@@ -70,6 +70,7 @@ components:
items:
$ref: "#/components/schemas/Pet"
`,
+ system: 'system',
},
};
});
@@ -152,4 +153,19 @@ components:
(entity as any).spec.definition = '';
await expect(validator.check(entity)).rejects.toThrow(/definition/);
});
+
+ it('accepts missing system', async () => {
+ delete (entity as any).spec.system;
+ await expect(validator.check(entity)).resolves.toBe(true);
+ });
+
+ it('rejects wrong system', async () => {
+ (entity as any).spec.system = 7;
+ await expect(validator.check(entity)).rejects.toThrow(/system/);
+ });
+
+ it('rejects empty system', async () => {
+ (entity as any).spec.system = '';
+ await expect(validator.check(entity)).rejects.toThrow(/system/);
+ });
});
diff --git a/packages/catalog-model/src/kinds/ApiEntityV1alpha1.ts b/packages/catalog-model/src/kinds/ApiEntityV1alpha1.ts
index 660cd71cd8..2c634ff091 100644
--- a/packages/catalog-model/src/kinds/ApiEntityV1alpha1.ts
+++ b/packages/catalog-model/src/kinds/ApiEntityV1alpha1.ts
@@ -30,6 +30,7 @@ const schema = yup.object>({
lifecycle: yup.string().required().min(1),
owner: yup.string().required().min(1),
definition: yup.string().required().min(1),
+ system: yup.string().notRequired().min(1),
})
.required(),
});
@@ -42,6 +43,7 @@ export interface ApiEntityV1alpha1 extends Entity {
lifecycle: string;
owner: string;
definition: string;
+ system?: string;
};
}
diff --git a/packages/catalog-model/src/kinds/ComponentEntityV1alpha1.test.ts b/packages/catalog-model/src/kinds/ComponentEntityV1alpha1.test.ts
index 10d66ac880..9284a5d5b1 100644
--- a/packages/catalog-model/src/kinds/ComponentEntityV1alpha1.test.ts
+++ b/packages/catalog-model/src/kinds/ComponentEntityV1alpha1.test.ts
@@ -36,6 +36,7 @@ describe('ComponentV1alpha1Validator', () => {
subcomponentOf: 'monolith',
providesApis: ['api-0'],
consumesApis: ['api-0'],
+ system: 'system',
},
};
});
@@ -158,4 +159,19 @@ describe('ComponentV1alpha1Validator', () => {
(entity as any).spec.consumesApis = [];
await expect(validator.check(entity)).resolves.toBe(true);
});
+
+ it('accepts missing system', async () => {
+ delete (entity as any).spec.system;
+ await expect(validator.check(entity)).resolves.toBe(true);
+ });
+
+ it('rejects wrong system', async () => {
+ (entity as any).spec.system = 7;
+ await expect(validator.check(entity)).rejects.toThrow(/system/);
+ });
+
+ it('rejects empty system', async () => {
+ (entity as any).spec.system = '';
+ await expect(validator.check(entity)).rejects.toThrow(/system/);
+ });
});
diff --git a/packages/catalog-model/src/kinds/ComponentEntityV1alpha1.ts b/packages/catalog-model/src/kinds/ComponentEntityV1alpha1.ts
index 97519ad403..c55c48055a 100644
--- a/packages/catalog-model/src/kinds/ComponentEntityV1alpha1.ts
+++ b/packages/catalog-model/src/kinds/ComponentEntityV1alpha1.ts
@@ -32,6 +32,7 @@ const schema = yup.object>({
subcomponentOf: yup.string().notRequired().min(1),
providesApis: yup.array(yup.string().required()).notRequired(),
consumesApis: yup.array(yup.string().required()).notRequired(),
+ system: yup.string().notRequired().min(1),
})
.required(),
});
@@ -46,6 +47,7 @@ export interface ComponentEntityV1alpha1 extends Entity {
subcomponentOf?: string;
providesApis?: string[];
consumesApis?: string[];
+ system?: string;
};
}
diff --git a/packages/catalog-model/src/kinds/DomainEntityV1alpha1.test.ts b/packages/catalog-model/src/kinds/DomainEntityV1alpha1.test.ts
new file mode 100644
index 0000000000..0e989f22ca
--- /dev/null
+++ b/packages/catalog-model/src/kinds/DomainEntityV1alpha1.test.ts
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2020 Spotify AB
+ *
+ * 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 {
+ DomainEntityV1alpha1,
+ domainEntityV1alpha1Validator as validator,
+} from './DomainEntityV1alpha1';
+
+describe('DomainV1alpha1Validator', () => {
+ let entity: DomainEntityV1alpha1;
+
+ beforeEach(() => {
+ entity = {
+ apiVersion: 'backstage.io/v1alpha1',
+ kind: 'Domain',
+ metadata: {
+ name: 'test',
+ },
+ spec: {
+ owner: 'me',
+ },
+ };
+ });
+
+ it('happy path: accepts valid data', async () => {
+ await expect(validator.check(entity)).resolves.toBe(true);
+ });
+
+ it('silently accepts v1beta1 as well', async () => {
+ (entity as any).apiVersion = 'backstage.io/v1beta1';
+ await expect(validator.check(entity)).resolves.toBe(true);
+ });
+
+ it('ignores unknown apiVersion', async () => {
+ (entity as any).apiVersion = 'backstage.io/v1beta0';
+ await expect(validator.check(entity)).resolves.toBe(false);
+ });
+
+ it('ignores unknown kind', async () => {
+ (entity as any).kind = 'Wizard';
+ await expect(validator.check(entity)).resolves.toBe(false);
+ });
+
+ it('rejects missing owner', async () => {
+ delete (entity as any).spec.owner;
+ await expect(validator.check(entity)).rejects.toThrow(/owner/);
+ });
+
+ it('rejects wrong owner', async () => {
+ (entity as any).spec.owner = 7;
+ await expect(validator.check(entity)).rejects.toThrow(/owner/);
+ });
+
+ it('rejects empty owner', async () => {
+ (entity as any).spec.owner = '';
+ await expect(validator.check(entity)).rejects.toThrow(/owner/);
+ });
+});
diff --git a/packages/catalog-model/src/kinds/DomainEntityV1alpha1.ts b/packages/catalog-model/src/kinds/DomainEntityV1alpha1.ts
new file mode 100644
index 0000000000..60b11aa124
--- /dev/null
+++ b/packages/catalog-model/src/kinds/DomainEntityV1alpha1.ts
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2020 Spotify AB
+ *
+ * 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 * as yup from 'yup';
+import type { Entity } from '../entity/Entity';
+import { schemaValidator } from './util';
+
+const API_VERSION = ['backstage.io/v1alpha1', 'backstage.io/v1beta1'] as const;
+const KIND = 'Domain' as const;
+
+const schema = yup.object>({
+ apiVersion: yup.string().required().oneOf(API_VERSION),
+ kind: yup.string().required().equals([KIND]),
+ spec: yup
+ .object({
+ owner: yup.string().required().min(1),
+ })
+ .required(),
+});
+
+export interface DomainEntityV1alpha1 extends Entity {
+ apiVersion: typeof API_VERSION[number];
+ kind: typeof KIND;
+ spec: {
+ owner: string;
+ };
+}
+
+export const domainEntityV1alpha1Validator = schemaValidator(
+ KIND,
+ API_VERSION,
+ schema,
+);
diff --git a/packages/catalog-model/src/kinds/ResourceEntityV1alpha1.test.ts b/packages/catalog-model/src/kinds/ResourceEntityV1alpha1.test.ts
new file mode 100644
index 0000000000..ad8ea5cdf3
--- /dev/null
+++ b/packages/catalog-model/src/kinds/ResourceEntityV1alpha1.test.ts
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2020 Spotify AB
+ *
+ * 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 {
+ ResourceEntityV1alpha1,
+ resourceEntityV1alpha1Validator as validator,
+} from './ResourceEntityV1alpha1';
+
+describe('ResourceV1alpha1Validator', () => {
+ let entity: ResourceEntityV1alpha1;
+
+ beforeEach(() => {
+ entity = {
+ apiVersion: 'backstage.io/v1alpha1',
+ kind: 'Resource',
+ metadata: {
+ name: 'test',
+ },
+ spec: {
+ type: 'database',
+ owner: 'me',
+ system: 'system',
+ },
+ };
+ });
+
+ it('happy path: accepts valid data', async () => {
+ await expect(validator.check(entity)).resolves.toBe(true);
+ });
+
+ it('silently accepts v1beta1 as well', async () => {
+ (entity as any).apiVersion = 'backstage.io/v1beta1';
+ await expect(validator.check(entity)).resolves.toBe(true);
+ });
+
+ it('ignores unknown apiVersion', async () => {
+ (entity as any).apiVersion = 'backstage.io/v1beta0';
+ await expect(validator.check(entity)).resolves.toBe(false);
+ });
+
+ it('ignores unknown kind', async () => {
+ (entity as any).kind = 'Wizard';
+ await expect(validator.check(entity)).resolves.toBe(false);
+ });
+
+ it('rejects missing type', async () => {
+ delete (entity as any).spec.type;
+ await expect(validator.check(entity)).rejects.toThrow(/type/);
+ });
+
+ it('rejects wrong type', async () => {
+ (entity as any).spec.type = 7;
+ await expect(validator.check(entity)).rejects.toThrow(/type/);
+ });
+
+ it('rejects empty type', async () => {
+ (entity as any).spec.type = '';
+ await expect(validator.check(entity)).rejects.toThrow(/type/);
+ });
+
+ it('rejects missing owner', async () => {
+ delete (entity as any).spec.owner;
+ await expect(validator.check(entity)).rejects.toThrow(/owner/);
+ });
+
+ it('rejects wrong owner', async () => {
+ (entity as any).spec.owner = 7;
+ await expect(validator.check(entity)).rejects.toThrow(/owner/);
+ });
+
+ it('rejects empty owner', async () => {
+ (entity as any).spec.owner = '';
+ await expect(validator.check(entity)).rejects.toThrow(/owner/);
+ });
+
+ it('accepts missing system', async () => {
+ delete (entity as any).spec.system;
+ await expect(validator.check(entity)).resolves.toBe(true);
+ });
+
+ it('rejects wrong system', async () => {
+ (entity as any).spec.system = 7;
+ await expect(validator.check(entity)).rejects.toThrow(/system/);
+ });
+
+ it('rejects empty system', async () => {
+ (entity as any).spec.system = '';
+ await expect(validator.check(entity)).rejects.toThrow(/system/);
+ });
+});
diff --git a/packages/catalog-model/src/kinds/ResourceEntityV1alpha1.ts b/packages/catalog-model/src/kinds/ResourceEntityV1alpha1.ts
new file mode 100644
index 0000000000..12df7f6664
--- /dev/null
+++ b/packages/catalog-model/src/kinds/ResourceEntityV1alpha1.ts
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2020 Spotify AB
+ *
+ * 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 * as yup from 'yup';
+import type { Entity } from '../entity/Entity';
+import { schemaValidator } from './util';
+
+const API_VERSION = ['backstage.io/v1alpha1', 'backstage.io/v1beta1'] as const;
+const KIND = 'Resource' as const;
+
+const schema = yup.object>({
+ apiVersion: yup.string().required().oneOf(API_VERSION),
+ kind: yup.string().required().equals([KIND]),
+ spec: yup
+ .object({
+ type: yup.string().required().min(1),
+ owner: yup.string().required().min(1),
+ system: yup.string().notRequired().min(1),
+ })
+ .required(),
+});
+
+export interface ResourceEntityV1alpha1 extends Entity {
+ apiVersion: typeof API_VERSION[number];
+ kind: typeof KIND;
+ spec: {
+ type: string;
+ owner: string;
+ system?: string;
+ };
+}
+
+export const resourceEntityV1alpha1Validator = schemaValidator(
+ KIND,
+ API_VERSION,
+ schema,
+);
diff --git a/packages/catalog-model/src/kinds/SystemEntityV1alpha1.test.ts b/packages/catalog-model/src/kinds/SystemEntityV1alpha1.test.ts
new file mode 100644
index 0000000000..7d744b7d0d
--- /dev/null
+++ b/packages/catalog-model/src/kinds/SystemEntityV1alpha1.test.ts
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2020 Spotify AB
+ *
+ * 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 {
+ SystemEntityV1alpha1,
+ systemEntityV1alpha1Validator as validator,
+} from './SystemEntityV1alpha1';
+
+describe('SystemV1alpha1Validator', () => {
+ let entity: SystemEntityV1alpha1;
+
+ beforeEach(() => {
+ entity = {
+ apiVersion: 'backstage.io/v1alpha1',
+ kind: 'System',
+ metadata: {
+ name: 'test',
+ },
+ spec: {
+ owner: 'me',
+ domain: 'domain',
+ },
+ };
+ });
+
+ it('happy path: accepts valid data', async () => {
+ await expect(validator.check(entity)).resolves.toBe(true);
+ });
+
+ it('silently accepts v1beta1 as well', async () => {
+ (entity as any).apiVersion = 'backstage.io/v1beta1';
+ await expect(validator.check(entity)).resolves.toBe(true);
+ });
+
+ it('ignores unknown apiVersion', async () => {
+ (entity as any).apiVersion = 'backstage.io/v1beta0';
+ await expect(validator.check(entity)).resolves.toBe(false);
+ });
+
+ it('ignores unknown kind', async () => {
+ (entity as any).kind = 'Wizard';
+ await expect(validator.check(entity)).resolves.toBe(false);
+ });
+
+ it('rejects missing owner', async () => {
+ delete (entity as any).spec.owner;
+ await expect(validator.check(entity)).rejects.toThrow(/owner/);
+ });
+
+ it('rejects wrong owner', async () => {
+ (entity as any).spec.owner = 7;
+ await expect(validator.check(entity)).rejects.toThrow(/owner/);
+ });
+
+ it('rejects empty owner', async () => {
+ (entity as any).spec.owner = '';
+ await expect(validator.check(entity)).rejects.toThrow(/owner/);
+ });
+
+ it('accepts missing domain', async () => {
+ delete (entity as any).spec.domain;
+ await expect(validator.check(entity)).resolves.toBe(true);
+ });
+
+ it('rejects wrong domain', async () => {
+ (entity as any).spec.domain = 7;
+ await expect(validator.check(entity)).rejects.toThrow(/domain/);
+ });
+
+ it('rejects empty domain', async () => {
+ (entity as any).spec.domain = '';
+ await expect(validator.check(entity)).rejects.toThrow(/domain/);
+ });
+});
diff --git a/packages/catalog-model/src/kinds/SystemEntityV1alpha1.ts b/packages/catalog-model/src/kinds/SystemEntityV1alpha1.ts
new file mode 100644
index 0000000000..764514efdd
--- /dev/null
+++ b/packages/catalog-model/src/kinds/SystemEntityV1alpha1.ts
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2020 Spotify AB
+ *
+ * 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 * as yup from 'yup';
+import type { Entity } from '../entity/Entity';
+import { schemaValidator } from './util';
+
+const API_VERSION = ['backstage.io/v1alpha1', 'backstage.io/v1beta1'] as const;
+const KIND = 'System' as const;
+
+const schema = yup.object>({
+ apiVersion: yup.string().required().oneOf(API_VERSION),
+ kind: yup.string().required().equals([KIND]),
+ spec: yup
+ .object({
+ owner: yup.string().required().min(1),
+ domain: yup.string().notRequired().min(1),
+ })
+ .required(),
+});
+
+export interface SystemEntityV1alpha1 extends Entity {
+ apiVersion: typeof API_VERSION[number];
+ kind: typeof KIND;
+ spec: {
+ owner: string;
+ domain?: string;
+ };
+}
+
+export const systemEntityV1alpha1Validator = schemaValidator(
+ KIND,
+ API_VERSION,
+ schema,
+);
diff --git a/packages/catalog-model/src/kinds/index.ts b/packages/catalog-model/src/kinds/index.ts
index e00a49acb5..bc157c79df 100644
--- a/packages/catalog-model/src/kinds/index.ts
+++ b/packages/catalog-model/src/kinds/index.ts
@@ -26,6 +26,11 @@ export type {
ComponentEntityV1alpha1 as ComponentEntity,
ComponentEntityV1alpha1,
} from './ComponentEntityV1alpha1';
+export { domainEntityV1alpha1Validator } from './DomainEntityV1alpha1';
+export type {
+ DomainEntityV1alpha1 as DomainEntity,
+ DomainEntityV1alpha1,
+} from './DomainEntityV1alpha1';
export { groupEntityV1alpha1Validator } from './GroupEntityV1alpha1';
export type {
GroupEntityV1alpha1 as GroupEntity,
@@ -37,6 +42,16 @@ export type {
LocationEntityV1alpha1,
} from './LocationEntityV1alpha1';
export * from './relations';
+export { resourceEntityV1alpha1Validator } from './ResourceEntityV1alpha1';
+export type {
+ ResourceEntityV1alpha1 as ResourceEntity,
+ ResourceEntityV1alpha1,
+} from './ResourceEntityV1alpha1';
+export { systemEntityV1alpha1Validator } from './SystemEntityV1alpha1';
+export type {
+ SystemEntityV1alpha1 as SystemEntity,
+ SystemEntityV1alpha1,
+} from './SystemEntityV1alpha1';
export { templateEntityV1alpha1Validator } from './TemplateEntityV1alpha1';
export type {
TemplateEntityV1alpha1 as TemplateEntity,
diff --git a/packages/catalog-model/src/kinds/relations.ts b/packages/catalog-model/src/kinds/relations.ts
index 78bbc61df2..ed40a7e9c6 100644
--- a/packages/catalog-model/src/kinds/relations.ts
+++ b/packages/catalog-model/src/kinds/relations.ts
@@ -30,7 +30,7 @@ export const RELATION_OWNED_BY = 'ownedBy';
export const RELATION_OWNER_OF = 'ownerOf';
/**
- * A relation with an API entity, typically from a component or system
+ * A relation with an API entity, typically from a component
*/
export const RELATION_CONSUMES_API = 'consumesApi';
export const RELATION_API_CONSUMED_BY = 'apiConsumedBy';
@@ -57,8 +57,13 @@ export const RELATION_MEMBER_OF = 'memberOf';
export const RELATION_HAS_MEMBER = 'hasMember';
/**
+<<<<<<< HEAD
* A part/whole relation, typically for components in a system and systems
* in a domain.
+=======
+ * A grouping relation, typically for components, resources or APIs in a
+ * system, or for systems inside a domain.
+>>>>>>> Add system, domain and resource entity kinds
*/
export const RELATION_PART_OF = 'partOf';
export const RELATION_HAS_PART = 'hasPart';
diff --git a/plugins/catalog-backend/src/ingestion/processors/BuiltinKindsEntityProcessor.test.ts b/plugins/catalog-backend/src/ingestion/processors/BuiltinKindsEntityProcessor.test.ts
index 1d2562c25b..feb4791477 100644
--- a/plugins/catalog-backend/src/ingestion/processors/BuiltinKindsEntityProcessor.test.ts
+++ b/plugins/catalog-backend/src/ingestion/processors/BuiltinKindsEntityProcessor.test.ts
@@ -17,7 +17,10 @@
import {
ApiEntity,
ComponentEntity,
+ DomainEntity,
GroupEntity,
+ ResourceEntity,
+ SystemEntity,
UserEntity,
} from '@backstage/catalog-model';
import { BuiltinKindsEntityProcessor } from './BuiltinKindsEntityProcessor';
@@ -42,12 +45,13 @@ describe('BuiltinKindsEntityProcessor', () => {
lifecycle: 'l',
providesApis: ['b'],
consumesApis: ['c'],
+ system: 's',
},
};
await processor.postProcessEntity(entity, location, emit);
- expect(emit).toBeCalledTimes(8);
+ expect(emit).toBeCalledTimes(10);
expect(emit).toBeCalledWith({
type: 'relation',
relation: {
@@ -112,6 +116,22 @@ describe('BuiltinKindsEntityProcessor', () => {
target: { kind: 'Component', namespace: 'default', name: 's' },
},
});
+ expect(emit).toBeCalledWith({
+ type: 'relation',
+ relation: {
+ source: { kind: 'System', namespace: 'default', name: 's' },
+ type: 'hasPart',
+ target: { kind: 'Component', namespace: 'default', name: 'n' },
+ },
+ });
+ expect(emit).toBeCalledWith({
+ type: 'relation',
+ relation: {
+ source: { kind: 'Component', namespace: 'default', name: 'n' },
+ type: 'partOf',
+ target: { kind: 'System', namespace: 'default', name: 's' },
+ },
+ });
});
it('generates relations for api entities', async () => {
@@ -124,12 +144,13 @@ describe('BuiltinKindsEntityProcessor', () => {
owner: 'o',
lifecycle: 'l',
definition: 'd',
+ system: 's',
},
};
await processor.postProcessEntity(entity, location, emit);
- expect(emit).toBeCalledTimes(2);
+ expect(emit).toBeCalledTimes(4);
expect(emit).toBeCalledWith({
type: 'relation',
relation: {
@@ -146,6 +167,150 @@ describe('BuiltinKindsEntityProcessor', () => {
target: { kind: 'Group', namespace: 'default', name: 'o' },
},
});
+ expect(emit).toBeCalledWith({
+ type: 'relation',
+ relation: {
+ source: { kind: 'System', namespace: 'default', name: 's' },
+ type: 'hasPart',
+ target: { kind: 'API', namespace: 'default', name: 'n' },
+ },
+ });
+ expect(emit).toBeCalledWith({
+ type: 'relation',
+ relation: {
+ source: { kind: 'API', namespace: 'default', name: 'n' },
+ type: 'partOf',
+ target: { kind: 'System', namespace: 'default', name: 's' },
+ },
+ });
+ });
+
+ it('generates relations for resource entities', async () => {
+ const entity: ResourceEntity = {
+ apiVersion: 'backstage.io/v1alpha1',
+ kind: 'Resource',
+ metadata: { name: 'n' },
+ spec: {
+ type: 'database',
+ owner: 'o',
+ system: 's',
+ },
+ };
+
+ await processor.postProcessEntity(entity, location, emit);
+
+ expect(emit).toBeCalledTimes(4);
+ expect(emit).toBeCalledWith({
+ type: 'relation',
+ relation: {
+ source: { kind: 'Group', namespace: 'default', name: 'o' },
+ type: 'ownerOf',
+ target: { kind: 'Resource', namespace: 'default', name: 'n' },
+ },
+ });
+ expect(emit).toBeCalledWith({
+ type: 'relation',
+ relation: {
+ source: { kind: 'Resource', namespace: 'default', name: 'n' },
+ type: 'ownedBy',
+ target: { kind: 'Group', namespace: 'default', name: 'o' },
+ },
+ });
+ expect(emit).toBeCalledWith({
+ type: 'relation',
+ relation: {
+ source: { kind: 'System', namespace: 'default', name: 's' },
+ type: 'hasPart',
+ target: { kind: 'Resource', namespace: 'default', name: 'n' },
+ },
+ });
+ expect(emit).toBeCalledWith({
+ type: 'relation',
+ relation: {
+ source: { kind: 'Resource', namespace: 'default', name: 'n' },
+ type: 'partOf',
+ target: { kind: 'System', namespace: 'default', name: 's' },
+ },
+ });
+ });
+
+ it('generates relations for system entities', async () => {
+ const entity: SystemEntity = {
+ apiVersion: 'backstage.io/v1alpha1',
+ kind: 'System',
+ metadata: { name: 'n' },
+ spec: {
+ owner: 'o',
+ domain: 'd',
+ },
+ };
+
+ await processor.postProcessEntity(entity, location, emit);
+
+ expect(emit).toBeCalledTimes(4);
+ expect(emit).toBeCalledWith({
+ type: 'relation',
+ relation: {
+ source: { kind: 'Group', namespace: 'default', name: 'o' },
+ type: 'ownerOf',
+ target: { kind: 'System', namespace: 'default', name: 'n' },
+ },
+ });
+ expect(emit).toBeCalledWith({
+ type: 'relation',
+ relation: {
+ source: { kind: 'System', namespace: 'default', name: 'n' },
+ type: 'ownedBy',
+ target: { kind: 'Group', namespace: 'default', name: 'o' },
+ },
+ });
+ expect(emit).toBeCalledWith({
+ type: 'relation',
+ relation: {
+ source: { kind: 'Domain', namespace: 'default', name: 'd' },
+ type: 'hasPart',
+ target: { kind: 'System', namespace: 'default', name: 'n' },
+ },
+ });
+ expect(emit).toBeCalledWith({
+ type: 'relation',
+ relation: {
+ source: { kind: 'System', namespace: 'default', name: 'n' },
+ type: 'partOf',
+ target: { kind: 'Domain', namespace: 'default', name: 'd' },
+ },
+ });
+ });
+
+ it('generates relations for domain entities', async () => {
+ const entity: DomainEntity = {
+ apiVersion: 'backstage.io/v1alpha1',
+ kind: 'Domain',
+ metadata: { name: 'n' },
+ spec: {
+ owner: 'o',
+ },
+ };
+
+ await processor.postProcessEntity(entity, location, emit);
+
+ expect(emit).toBeCalledTimes(2);
+ expect(emit).toBeCalledWith({
+ type: 'relation',
+ relation: {
+ source: { kind: 'Group', namespace: 'default', name: 'o' },
+ type: 'ownerOf',
+ target: { kind: 'Domain', namespace: 'default', name: 'n' },
+ },
+ });
+ expect(emit).toBeCalledWith({
+ type: 'relation',
+ relation: {
+ source: { kind: 'Domain', namespace: 'default', name: 'n' },
+ type: 'ownedBy',
+ target: { kind: 'Group', namespace: 'default', name: 'o' },
+ },
+ });
});
it('generates relations for user entities', async () => {
diff --git a/plugins/catalog-backend/src/ingestion/processors/BuiltinKindsEntityProcessor.ts b/plugins/catalog-backend/src/ingestion/processors/BuiltinKindsEntityProcessor.ts
index 67e89ac52c..c75a46874d 100644
--- a/plugins/catalog-backend/src/ingestion/processors/BuiltinKindsEntityProcessor.ts
+++ b/plugins/catalog-backend/src/ingestion/processors/BuiltinKindsEntityProcessor.ts
@@ -19,6 +19,8 @@ import {
apiEntityV1alpha1Validator,
ComponentEntity,
componentEntityV1alpha1Validator,
+ DomainEntity,
+ domainEntityV1alpha1Validator,
Entity,
getEntityName,
GroupEntity,
@@ -31,13 +33,17 @@ import {
RELATION_CHILD_OF,
RELATION_CONSUMES_API,
RELATION_HAS_MEMBER,
- RELATION_MEMBER_OF,
RELATION_HAS_PART,
- RELATION_PART_OF,
+ RELATION_MEMBER_OF,
RELATION_OWNED_BY,
RELATION_OWNER_OF,
RELATION_PARENT_OF,
+ RELATION_PART_OF,
RELATION_PROVIDES_API,
+ ResourceEntity,
+ resourceEntityV1alpha1Validator,
+ SystemEntity,
+ systemEntityV1alpha1Validator,
templateEntityV1alpha1Validator,
UserEntity,
userEntityV1alpha1Validator,
@@ -49,10 +55,13 @@ export class BuiltinKindsEntityProcessor implements CatalogProcessor {
private readonly validators = [
apiEntityV1alpha1Validator,
componentEntityV1alpha1Validator,
+ resourceEntityV1alpha1Validator,
groupEntityV1alpha1Validator,
locationEntityV1alpha1Validator,
templateEntityV1alpha1Validator,
userEntityV1alpha1Validator,
+ systemEntityV1alpha1Validator,
+ domainEntityV1alpha1Validator,
];
async validateEntityKind(entity: Entity): Promise {
@@ -135,6 +144,12 @@ export class BuiltinKindsEntityProcessor implements CatalogProcessor {
RELATION_CONSUMES_API,
RELATION_API_CONSUMED_BY,
);
+ doEmit(
+ component.spec.system,
+ { defaultKind: 'System', defaultNamespace: selfRef.namespace },
+ RELATION_PART_OF,
+ RELATION_HAS_PART,
+ );
}
/*
@@ -149,6 +164,32 @@ export class BuiltinKindsEntityProcessor implements CatalogProcessor {
RELATION_OWNED_BY,
RELATION_OWNER_OF,
);
+ doEmit(
+ api.spec.system,
+ { defaultKind: 'System', defaultNamespace: selfRef.namespace },
+ RELATION_PART_OF,
+ RELATION_HAS_PART,
+ );
+ }
+
+ /*
+ * Emit relations for the Resource kind
+ */
+
+ if (entity.kind === 'Resource') {
+ const resource = entity as ResourceEntity;
+ doEmit(
+ resource.spec.owner,
+ { defaultKind: 'Group', defaultNamespace: selfRef.namespace },
+ RELATION_OWNED_BY,
+ RELATION_OWNER_OF,
+ );
+ doEmit(
+ resource.spec.system,
+ { defaultKind: 'System', defaultNamespace: selfRef.namespace },
+ RELATION_PART_OF,
+ RELATION_HAS_PART,
+ );
}
/*
@@ -185,6 +226,40 @@ export class BuiltinKindsEntityProcessor implements CatalogProcessor {
);
}
+ /*
+ * Emit relations for the System kind
+ */
+
+ if (entity.kind === 'System') {
+ const system = entity as SystemEntity;
+ doEmit(
+ system.spec.owner,
+ { defaultKind: 'Group', defaultNamespace: selfRef.namespace },
+ RELATION_OWNED_BY,
+ RELATION_OWNER_OF,
+ );
+ doEmit(
+ system.spec.domain,
+ { defaultKind: 'Domain', defaultNamespace: selfRef.namespace },
+ RELATION_PART_OF,
+ RELATION_HAS_PART,
+ );
+ }
+
+ /*
+ * Emit relations for the Domain kind
+ */
+
+ if (entity.kind === 'Domain') {
+ const domain = entity as DomainEntity;
+ doEmit(
+ domain.spec.owner,
+ { defaultKind: 'Group', defaultNamespace: selfRef.namespace },
+ RELATION_OWNED_BY,
+ RELATION_OWNER_OF,
+ );
+ }
+
return entity;
}
}
From 6dee39ebe285f4f4013fbafad683c5da0a57b68d Mon Sep 17 00:00:00 2001
From: Jussi Hallila
Date: Wed, 13 Jan 2021 09:16:58 +0100
Subject: [PATCH 025/144] Fix spelling.
---
docs/tutorials/quickstart-app-auth.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/tutorials/quickstart-app-auth.md b/docs/tutorials/quickstart-app-auth.md
index 205fcddb65..14ed856c96 100644
--- a/docs/tutorials/quickstart-app-auth.md
+++ b/docs/tutorials/quickstart-app-auth.md
@@ -103,7 +103,7 @@ auth:
-GitLab
+Gitlab
### 1. Open `app-config.yaml` and change it as follows
From e921fb2ec7428029748ad4d5a109a32ebde437ea Mon Sep 17 00:00:00 2001
From: Jussi Hallila
Date: Wed, 13 Jan 2021 09:25:25 +0100
Subject: [PATCH 026/144] Fix GitHub stylization
---
docs/tutorials/quickstart-app-auth.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/docs/tutorials/quickstart-app-auth.md b/docs/tutorials/quickstart-app-auth.md
index 14ed856c96..4218940ef7 100644
--- a/docs/tutorials/quickstart-app-auth.md
+++ b/docs/tutorials/quickstart-app-auth.md
@@ -60,7 +60,7 @@ external authentication provider. Please see a subset of possible providers and
instructions to integrate them below. Steps 1 & 2 are described separately for
each provider and steps beyond that are common for all.
-Github
+GitHub
### 1. Open `app-config.yaml` and change it as follows
@@ -334,7 +334,7 @@ above:
| Auth Provider | Import Name |
| ------------- | ------------------- |
-| Github | githubAuthApiRef |
+| GitHub | githubAuthApiRef |
| Gitlab | gitlabAuthApiRef |
| Google | googleAuthApiRef |
| Microsoft | microsoftAuthApiRef |
From 37e4bf3473a1f399f572eb7bdcb636f57204ebd8 Mon Sep 17 00:00:00 2001
From: Jussi Hallila
Date: Wed, 13 Jan 2021 10:12:40 +0100
Subject: [PATCH 027/144] Modifying GitLab text to be stylized
---
docs/tutorials/quickstart-app-auth.md | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/docs/tutorials/quickstart-app-auth.md b/docs/tutorials/quickstart-app-auth.md
index 4218940ef7..1c661d274c 100644
--- a/docs/tutorials/quickstart-app-auth.md
+++ b/docs/tutorials/quickstart-app-auth.md
@@ -93,8 +93,8 @@ auth:
- Log into http://github.com
- Navigate to (Settings > Developer Settings > OAuth Apps > New OAuth
App)[https://github.com/settings/applications/new]
-- Set Homepage URL = http://localhost:3000
-- Set Callback URL = http://localhost:7000/api/auth/github
+- Set Homepage URL = `http://localhost:3000`
+- Set Callback URL = `http://localhost:7000/api/auth/github`
- Click [Register application]
- On the next page, copy and paste your new Client ID and Client Secret to
environment variables defined in the `app-config.yaml` file,
@@ -103,7 +103,7 @@ auth:
-Gitlab
+GitLab
### 1. Open `app-config.yaml` and change it as follows
@@ -126,16 +126,16 @@ auth:
$env: AUTH_GITLAB_CLIENT_ID
clientSecret:
$env: AUTH_GITLAB_CLIENT_SECRET
- audience: https://gitlab.com # Or your self-hosted Gitlab instance URL
+ audience: https://gitlab.com # Or your self-hosted GitLab instance URL
```
-### 2. Generate a Gitlab Application client ID and secret
+### 2. Generate a GitLab Application client ID and secret
- Log into GitLab
- Navigate to (Profile > Settings >
Applications)[https://gitlab.com/-/profile/applications]
- Name your application
-- Set Callback URL = http://localhost:7000/api/auth/gitlab/handler/frame
+- Set Callback URL = `http://localhost:7000/api/auth/gitlab/handler/frame`
- Select the following values:
- `read_user` (Read the authenticated user's personal information)
- `read_repository` (Allows read-only access to the repository)
@@ -335,7 +335,7 @@ above:
| Auth Provider | Import Name |
| ------------- | ------------------- |
| GitHub | githubAuthApiRef |
-| Gitlab | gitlabAuthApiRef |
+| GitLab | gitlabAuthApiRef |
| Google | googleAuthApiRef |
| Microsoft | microsoftAuthApiRef |
| Auth0 | auth0AuthApiRef |
From 371f67ecd0473fee596d5832fc8931371c5e164e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?=
Date: Wed, 13 Jan 2021 10:37:02 +0100
Subject: [PATCH 028/144] techdocs-common: fix to-string breakage of binary
files
---
.changeset/funny-snails-cry.md | 5 +++++
packages/techdocs-common/src/stages/publish/awsS3.ts | 10 +++++-----
2 files changed, 10 insertions(+), 5 deletions(-)
create mode 100644 .changeset/funny-snails-cry.md
diff --git a/.changeset/funny-snails-cry.md b/.changeset/funny-snails-cry.md
new file mode 100644
index 0000000000..161a386a8c
--- /dev/null
+++ b/.changeset/funny-snails-cry.md
@@ -0,0 +1,5 @@
+---
+'@backstage/techdocs-common': patch
+---
+
+fix to-string breakage of binary files
diff --git a/packages/techdocs-common/src/stages/publish/awsS3.ts b/packages/techdocs-common/src/stages/publish/awsS3.ts
index 7a21ae6475..3f7a0e3d81 100644
--- a/packages/techdocs-common/src/stages/publish/awsS3.ts
+++ b/packages/techdocs-common/src/stages/publish/awsS3.ts
@@ -24,13 +24,13 @@ import { PublisherBase, PublishRequest } from './types';
import fs from 'fs-extra';
import { Readable } from 'stream';
-const streamToString = (stream: Readable): Promise => {
+const streamToBuffer = (stream: Readable): Promise => {
return new Promise((resolve, reject) => {
try {
const chunks: any[] = [];
stream.on('data', chunk => chunks.push(chunk));
stream.on('error', reject);
- stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
+ stream.on('end', () => resolve(Buffer.concat(chunks)));
} catch (e) {
throw new Error(`Unable to parse the response data, ${e.message}`);
}
@@ -173,7 +173,7 @@ export class AwsS3Publish implements PublisherBase {
Key: `${entityRootDir}/techdocs_metadata.json`,
})
.then(async file => {
- const techdocsMetadataJson = await streamToString(
+ const techdocsMetadataJson = await streamToBuffer(
file.Body as Readable,
);
@@ -183,7 +183,7 @@ export class AwsS3Publish implements PublisherBase {
);
}
- resolve(techdocsMetadataJson);
+ resolve(techdocsMetadataJson.toString('utf-8'));
})
.catch(err => {
this.logger.error(err.message);
@@ -211,7 +211,7 @@ export class AwsS3Publish implements PublisherBase {
this.storageClient
.getObject({ Bucket: this.bucketName, Key: filePath })
.then(async object => {
- const fileContent = await streamToString(object.Body as Readable);
+ const fileContent = await streamToBuffer(object.Body as Readable);
if (!fileContent) {
throw new Error(`Unable to parse the file ${filePath}.`);
}
From 9560a1a4ab42a329124bf3daccf43e4e431dd5a0 Mon Sep 17 00:00:00 2001
From: Himanshu Mishra
Date: Wed, 13 Jan 2021 15:24:22 +0100
Subject: [PATCH 029/144] chore: Move Dockerfile at root to contrib/
In deployment docs https://backstage.io/docs/getting-started/deployment-other, we suggest doing a `yarn docker-build` and I thought the root Dockerfile was being used to build the image. Hence I modified it for some needs, but no changes were reflected. Later I found that `yarn docker-build` uses the `Dockerfile` present inside `packages/backend` https://github.com/backstage/backstage/blob/master/packages/backend/Dockerfile. So, I think the Dockerfile at the root is a bit misleading, and should be moved to contrib.
Signed-off-by: Himanshu Mishra
---
Dockerfile => contrib/docker/frontend-with-nginx/Dockerfile | 0
.../docker/frontend-with-nginx/docker}/default.conf.template | 0
{docker => contrib/docker/frontend-with-nginx/docker}/run.sh | 0
3 files changed, 0 insertions(+), 0 deletions(-)
rename Dockerfile => contrib/docker/frontend-with-nginx/Dockerfile (100%)
rename {docker => contrib/docker/frontend-with-nginx/docker}/default.conf.template (100%)
rename {docker => contrib/docker/frontend-with-nginx/docker}/run.sh (100%)
diff --git a/Dockerfile b/contrib/docker/frontend-with-nginx/Dockerfile
similarity index 100%
rename from Dockerfile
rename to contrib/docker/frontend-with-nginx/Dockerfile
diff --git a/docker/default.conf.template b/contrib/docker/frontend-with-nginx/docker/default.conf.template
similarity index 100%
rename from docker/default.conf.template
rename to contrib/docker/frontend-with-nginx/docker/default.conf.template
diff --git a/docker/run.sh b/contrib/docker/frontend-with-nginx/docker/run.sh
similarity index 100%
rename from docker/run.sh
rename to contrib/docker/frontend-with-nginx/docker/run.sh
From 71fb4e1281b57754ed8cb9765bba2018678d98a4 Mon Sep 17 00:00:00 2001
From: Johan Haals
Date: Wed, 13 Jan 2021 16:58:11 +0100
Subject: [PATCH 030/144] cli: Remove api url from github app configuration
---
.../src/commands/create-github-app/GithubCreateAppServer.ts | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/packages/cli/src/commands/create-github-app/GithubCreateAppServer.ts b/packages/cli/src/commands/create-github-app/GithubCreateAppServer.ts
index 406e563ebc..45671c2ead 100644
--- a/packages/cli/src/commands/create-github-app/GithubCreateAppServer.ts
+++ b/packages/cli/src/commands/create-github-app/GithubCreateAppServer.ts
@@ -47,7 +47,6 @@ const FORM_PAGE = `
type GithubAppConfig = {
appId: number;
- apiUrl: string;
slug?: string;
name?: string;
webhookUrl?: string;
@@ -88,14 +87,11 @@ export class GithubCreateAppServer {
`POST /app-manifests/${encodeURIComponent(
req.query.code as string,
)}/conversions`,
- ).then(({ data, url }) => {
- // url = https://api.github.com/app-manifests//conversions
- const apiUrl = url.replace(/(?:\/[^\/]+){3}$/, '');
+ ).then(({ data }) => {
resolve({
name: data.name,
slug: data.slug,
appId: data.id,
- apiUrl,
webhookUrl: this.webhookUrl,
clientId: data.client_id,
clientSecret: data.client_secret,
From 8277fe6f77094d3254c268ec8e5c64c28221242c Mon Sep 17 00:00:00 2001
From: Johan Haals
Date: Wed, 13 Jan 2021 17:04:10 +0100
Subject: [PATCH 031/144] Add changeset
---
.changeset/real-vans-provide.md | 5 +++++
1 file changed, 5 insertions(+)
create mode 100644 .changeset/real-vans-provide.md
diff --git a/.changeset/real-vans-provide.md b/.changeset/real-vans-provide.md
new file mode 100644
index 0000000000..9d83804bd6
--- /dev/null
+++ b/.changeset/real-vans-provide.md
@@ -0,0 +1,5 @@
+---
+'@backstage/cli': patch
+---
+
+Remove `apiUrl` from the output of the create-github-app because apiUrl already exist in the GitHub integration config.
From 4f78ee3a69571d0fed625a5120f64ffb940ddbdf Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Wed, 13 Jan 2021 16:35:56 +0000
Subject: [PATCH 032/144] chore(deps): bump azure-devops-node-api from 10.1.1
to 10.2.1
Bumps [azure-devops-node-api](https://github.com/Microsoft/azure-devops-node-api) from 10.1.1 to 10.2.1.
- [Release notes](https://github.com/Microsoft/azure-devops-node-api/releases)
- [Commits](https://github.com/Microsoft/azure-devops-node-api/commits)
Signed-off-by: dependabot[bot]
---
yarn.lock | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/yarn.lock b/yarn.lock
index b10819d4f2..1981e1f886 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -8560,12 +8560,12 @@ axobject-query@^2.0.2:
integrity sha512-ICt34ZmrVt8UQnvPl6TVyDTkmhXmAyAT4Jh5ugfGUX4MOrZ+U/ZY6/sdylRw3qGNr9Ub5AJsaHeDMzNLehRdOQ==
azure-devops-node-api@^10.1.1:
- version "10.1.1"
- resolved "https://registry.npmjs.org/azure-devops-node-api/-/azure-devops-node-api-10.1.1.tgz#9016d8935316fff260f5f8fafd81d0caff90a19e"
- integrity sha512-P4Hyrh/+Nzc2KXQk73z72/GsenSWIH5o8uiyELqykJYs9TWTVCxVwghoR7lPeiY6QVoXkq2S2KtvAgi5fyjl9w==
+ version "10.2.1"
+ resolved "https://registry.npmjs.org/azure-devops-node-api/-/azure-devops-node-api-10.2.1.tgz#835080164f8c30cec6506c47198b044c053f1f36"
+ integrity sha512-XuSiUaYpk0tQpd9fD8qfRa5y1IdavupKNVmwxy0w/RhmxG2Wl8uAYnNJchUoWd3Rn9On0mYTCCZSn+UlYdYFSg==
dependencies:
tunnel "0.0.6"
- typed-rest-client "^1.7.3"
+ typed-rest-client "^1.8.0"
underscore "1.8.3"
babel-code-frame@^6.22.0:
@@ -24977,10 +24977,10 @@ type@^2.0.0:
resolved "https://registry.npmjs.org/type/-/type-2.0.0.tgz#5f16ff6ef2eb44f260494dae271033b29c09a9c3"
integrity sha512-KBt58xCHry4Cejnc2ISQAF7QY+ORngsWfxezO68+12hKV6lQY8P/psIkcbjeHWn7MqcgciWJyCCevFMJdIXpow==
-typed-rest-client@^1.7.3:
- version "1.7.3"
- resolved "https://registry.npmjs.org/typed-rest-client/-/typed-rest-client-1.7.3.tgz#1beb263b86b14d34596f6127c6172dd5fd652e7b"
- integrity sha512-CwTpx/TkRHGZoHkJhBcp4X8K3/WtlzSHVQR0OIFnt10j4tgy4ypgq/SrrgVpA1s6tAL49Q6J3R5C0Cgfh2ddqA==
+typed-rest-client@^1.8.0:
+ version "1.8.0"
+ resolved "https://registry.npmjs.org/typed-rest-client/-/typed-rest-client-1.8.0.tgz#3b6c22a7cc31b665ec1e4bedb3482ebe12e2fbe6"
+ integrity sha512-Nu1MrdH6ECrRW5gHoRAdubgCs4oH6q5/J76jsEC8bVDfvVoVPkigukPalhMHPwb7ZvpsZqPptd5zpt/QdtrdBw==
dependencies:
qs "^6.9.1"
tunnel "0.0.6"
From cb7af51e7367e57af5c555b49ceda8a92a490c72 Mon Sep 17 00:00:00 2001
From: Himanshu Mishra
Date: Wed, 13 Jan 2021 21:08:03 +0100
Subject: [PATCH 033/144] techdocs: cache docs site when built using urlReader
for 30 minutes
This caching makes it usable experience, so that docs are not built on every load.
In future readTree will support a method to fetch the timestamp of the latest HEAD. And
it should be used to invalidate the cache.
---
.changeset/techdocs-rotten-crabs-ring.md | 5 +++++
plugins/techdocs-backend/src/DocsBuilder/builder.ts | 12 ++++++++++++
2 files changed, 17 insertions(+)
create mode 100644 .changeset/techdocs-rotten-crabs-ring.md
diff --git a/.changeset/techdocs-rotten-crabs-ring.md b/.changeset/techdocs-rotten-crabs-ring.md
new file mode 100644
index 0000000000..7eddd8ba6c
--- /dev/null
+++ b/.changeset/techdocs-rotten-crabs-ring.md
@@ -0,0 +1,5 @@
+---
+'@backstage/plugin-techdocs-backend': patch
+---
+
+If using Url Reader, cache downloaded source files for 30 minutes.
diff --git a/plugins/techdocs-backend/src/DocsBuilder/builder.ts b/plugins/techdocs-backend/src/DocsBuilder/builder.ts
index 3d40f0a870..33d3120c47 100644
--- a/plugins/techdocs-backend/src/DocsBuilder/builder.ts
+++ b/plugins/techdocs-backend/src/DocsBuilder/builder.ts
@@ -144,6 +144,18 @@ export class DocsBuilder {
}
}
+ // Cache downloaded source files for 30 minutes.
+ // TODO: When urlReader/readTree supports some way to get latest commit timestamp,
+ // it should be used to invalidate cache.
+ if (type === 'url') {
+ const builtAt = buildMetadataStorage.getTimestamp();
+ const now = Date.now();
+
+ if (builtAt > now - 1800000) {
+ return true;
+ }
+ }
+
this.logger.debug(
`Docs for entity ${getEntityId(this.entity)} was outdated.`,
);
From dc33c518904549716a8af0cc5cc73fbe2f15388d Mon Sep 17 00:00:00 2001
From: Himanshu Mishra
Date: Wed, 13 Jan 2021 21:35:36 +0100
Subject: [PATCH 034/144] TechDocs: Use URL Reader in the out-of-the-box
experience
It is time to start using URL Reader for the exmaple docs components we provide in the out-of-the-box experience (i.e. when users experience TechDocs by doing a git clone of this repository).
URL Reader makes the prepare step 8x faster.
---
app-config.yaml | 4 ++--
catalog-info.yaml | 2 +-
.../{documented-component.yaml => catalog-info.yaml} | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
rename plugins/techdocs-backend/examples/documented-component/{documented-component.yaml => catalog-info.yaml} (61%)
diff --git a/app-config.yaml b/app-config.yaml
index d2100801ae..ac9cf700df 100644
--- a/app-config.yaml
+++ b/app-config.yaml
@@ -178,9 +178,9 @@ catalog:
# Example component for github-actions
- type: url
target: https://github.com/backstage/backstage/blob/master/plugins/github-actions/examples/sample.yaml
- # Example component for techdocs
+ # Example component for TechDocs
- type: url
- target: https://github.com/backstage/backstage/blob/master/plugins/techdocs-backend/examples/documented-component/documented-component.yaml
+ target: https://github.com/backstage/backstage/blob/master/plugins/techdocs-backend/examples/documented-component/catalog-info.yaml
# Backstage example APIs
- type: url
target: https://github.com/backstage/backstage/blob/master/packages/catalog-model/examples/all-apis.yaml
diff --git a/catalog-info.yaml b/catalog-info.yaml
index 617d01093e..2144d1709c 100644
--- a/catalog-info.yaml
+++ b/catalog-info.yaml
@@ -6,7 +6,7 @@ metadata:
Backstage is an open-source developer portal that puts the developer experience first.
annotations:
github.com/project-slug: backstage/backstage
- backstage.io/techdocs-ref: github:https://github.com/backstage/backstage.git
+ backstage.io/techdocs-ref: url:https://github.com/backstage/backstage/tree/master
lighthouse.com/website-url: https://backstage.io
spec:
type: library
diff --git a/plugins/techdocs-backend/examples/documented-component/documented-component.yaml b/plugins/techdocs-backend/examples/documented-component/catalog-info.yaml
similarity index 61%
rename from plugins/techdocs-backend/examples/documented-component/documented-component.yaml
rename to plugins/techdocs-backend/examples/documented-component/catalog-info.yaml
index 800116344f..d609866f9b 100644
--- a/plugins/techdocs-backend/examples/documented-component/documented-component.yaml
+++ b/plugins/techdocs-backend/examples/documented-component/catalog-info.yaml
@@ -4,7 +4,7 @@ metadata:
name: documented-component
description: A Service with TechDocs documentation
annotations:
- backstage.io/techdocs-ref: 'github:https://github.com/backstage/backstage/blob/master/plugins/techdocs-backend/examples/documented-component'
+ backstage.io/techdocs-ref: 'url:https://github.com/backstage/backstage/tree/master/plugins/techdocs-backend/examples/documented-component'
spec:
type: service
lifecycle: experimental
From 77c8a9af2106396f1538379142a2d7dbe44c8bb6 Mon Sep 17 00:00:00 2001
From: Himanshu Mishra
Date: Wed, 13 Jan 2021 23:16:19 +0100
Subject: [PATCH 035/144] docs: Update project structure page to remove docker/
---
docs/support/project-structure.md | 4 ----
1 file changed, 4 deletions(-)
diff --git a/docs/support/project-structure.md b/docs/support/project-structure.md
index bb2c02ec76..5c8a8cd3bb 100644
--- a/docs/support/project-structure.md
+++ b/docs/support/project-structure.md
@@ -32,10 +32,6 @@ the code.
better control over our `yarn.lock` file and hopefully avoid problems due to
yarn versioning differences.
-- [`docker/`](https://github.com/backstage/backstage/tree/master/docker) - Files
- related to our root Dockerfile. We are planning to refactor this, so expect
- this folder to be moved in the future.
-
- [`contrib/`](https://github.com/backstage/backstage/tree/master/contrib) -
Collection of examples or resources provided by the community. We really
appreciate contributions in here and encourage them being kept up to date.
From 3e9b38e288231d070777cd651cd3727b5705b4b6 Mon Sep 17 00:00:00 2001
From: Patrik Oldsberg
Date: Sun, 10 Jan 2021 18:11:23 +0100
Subject: [PATCH 036/144] docs: initial incomplete composability docs
---
docs/plugins/composability.md | 86 +++++++++++++++++++++++++++++++++++
1 file changed, 86 insertions(+)
create mode 100644 docs/plugins/composability.md
diff --git a/docs/plugins/composability.md b/docs/plugins/composability.md
new file mode 100644
index 0000000000..d85a557772
--- /dev/null
+++ b/docs/plugins/composability.md
@@ -0,0 +1,86 @@
+---
+id: composability
+title: New Composability System
+description:
+ Documentation and migration instructions for new composability APIs.
+---
+
+## Summary
+
+This page describes the new composability system that was recently introduced in
+Backstage. It describes the new system from the perspective of the existing
+patterns and APIs. As the new system is solidified and existing code is ported,
+this page will removed and replaced with a more direct description of the
+composability system.
+
+The core principle of the new composability system is that plugins should have
+clear boundaries and connections. It should isolate crashes within a plugin, but
+allow navigation between them. It should allow for plugins to be loaded only
+when needed, and enable plugins to provide extension point for other plugins to
+build upon. The composability system is also built with an app-first mindset,
+prioritizing simplicity and clarity in the app over plugins and core APIs.
+
+The new composability system isn't a single new API surface. It is a collection
+of patterns, new primitives, new APIs, and old APIs used in new ways. At the
+core is the new concept of Extensions, are exported by plugins for use in the
+app. There is a new primitive called component data, which is used to connect
+plugin and the app, and a new hook that provides a practical use of .
+
+## Component Data
+
+Component data is a new composability primitive that is introduced as a way to
+provide a new data dimension for React components. Data is attached to React
+components using a key, and is then readable from any JSX elements created with
+those components using the same key, as illustrated by the following example:
+
+```tsx
+const MyComponent = () =>
This is my component
;
+attachComponentData(MyComponent, 'my.data', 5);
+
+const element = ;
+const myData = getComponentData(element, 'my.data');
+// myData === 5
+```
+
+The purpose of component data is to provide a method for embedding data that can
+be inspected before rendering elements. It's a pattern that is quite common
+among React libraries, and used for example by `react-router` and `material-ui`
+to discover properties of the child elements before rendering. Although in those
+libraries only the element type and props are typically inspected, while our
+component data adds more structured access and simplifies evolution by allowing
+for multiple different versions of a piece of data to be used at once.
+
+The main use-case
+
+## Extensions
+
+Extensions are what plugins export for use in an app. Most typically they are
+React components, but in practice they can be any kind of value. They are
+created using `create*Extension` functions, and wrapped with `plugin.provide()`
+in order to create the actual exported extension.
+
+The Backstage core API currently provides two different types of extension
+creators, `createComponentExtension`, and `createRoutableExtension`.
+
+### Extensions from a plugin's point of view
+
+Extensions are one of the primary methods to traverse the plugin boundary, and
+the way that plugins provide concrete content for use within an app. They
+replace existing component export concepts such as `Router` or `*Card`s for
+display on entity overview pages.
+
+### Using Extensions in an app
+
+TODO
+
+## RouteRefs, useRouteRef, and plugin routes and externalRoutes
+
+TODO
+
+## Binding external routes in the app
+
+TODO
+
+## New catalog components, EntitySwitch & EntityLayout, and how to use those in the app
+
+TODO
From 492258d2a10d83fba72d38e5101dc81b0f8795c7 Mon Sep 17 00:00:00 2001
From: Patrik Oldsberg
Date: Tue, 12 Jan 2021 20:23:27 +0100
Subject: [PATCH 037/144] docs: lotsa more composability docs
---
.github/styles/vocab.txt | 2 +
docs/plugins/composability.md | 255 +++++++++++++++++++++++++++++++---
2 files changed, 234 insertions(+), 23 deletions(-)
diff --git a/.github/styles/vocab.txt b/.github/styles/vocab.txt
index a71887f796..6c38cf638a 100644
--- a/.github/styles/vocab.txt
+++ b/.github/styles/vocab.txt
@@ -183,6 +183,8 @@ rollbar
Rollbar
Rollup
Rosaceae
+routable
+Routable
rst
rsync
rugvip
diff --git a/docs/plugins/composability.md b/docs/plugins/composability.md
index d85a557772..5c96b88cee 100644
--- a/docs/plugins/composability.md
+++ b/docs/plugins/composability.md
@@ -26,7 +26,12 @@ core is the new concept of Extensions, are exported by plugins for use in the
app. There is a new primitive called component data, which is used to connect
plugin and the app, and a new hook that provides a practical use of .
-## Component Data
+## New Concepts
+
+This section is a brief look into all the new and updated concepts that were put
+in place to support the new composability system.
+
+### Component Data
Component data is a new composability primitive that is introduced as a way to
provide a new data dimension for React components. Data is attached to React
@@ -43,44 +48,248 @@ const myData = getComponentData(element, 'my.data');
```
The purpose of component data is to provide a method for embedding data that can
-be inspected before rendering elements. It's a pattern that is quite common
-among React libraries, and used for example by `react-router` and `material-ui`
-to discover properties of the child elements before rendering. Although in those
-libraries only the element type and props are typically inspected, while our
-component data adds more structured access and simplifies evolution by allowing
-for multiple different versions of a piece of data to be used at once.
+be inspected before rendering elements. Element inspection is a pattern that is
+quite common among React libraries, and used for example by `react-router` and
+`material-ui` to discover properties of the child elements before rendering.
+Though in those libraries only the element type and props are typically
+inspected, while our component data adds more structured access and simplifies
+evolution by allowing for multiple different versions of a piece of data to be
+used at once.
-The main use-case
+The initial use-cases for component data is support route and plugin discovery
+through elements in the app. Through this we allow for the React element tree in
+the app to be the source of truth, both for which plugins are used and all
+top-level plugin routes in the app. The use of component data is not limited to
+these use-cases though, as it can be used as a primitive to create new
+abstractions as well.
-## Extensions
+### Extensions
Extensions are what plugins export for use in an app. Most typically they are
React components, but in practice they can be any kind of value. They are
created using `create*Extension` functions, and wrapped with `plugin.provide()`
in order to create the actual exported extension.
-The Backstage core API currently provides two different types of extension
-creators, `createComponentExtension`, and `createRoutableExtension`.
+The extension type is dead simple:
-### Extensions from a plugin's point of view
+```ts
+export type Extension = {
+ expose(plugin: BackstagePlugin): T;
+};
+```
+
+The power of extensions comes from the ability of various actors to hook into
+their usage. The creation and plugin wrapping is controlled by whoever owns the
+creation function, the Backstage core is able to hook into the process of
+exposing the extension outside the plugin, and in the end the app controls the
+usage of the extension.
+
+The Backstage core API currently provides two different types of extension
+creators, `createComponentExtension`, and `createRoutableExtension`. Component
+extensions are plain react component with no particular requirements, such as
+cards for entity overview pages. The component will be exported more or less as
+is, but is wrapped up to provide things like an error boundary, lazy loading,
+and a plugin context.
+
+Routable extensions build on top of component extensions and are used for any
+component that should be rendered at a specific route path, such as full pages
+or entity page tab content. When creating a routable extension you need to
+supply a `RouteRef` as `mountPoint`. The mount point will be the handle of the
+component for the outside world, and is used by other components and plugins
+that wish to link to the routable component.
+
+As of now there are only two extension creation functions, but it is possible to
+add more of them in the future, both in the core library and in plugins that
+wish to provide an extension point for other plugins to build upon. Extensions
+are also not tied to React, and can both be used to model generic JavaScript
+concepts, as well as potentially bridge to rendering libraries and web
+frameworks other than React.
+
+### Extensions from a Plugin's Point of View
Extensions are one of the primary methods to traverse the plugin boundary, and
the way that plugins provide concrete content for use within an app. They
replace existing component export concepts such as `Router` or `*Card`s for
display on entity overview pages.
-### Using Extensions in an app
+It is recommended to create the exported extensions either in the top-level
+`plugin.ts` file, or in a dedicated `extensions.ts` (or `.tsx`) file. That file
+should not contain the bulk of the implementation though, and in fact, if the
+extension is a React component it is recommended to lazy-load the actual
+component. Component extensions support lazy loading out of the box using the
+`lazy` component declaration, for example:
+
+```ts
+export const EntityFooCard = plugin.provide(
+ createComponentExtension({
+ component: {
+ lazy: () => import('./components/FooCard').then(m => m.FooCard),
+ },
+ }),
+);
+```
+
+Routable extensions even enforce lazy loading, for example:
+
+```ts
+export const FooPage = plugin.provide(
+ createRoutableExtension({
+ component: () => import('./components/FooPage').then(m => m.FooPage),
+ mountPoint: fooRouteRef,
+ }),
+);
+```
+
+### Using Extensions in an App
+
+Right now all extensions are modelled as React components. The usage of these
+extension is like regular usage of any React components, with one important
+difference. Extensions must be all be part of a single React element tree
+spanning from the root `AppProvider`.
+
+For example, the following app code does **NOT** work:
+
+```tsx
+const AppRoutes = () => (
+
+ } />
+ } />
+
+);
+
+const App = () => (
+
+
+
+
+
+
+
+);
+```
+
+But it is simple to fix! Simply make sure that you don't create any intermediate
+components in the app, for example like this:
+
+```tsx
+const appRoutes = (
+
+ } />
+ } />
+
+);
+
+const App = () => (
+
+
+ {appRoutes}
+
+
+);
+```
+
+### New Routing System
+
+A big piece of what is enabled by moving over to this new composability system
+is to make `RouteRef`s useful. The `RouteRef`s no longer have their own path, in
+fact the only required parameter is currently a `title`. Instead of assigning a
+path to each `RouteRef` and possibly overriding these paths in the app, the
+concrete `path` for each `RouteRef` is discovered based on the element tree in
+the app. Let's consider the following example:
+
+```tsx
+
+ } />
+ } />
+
+```
+
+We'll assume that `FooPage` and `BarPage` are routable extensions, exported by
+the `fooPlugin` and `barPlugin` respectively. Since the `FooPage` is a routable
+extension it has a `RouteRef` assigned as its mount point, which we'll refer to
+as `fooRootRouteRef`.
+
+Given the above example, the `fooRootRouteRef` will be associated with the
+`'/foo'` route. The path is no longer accessible via the `path` property of the
+`RouteRef` though, as the routing structure is tied to the app's react tree. We
+instead use the new `useRouteRef` hook if we want to create a concrete link to
+the page. The `useRouteRef` hook takes a single `RouteRef` as its only
+parameter, and returns a function that is called to create the URL.
+
+Now let's assume that we want to link from the `BarPage` to the `FooPage`.
+Before the introduction of the new composability system, we would do this by
+importing the `fooRootRouteRef` from the `fooPlugin`. This created an
+unnecessary dependency on the plugin, and also provided little flexibility
+allowing the app to tie plugins together rather than the plugins themselves. To
+handle this, we introduce the concept of `ExternalRouteRef`s. Much like regular
+route refs, they can be passed to `useRouteRef` to create concrete URLs, but
+they can not be used as mount points in routable component and instead have to
+be associated with an actual using route bindings in the app.
+
+The `ExternalRouteRef` inside the `barPlugin` should also not be opinionated
+about what it is linking to either, allowing the app to decide the final target.
+It should however provide context in how the link is presented or used, to make
+it easier to understand the flow of the app. If the `BarPage` for example wants
+to link to an external page in the header, it might declare an
+`ExternalRouteRef` similar to this:
+
+```ts
+const headerLinkRouteRef = createExternalRouteRef();
+```
+
+### Binding External Routes in the App
+
+The association of external routes are controlled by the app. Each
+`ExternalRouteRef` of a plugin is bound to an actual `RouteRef`, usually from
+another plugin. The binding process happens once att app startup, and is then
+used through the lifetime of the app to help resolve concrete route paths.
+
+Using the above example of the `BarPage` linking to the `FooPage`, we might do
+something like this in the app:
+
+```ts
+createApp({
+ bindRoutes({ bind }) {
+ bind(barPlugin.externalRoutes, {
+ headerLink: fooPlugin.routes.root,
+ });
+ },
+});
+```
+
+Given the above binding, using `useRouteRef(external)`
+
+Note that we are not importing and using the `RouteRef`s directly, and instead
+rely on the plugin instance to access routes of the plugins. This is a new
+convention that was introduced to provide better namespacing and discoverability
+of routes, as well as reduce the number of different things exported from each
+plugin package. The route references would be supplied to `createPlugin` like
+this:
+
+```ts
+// In foo-plugin
+export const fooPlugin = createPlugin({
+ routes: {
+ root: fooRootRouteRef,
+ },
+ ...
+})
+
+// In bar-plugin
+export const barPlugin = createPlugin({
+ externalRoutes: {
+ headerLink: headerLinkRouteRef,
+ },
+ ...
+})
+```
+
+### New Catalog Components
+
+EntitySwitch & EntityLayout, and how to use those in the app
TODO
-## RouteRefs, useRouteRef, and plugin routes and externalRoutes
+## Porting Existing Plugins
-TODO
-
-## Binding external routes in the app
-
-TODO
-
-## New catalog components, EntitySwitch & EntityLayout, and how to use those in the app
-
-TODO
+## Porting Existing Apps
From 70d8653bdad5649399bcae8d146922bdc3d7b2d5 Mon Sep 17 00:00:00 2001
From: Patrik Oldsberg
Date: Wed, 13 Jan 2021 23:52:10 +0100
Subject: [PATCH 038/144] docs/composability: the rest of the f***ing owl
---
docs/plugins/composability.md | 403 +++++++++++++++++++++++++++++-----
1 file changed, 346 insertions(+), 57 deletions(-)
diff --git a/docs/plugins/composability.md b/docs/plugins/composability.md
index 5c96b88cee..3e38f3376e 100644
--- a/docs/plugins/composability.md
+++ b/docs/plugins/composability.md
@@ -16,15 +16,17 @@ composability system.
The core principle of the new composability system is that plugins should have
clear boundaries and connections. It should isolate crashes within a plugin, but
allow navigation between them. It should allow for plugins to be loaded only
-when needed, and enable plugins to provide extension point for other plugins to
+when needed, and enable plugins to provide extension points for other plugins to
build upon. The composability system is also built with an app-first mindset,
-prioritizing simplicity and clarity in the app over plugins and core APIs.
+prioritizing simplicity and clarity in the app over that in the plugins and core
+APIs.
The new composability system isn't a single new API surface. It is a collection
-of patterns, new primitives, new APIs, and old APIs used in new ways. At the
-core is the new concept of Extensions, are exported by plugins for use in the
-app. There is a new primitive called component data, which is used to connect
-plugin and the app, and a new hook that provides a practical use of .
+of patterns, primitives, new APIs, and old APIs used in new ways. At the core is
+the new concept of extensions, which are exported by plugins for use in the app.
+There is also a new primitive called component data, which assists in the
+conversion to a more declarative app. The `RouteRef`s now have a clear purpose
+as well, and can be used route to pages in a flexible way.
## New Concepts
@@ -36,7 +38,7 @@ in place to support the new composability system.
Component data is a new composability primitive that is introduced as a way to
provide a new data dimension for React components. Data is attached to React
components using a key, and is then readable from any JSX elements created with
-those components using the same key, as illustrated by the following example:
+those components, using the same key, as illustrated by the following example:
```tsx
const MyComponent = () =>
This is my component
;
@@ -51,26 +53,26 @@ The purpose of component data is to provide a method for embedding data that can
be inspected before rendering elements. Element inspection is a pattern that is
quite common among React libraries, and used for example by `react-router` and
`material-ui` to discover properties of the child elements before rendering.
-Though in those libraries only the element type and props are typically
+Although in those libraries only the element type and props are typically
inspected, while our component data adds more structured access and simplifies
evolution by allowing for multiple different versions of a piece of data to be
-used at once.
+used and interpreted at once.
The initial use-cases for component data is support route and plugin discovery
through elements in the app. Through this we allow for the React element tree in
-the app to be the source of truth, both for which plugins are used and all
-top-level plugin routes in the app. The use of component data is not limited to
-these use-cases though, as it can be used as a primitive to create new
+the app to be the source of truth, both for which plugins are used, as well as
+all top-level plugin routes in the app. The use of component data is not limited
+to these use-cases though, as it can be used as a primitive to create new
abstractions as well.
### Extensions
Extensions are what plugins export for use in an app. Most typically they are
-React components, but in practice they can be any kind of value. They are
-created using `create*Extension` functions, and wrapped with `plugin.provide()`
-in order to create the actual exported extension.
+React components, but in practice they can be any kind of JavaScript value. They
+are created using `create*Extension` functions, and wrapped with
+`plugin.provide()` in order to create the actual exported extension.
-The extension type is dead simple:
+The extension type is a simple one:
```ts
export type Extension = {
@@ -86,14 +88,14 @@ usage of the extension.
The Backstage core API currently provides two different types of extension
creators, `createComponentExtension`, and `createRoutableExtension`. Component
-extensions are plain react component with no particular requirements, such as
-cards for entity overview pages. The component will be exported more or less as
-is, but is wrapped up to provide things like an error boundary, lazy loading,
-and a plugin context.
+extensions are plain React component with no particular requirements, for
+example a card for an entity overview page. The component will be exported more
+or less as is, but is wrapped to provide things like an error boundary, lazy
+loading, and a plugin context.
Routable extensions build on top of component extensions and are used for any
-component that should be rendered at a specific route path, such as full pages
-or entity page tab content. When creating a routable extension you need to
+component that should be rendered at a specific route path, such as top-level
+pages or entity page tab content. When creating a routable extension you need to
supply a `RouteRef` as `mountPoint`. The mount point will be the handle of the
component for the outside world, and is used by other components and plugins
that wish to link to the routable component.
@@ -129,7 +131,8 @@ export const EntityFooCard = plugin.provide(
);
```
-Routable extensions even enforce lazy loading, for example:
+Routable extensions even enforce lazy loading, as it is the only way to provide
+a component:
```ts
export const FooPage = plugin.provide(
@@ -144,8 +147,8 @@ export const FooPage = plugin.provide(
Right now all extensions are modelled as React components. The usage of these
extension is like regular usage of any React components, with one important
-difference. Extensions must be all be part of a single React element tree
-spanning from the root `AppProvider`.
+difference. Extensions must all be part of a single React element tree spanning
+from the root `AppProvider`.
For example, the following app code does **NOT** work:
@@ -168,8 +171,8 @@ const App = () => (
);
```
-But it is simple to fix! Simply make sure that you don't create any intermediate
-components in the app, for example like this:
+But in this case it is simple to fix! Simply be sure to not create any
+intermediate components in the app, for example like this:
```tsx
const appRoutes = (
@@ -198,10 +201,12 @@ concrete `path` for each `RouteRef` is discovered based on the element tree in
the app. Let's consider the following example:
```tsx
-
- } />
- } />
-
+const appRoutes = (
+
+ } />
+ } />
+
+);
```
We'll assume that `FooPage` and `BarPage` are routable extensions, exported by
@@ -214,24 +219,32 @@ Given the above example, the `fooRootRouteRef` will be associated with the
`RouteRef` though, as the routing structure is tied to the app's react tree. We
instead use the new `useRouteRef` hook if we want to create a concrete link to
the page. The `useRouteRef` hook takes a single `RouteRef` as its only
-parameter, and returns a function that is called to create the URL.
+parameter, and returns a function that is called to create the URL. For example
+like this:
+
+```tsx
+const MyComponent = () => {
+ const fooRoute = useRouteRef(fooRouteRef);
+ return Link to Foo;
+};
+```
Now let's assume that we want to link from the `BarPage` to the `FooPage`.
Before the introduction of the new composability system, we would do this by
importing the `fooRootRouteRef` from the `fooPlugin`. This created an
-unnecessary dependency on the plugin, and also provided little flexibility
-allowing the app to tie plugins together rather than the plugins themselves. To
-handle this, we introduce the concept of `ExternalRouteRef`s. Much like regular
-route refs, they can be passed to `useRouteRef` to create concrete URLs, but
-they can not be used as mount points in routable component and instead have to
-be associated with an actual using route bindings in the app.
+unnecessary dependency on the plugin, and also provided little flexibility in
+allowing the app to tie plugins together, with the links instead being dictated
+by the plugins themselves. To solve this, we introduce `ExternalRouteRef`s. Much
+like regular route references, they can be passed to `useRouteRef` to create
+concrete URLs, but they can not be used as mount points in routable component
+and instead have to be associated with a target route using route bindings in
+the app.
-The `ExternalRouteRef` inside the `barPlugin` should also not be opinionated
-about what it is linking to either, allowing the app to decide the final target.
-It should however provide context in how the link is presented or used, to make
-it easier to understand the flow of the app. If the `BarPage` for example wants
-to link to an external page in the header, it might declare an
-`ExternalRouteRef` similar to this:
+We create a new `ExternalRouteRef` inside the `barPlugin`, using a neutral name
+that describes its role in the plugin rather than a specific plugin page that it
+might be linking to, allowing the app to decide the final target. If the
+`BarPage` for example wants to link to an external page in the header, it might
+declare an `ExternalRouteRef` similar to this:
```ts
const headerLinkRouteRef = createExternalRouteRef();
@@ -239,10 +252,11 @@ const headerLinkRouteRef = createExternalRouteRef();
### Binding External Routes in the App
-The association of external routes are controlled by the app. Each
-`ExternalRouteRef` of a plugin is bound to an actual `RouteRef`, usually from
-another plugin. The binding process happens once att app startup, and is then
-used through the lifetime of the app to help resolve concrete route paths.
+The association of external routes is controlled by the app. Each
+`ExternalRouteRef` of a plugin should be<- bound to an actual `RouteRef`,
+usually from another plugin. The binding process happens once att app startup,
+and is then used through the lifetime of the app to help resolve concrete route
+paths.
Using the above example of the `BarPage` linking to the `FooPage`, we might do
something like this in the app:
@@ -257,14 +271,15 @@ createApp({
});
```
-Given the above binding, using `useRouteRef(external)`
+Given the above binding, using `useRouteRef(headerLinkRouteRef)` within the
+`barPlugin` will let us create a link whatever path the `FooPage` is mounted at.
-Note that we are not importing and using the `RouteRef`s directly, and instead
-rely on the plugin instance to access routes of the plugins. This is a new
-convention that was introduced to provide better namespacing and discoverability
-of routes, as well as reduce the number of different things exported from each
-plugin package. The route references would be supplied to `createPlugin` like
-this:
+Note that we are not importing and using the `RouteRef`s directly in the app,
+and instead rely on the plugin instance to access routes of the plugins. This is
+a new convention that was introduced to provide better namespacing and
+discoverability of routes, as well as reduce the number of separate exports from
+each plugin package. The route references would be supplied to `createPlugin`
+like this:
```ts
// In foo-plugin
@@ -284,12 +299,286 @@ export const barPlugin = createPlugin({
})
```
+Also note that you almost always want to create the route references themselves
+in a different file than the one that creates the plugin instance, for example a
+top-level `routes.ts`. This is to avoid circular imports when you use the route
+references from other parts of the app.
+
+### Parameterized Routes
+
+A new addition to `RouteRef`s is the possibility of adding named and typed
+parameters. Parameters are declared at creation, and will enforce presence of
+the parameters in the path in the app, and require them as a parameter when
+using `useRouteRef`.
+
+The following is an example of creation and usage of a parameterized route:
+
+```tsx
+// Creation of a parameterized route
+const myRouteRef = createRouteRef({
+ title: 'My Named Route',
+ params: ['name']
+})
+
+// In the app, where MyPage is a routable extension with myRouteRef set as mountPoint
+}/>
+
+// Usage within a component
+const myRoute = useRouteRef(myRouteRef)
+return (
+
+)
+```
+
+It is currently not possible to have parameterized `ExternalRouteRef`s, or to
+bind an external route to a parameterized route, although this may be added in
+the future if needed.
+
### New Catalog Components
-EntitySwitch & EntityLayout, and how to use those in the app
+The established pattern for selecting what plugins should be available on each
+catalog page is to use custom components in the app, with logic embedded in the
+render function. Typically this takes form as a component that either receives
+the entity via props or uses the `useEntity` hook to retrieve the selected
+entity. A `switch` or `if` / `else if` chain is then used to select what
+children should be rendered based on information in the entity.
-TODO
+This pattern will no longer work with the new composability system, and in
+general is very difficult to build any form declarative model around, as it
+depends on runtime execution. To help replace existing code, a new
+`EntitySwitch` component has been added to the `@backstage/catalog` plugin,
+which grabs the selected entity from context, and selects at most one element to
+render using a list of `EntitySwitch.Case`s children.
+
+For example, if you want all entities of kind `"Template"` to be rendered with a
+`MyTemplate` component, and all other entities to be rendered with a `MyOther`
+component, you would do the following:
+
+```tsx
+
+
+
+
+
+
+
+
+
+
+// Shorter form if desired:
+
+ }/>
+ }/>
+
+```
+
+The `EntitySwitch` component will render the children of the first
+`EntitySwitch.Case` that returns `true` when the selected entity is passed to
+the function of the `if` prop. If none of the cases match, no children will be
+rendered, and if a case doesn't specify an `if` filter function, it will always
+match. The `if` property is simply a function of the type
+`(entity: Entity) => boolean`, for example, `isKind` can be implemented like
+this:
+
+```ts
+function isKind(kind: string) {
+ return (entity: Entity) => entity.kind.toLowerCase() === kind.toLowerCase();
+}
+```
+
+The `@backstage/catalog` plugin provides a couple of built-in conditions,
+`isKind`, `isComponentType`, and `isNamespace`.
+
+In addition to the `EntitySwitch` component, the catalog plugin also exports a
+new `EntityLayout` component. It is a tweaked version and replacement for the
+`EntityPageLayout` component, and is introduced more in depth in the app
+migration section below.
## Porting Existing Plugins
+There are a couple of high-level steps to porting an existing plugin to the new
+composability system:
+
+- Remove usage of `router.addRoute` or `router.registerRoute` within
+ `createPlugin`, and export the page components as routable extensions instead.
+- Switch any `Router` export to instead be a routable extension.
+- Change any plain component exports, such as catalog overview cards, to be
+ component extensions.
+- Stop exporting `RouteRef`s and instead pass them to `createPlugin`.
+- Stop accepting `RouteRef`s as props or importing them from other plugins,
+ instead create an `ExternalRouteRef` as a replacement, and pass it to
+ `createPlugin.`
+- Rename any other exported symbols according to the naming pattern table below.
+
+Note that removing the existing exports and configuration is a breaking change
+in any plugin. If backwards compatibility is needed the existing code be
+deprecated while making the new additions, to then be removed at a later point.
+
+### Naming Patterns
+
+Many export naming patterns have been changed to avoid import aliases and to
+clarify intent. Refer to the following table to formulate the new name:
+
+| Description | Existing Pattern | New Pattern | Examples |
+| -------------------- | -------------------------- | --------------- | ---------------------------------------------- |
+| Top-level Pages | Router | \*Page | CatalogIndexPage, SettingsPage, LighthousePage |
+| Entity Tab Content | Router | Entity\*Content | EntityJenkinsContent, EntityKubernetesContent |
+| Entity Overview Card | \*Card | Entity\*Card | EntitySentryCard, EntityPagerDutyCard |
+| Entity Conditional | isPluginApplicableToEntity | is\*Available | isPagerDutyAvailable, isJenkinsAvailable |
+| Plugin Instance | plugin | \*Plugin | jenkinsPlugin, catalogPlugin |
+
## Porting Existing Apps
+
+The first step of porting any app is to replace the root `Routes` component with
+`FlatRoutes` from `@backstage/core`. As opposed to the `Routes` component,
+`FlatRoutes` only considers the first level of `Route` components in its
+children, and provides any additional children to the outlet of the route. It
+also removes the need to append `"/*"` to paths, as it is added automatically.
+
+```diff
+const AppRoutes = () => (
+-
++
+ ...
+- } />
++ } />
+ ...
+-
++
+);
+```
+
+The next step should be to switch from using `EntityPageLayout` to
+`EntityLayout`, as this can also be done without waiting for plugins to be
+ported. You should also replace the top-level `Router` from the catalog plugin
+with the separate `CatalogIndexPage` and `CatalogEntityPage` extensions that
+have been added to the catalog:
+
+```diff
+-}
+-/>
++} />
++}
++>
++
++
+```
+
+At that point you should flatten out the element tree as much as possible in the
+app, removing any intermediate components. At the top level this should usually
+be straightforward, but when reaching the catalog entity pages you may need to
+wait for some plugins to be migrated. This is because it is no longer possible
+to pass in the selected entity through component props, and it should be picked
+up from context inside the plugin instead. See the sections below for how to
+carry out migrations of some common entity page patterns.
+
+Once the app element tree doesn't contain any intermediate components, and all
+plugin imports have been switched to extensions rather than plain components,
+the app has been fully ported.
+
+### Switching from EntityPageLayout to EntityLayout
+
+The existing `EntityPageLayout` is replaced by the new `EntityLayout` component,
+which has a slightly different pattern for expressing the contents and paths.
+
+Porting from the old to the new API is just a matter of moving some things
+around. For example, given the following existing code:
+
+```tsx
+
+ }
+ />
+ }
+ />
+ }
+ />
+
+```
+
+It would be ported to this:
+
+```tsx
+
+
+ }
+
+
+
+ }
+
+
+
+ }
+
+
+```
+
+In addition to the renaming, the `element` prop has been moved to `children`.
+Also note that the `/*` suffix has been remove from the `"/kubernetes"` path, as
+it's now added automatically.
+
+Usage of the `EntityLayout` component is required to be able to properly
+discover routes, and so it is required to apply this change before you can start
+using routable entity content extensions from plugins.
+
+### Porting Entity Pages
+
+The established pattern in the app is to use custom components in order to
+select what plugin components to render for a given entity. The new
+`EntitySwitch` component introduced above is what is intended to replace this
+pattern, now that the entire app needs to be rendered as a single element tree.
+For example, given the following existing code:
+
+```tsx
+export const EntityPage = () => {
+ const { entity } = useEntity();
+
+ switch (entity?.kind?.toLowerCase()) {
+ case 'component':
+ return ;
+ case 'api':
+ return ;
+ case 'group':
+ return ;
+ case 'user':
+ return ;
+ default:
+ return ;
+ }
+};
+```
+
+It would be migrated to this:
+
+```tsx
+export const entityPage = (
+
+
+
+
+
+
+
+);
+```
+
+Note that for example `` has been changed to simply
+`componentPage`, that is because just like the `EntityPage` component, the
+`ComponentEntityPage` also needs to be ported to be an element rather a
+component in a similar way.
From 72ce0f8b163b4d01a309064cad99f6f5af20e36e Mon Sep 17 00:00:00 2001
From: Patrik Oldsberg
Date: Thu, 14 Jan 2021 02:04:57 +0100
Subject: [PATCH 039/144] docs/composability: include in sidebar and add note
about purpose
---
docs/plugins/composability.md | 11 ++++++-----
microsite/sidebars.json | 1 +
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/docs/plugins/composability.md b/docs/plugins/composability.md
index 3e38f3376e..e6f00d2374 100644
--- a/docs/plugins/composability.md
+++ b/docs/plugins/composability.md
@@ -1,6 +1,6 @@
---
id: composability
-title: New Composability System
+title: Composability System Migration
description:
Documentation and migration instructions for new composability APIs.
---
@@ -8,10 +8,11 @@ description:
## Summary
This page describes the new composability system that was recently introduced in
-Backstage. It describes the new system from the perspective of the existing
-patterns and APIs. As the new system is solidified and existing code is ported,
-this page will removed and replaced with a more direct description of the
-composability system.
+Backstage, and it does so from the perspective of the existing patterns and
+APIs. As the new system is solidified and existing code is ported, this page
+will removed and replaced with a more direct description of the composability
+system. For now, the primary purpose of this documentation is to aid in the
+migration of existing plugins, but it does cover the migration of apps as well.
The core principle of the new composability system is that plugins should have
clear boundaries and connections. It should isolate crashes within a plugin, but
diff --git a/microsite/sidebars.json b/microsite/sidebars.json
index 3d6417cc65..05e421cb19 100644
--- a/microsite/sidebars.json
+++ b/microsite/sidebars.json
@@ -95,6 +95,7 @@
"plugins/plugin-development",
"plugins/structure-of-a-plugin",
"plugins/integrating-plugin-into-service-catalog",
+ "plugins/composability",
{
"type": "subcategory",
"label": "Backends and APIs",
From 1f383bbb7c07e5b5e2f7892731bb0c68fc79e749 Mon Sep 17 00:00:00 2001
From: Adam Harvey
Date: Thu, 14 Jan 2021 00:24:40 -0500
Subject: [PATCH 040/144] Clarity of error vs problem
---
.../src/components/KubernetesContent/ErrorPanel.tsx | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/plugins/kubernetes/src/components/KubernetesContent/ErrorPanel.tsx b/plugins/kubernetes/src/components/KubernetesContent/ErrorPanel.tsx
index 85060fc11b..650e6ddff1 100644
--- a/plugins/kubernetes/src/components/KubernetesContent/ErrorPanel.tsx
+++ b/plugins/kubernetes/src/components/KubernetesContent/ErrorPanel.tsx
@@ -52,8 +52,8 @@ export const ErrorPanel = ({
clustersWithErrors,
}: ErrorPanelProps) => (
{clustersWithErrors && (