Skip to content

Commit

Permalink
moved secrets to backend schema
Browse files Browse the repository at this point in the history
  • Loading branch information
fokolo committed Dec 17, 2024
1 parent 75c2ab7 commit 9051529
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 45 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ For more than 15 users you need to get a license from [Port](https://backstage-p

- In Port, on the top right, click on the three dots and select **Credentials**
- Generate API credentials (Client ID and Client Secret)
- Add these credentials to your Backstage's `app-config.yaml`:
- Add these credentials to your Backstage's `app-config.yaml` under the `backend`:
```yaml
port:
api:
baseUrl: https://api.getport.io/
auth:
clientId: YOUR_CLIENT_ID
clientSecret: YOUR_CLIENT_SECRET
backend:
port:
api:
baseUrl: https://api.getport.io/
auth:
clientId: YOUR_CLIENT_ID
clientSecret: YOUR_CLIENT_SECRET
```
- [Find your Port credentials](https://docs.getport.io/build-your-software-catalog/custom-integration/api/#find-your-port-credentials)
Expand Down
15 changes: 6 additions & 9 deletions backstage-plugins/plugins/backend-plugin/app-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ backend:
baseUrl: http://localhost:7007
listen:
port: 7007
auth:
# For testing purposes, we're disabling the default auth policy
dangerouslyDisableDefaultAuthPolicy: true

port:
api:
baseUrl: https://api.getport.io/
auth:
clientId:
clientSecret:
port:
api:
baseUrl: https://api.getport.io/
auth:
clientId:
clientSecret:
13 changes: 13 additions & 0 deletions backstage-plugins/plugins/backend-plugin/config.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export interface Config {
backend: {
port: {
api: {
baseUrl: string;
auth: {
clientId: string;
clientSecret: string;
};
};
};
};
}
6 changes: 4 additions & 2 deletions backstage-plugins/plugins/backend-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
"supertest": "^6.2.4"
},
"files": [
"dist"
]
"dist",
"config.d.ts"
],
"configSchema": "config.d.ts"
}
25 changes: 12 additions & 13 deletions backstage-plugins/plugins/backend-plugin/src/service/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ function isTokenExpired(token: string): boolean {

export function createAuthMiddleware(options: {
logger: LoggerService;
config: RootConfigService;
baseUrl: string;
clientId: string;
clientSecret: string;
}) {
const { logger, config } = options;
const baseUrl = config.getString('port.api.baseUrl');
const clientId = config.getString('port.api.auth.clientId');
const clientSecret = config.getString('port.api.auth.clientSecret');
const { logger, baseUrl, clientId, clientSecret } = options;

const router = Router();
logger.info('Creating auth middleware');
Expand All @@ -64,10 +63,9 @@ export function createAuthMiddleware(options: {

export function createPortProxyMiddleware(options: {
logger: LoggerService;
config: RootConfigService;
baseUrl: string;
}) {
const { logger, config } = options;
const baseUrl = config.getString('port.api.baseUrl');
const { logger, baseUrl } = options;

const target = getBaseUrl(baseUrl);

Expand All @@ -85,9 +83,10 @@ export async function createRouter(
options: RouterOptions,
): Promise<express.Handler> {
const { logger, config } = options;
const baseUrl = config.getString('port.api.baseUrl');
const clientId = config.getString('port.api.auth.clientId');
const clientSecret = config.getString('port.api.auth.clientSecret');
const portConfig = config.getConfig('backend.port');
const baseUrl = portConfig.getString('api.baseUrl');
const clientId = portConfig.getString('api.auth.clientId');
const clientSecret = portConfig.getString('api.auth.clientSecret');

const router = Router();
router.use(express.json());
Expand All @@ -112,8 +111,8 @@ export async function createRouter(

router.use(
'/proxy',
createAuthMiddleware(options),
createPortProxyMiddleware(options),
createAuthMiddleware({ logger, baseUrl, clientId, clientSecret }),
createPortProxyMiddleware({ logger, baseUrl }),
);
return router;
}
15 changes: 8 additions & 7 deletions docs/site/docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,16 @@ and then add the link to the NavBar, in the file: `packages/app/src/components/R

1. In Port, on the top right, click on the `...` (three dots) and select **Credentials**.
2. Generate API credentials (Client ID and Client Secret)
3. Add these credentials to your Backstage's `app-config.yaml`:
3. Add these credentials to your Backstage's `app-config.yaml` under the `backend`:

```yaml
port:
api:
baseUrl: https://api.getport.io/
auth:
clientId: YOUR_CLIENT_ID
clientSecret: YOUR_CLIENT_SECRET
backend:
port:
api:
baseUrl: https://api.getport.io/
auth:
clientId: YOUR_CLIENT_ID
clientSecret: YOUR_CLIENT_SECRET
```
<br />
Expand Down
15 changes: 8 additions & 7 deletions docs/site/docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@ and then add the link to the NavBar, in the file: `packages/app/src/components/R

1. In Port, on the top right, click on the `...` (three dots) and select **Credentials**.
2. Generate API credentials (Client ID and Client Secret)
3. Add these credentials to your Backstage's `app-config.yaml`:
3. Add these credentials to your Backstage's `app-config.yaml` under the `backend`:

```yaml
port:
api:
baseUrl: https://api.getport.io/
auth:
clientId: YOUR_CLIENT_ID
clientSecret: YOUR_CLIENT_SECRET
backend:
port:
api:
baseUrl: https://api.getport.io/
auth:
clientId: YOUR_CLIENT_ID
clientSecret: YOUR_CLIENT_SECRET
```
<br />
Expand Down

0 comments on commit 9051529

Please sign in to comment.