Skip to content

Commit

Permalink
feat(aap)!: migrate to the new backend and remove deprecations (#2189)
Browse files Browse the repository at this point in the history
* feat(aap)!: migrate to the new backend and remove deprecations

Signed-off-by: Paul Schultz <pschultz@pobox.com>

* update docs

Signed-off-by: Paul Schultz <pschultz@pobox.com>

* update provider

Signed-off-by: Paul Schultz <pschultz@pobox.com>

* fix config issues

Signed-off-by: Paul Schultz <pschultz@pobox.com>

* update dist-dynamic

Signed-off-by: Paul Schultz <pschultz@pobox.com>

* update exports

Signed-off-by: Paul Schultz <pschultz@pobox.com>

* fix deps

Signed-off-by: Paul Schultz <pschultz@pobox.com>

* Update plugins/aap-backend/src/providers/AapResourceEntityProvider.ts

Co-authored-by: Kashish Mittal <113269381+04kash@users.noreply.github.com>

* update readme

Signed-off-by: Paul Schultz <pschultz@pobox.com>

---------

Signed-off-by: Paul Schultz <pschultz@pobox.com>
Co-authored-by: Kashish Mittal <113269381+04kash@users.noreply.github.com>
  • Loading branch information
schultzp2020 and 04kash authored Sep 26, 2024
1 parent 1ea2d5a commit c6f967b
Show file tree
Hide file tree
Showing 18 changed files with 386 additions and 405 deletions.
105 changes: 2 additions & 103 deletions plugins/aap-backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,108 +8,7 @@ The Ansible Automation Platform (AAP) Backstage provider plugin synchronizes the

The AAP Backstage provider plugin allows the configuration of one or multiple providers using the `app-config.yaml` configuration file of Backstage.

#### Legacy Backend Procedure

1. Run the following command to install the AAP Backstage provider plugin:

```console
yarn workspace backend add @janus-idp/backstage-plugin-aap-backend
```

1. Use `aap` marker to configure the `app-config.yaml` file of Backstage as follows:

```yaml title="app-config.yaml"
catalog:
providers:
aap:
dev:
baseUrl: <URL>
authorization: 'Bearer ${AAP_AUTH_TOKEN}'
owner: <owner>
system: <system>
schedule: # optional; same options as in TaskScheduleDefinition
# supports cron, ISO duration, "human duration" as used in code
frequency: { minutes: 1 }
# supports ISO duration, "human duration" as used in code
timeout: { minutes: 1 }
```
1. Configure the scheduler using one of the following options:
- **Method 1**: If the scheduler is configured inside the `app-config.yaml` using the schedule config key mentioned previously, add the following code to `packages/backend/src/plugins/catalog.ts` file:

```ts title="packages/backend/src/plugins/catalog.ts"
/* highlight-add-next-line */
import { AapResourceEntityProvider } from '@janus-idp/backstage-plugin-aap-backend';
export default async function createPlugin(
env: PluginEnvironment,
): Promise<Router> {
const builder = await CatalogBuilder.create(env);
/* ... other processors and/or providers ... */
/* highlight-add-start */
builder.addEntityProvider(
AapResourceEntityProvider.fromConfig(env.config, {
logger: env.logger,
scheduler: env.scheduler,
}),
);
/* highlight-add-end */
const { processingEngine, router } = await builder.build();
await processingEngine.start();
return router;
}
```

***

**NOTE**

If you have made any changes to the schedule in the `app-config.yaml` file, then restart to apply the changes.

***

- **Method 2**: Add a schedule directly inside the `packages/backend/src/plugins/catalog.ts` file as follows:

```ts title="packages/backend/src/plugins/catalog.ts"
/* highlight-add-next-line */
import { AapResourceEntityProvider } from '@janus-idp/backstage-plugin-aap-backend';
export default async function createPlugin(
env: PluginEnvironment,
): Promise<Router> {
const builder = await CatalogBuilder.create(env);
/* ... other processors and/or providers ... */
/* highlight-add-start */
builder.addEntityProvider(
AapResourceEntityProvider.fromConfig(env.config, {
logger: env.logger,
schedule: env.scheduler.createScheduledTaskRunner({
frequency: { minutes: 30 },
timeout: { minutes: 3 },
}),
}),
);
/* highlight-add-end */
const { processingEngine, router } = await builder.build();
await processingEngine.start();
return router;
}
```

***

**NOTE**

If both the `schedule` (hard-coded schedule) and `scheduler` (`app-config.yaml` schedule) option are provided in the `packages/backend/src/plugins/catalog.ts`, the `scheduler` option takes precedence. However, if the schedule inside the `app-config.yaml` file is not configured, then the `schedule` option is used.

***

#### New Backend Procedure
#### Backend Procedure

1. Run the following command to install the AAP Backstage provider plugin:

Expand Down Expand Up @@ -141,7 +40,7 @@ The AAP Backstage provider plugin allows the configuration of one or multiple pr
const backend = createBackend();
/* highlight-add-next-line */
backend.add(import('@janus-idp/backstage-plugin-aap-backend/alpha'));
backend.add(import('@janus-idp/backstage-plugin-aap-backend'));
backend.start();
```
Expand Down
4 changes: 2 additions & 2 deletions plugins/aap-backend/config.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TaskScheduleDefinitionConfig } from '@backstage/backend-tasks';
import { SchedulerServiceTaskScheduleDefinitionConfig } from '@backstage/backend-plugin-api';

export interface Config {
catalog?: {
Expand All @@ -13,7 +13,7 @@ export interface Config {
authorization: string;
system?: string;
owner?: string;
schedule?: TaskScheduleDefinitionConfig;
schedule?: SchedulerServiceTaskScheduleDefinitionConfig;
};
};
};
Expand Down
11 changes: 11 additions & 0 deletions plugins/aap-backend/dev/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createBackend } from '@backstage/backend-defaults';

import { catalogModuleAapResourceEntityProvider } from '../src/module';

const backend = createBackend();

// api endpoints from here: https://github.com/backstage/backstage/blob/master/plugins/catalog-backend/src/service/createRouter.ts
backend.add(import('@backstage/plugin-catalog-backend/alpha'));
backend.add(catalogModuleAapResourceEntityProvider);

backend.start();
14 changes: 3 additions & 11 deletions plugins/aap-backend/dist-dynamic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
"require": "./dist/index.cjs.js",
"default": "./dist/index.cjs.js"
},
"./alpha": {
"require": "./dist/alpha.cjs.js",
"default": "./dist/alpha.cjs.js"
},
"./package.json": "./package.json"
},
"scripts": {},
Expand All @@ -30,8 +26,7 @@
"files": [
"dist",
"config.d.ts",
"app-config.janus-idp.yaml",
"alpha"
"app-config.janus-idp.yaml"
],
"configSchema": "config.d.ts",
"repository": {
Expand All @@ -53,13 +48,10 @@
"author": "Red Hat",
"bundleDependencies": true,
"peerDependencies": {
"@backstage/backend-common": "^0.23.3",
"@backstage/backend-plugin-api": "^0.7.0",
"@backstage/backend-tasks": "^0.5.27",
"@backstage/catalog-model": "^1.5.0",
"@backstage/config": "^1.2.0",
"@backstage/plugin-catalog-node": "^1.12.4",
"@backstage/backend-dynamic-feature-service": "^0.2.15"
"@backstage/errors": "^1.2.4",
"@backstage/plugin-catalog-node": "^1.12.4"
},
"overrides": {
"@aws-sdk/util-utf8-browser": {
Expand Down
6 changes: 3 additions & 3 deletions plugins/aap-backend/dist-dynamic/yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 6 additions & 10 deletions plugins/aap-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@
},
"exports": {
".": "./src/index.ts",
"./alpha": "./src/alpha.ts",
"./package.json": "./package.json"
},
"typesVersions": {
"*": {
"alpha": [
"src/alpha.ts"
],
"package.json": [
"package.json"
]
Expand All @@ -41,16 +37,17 @@
"tsc": "tsc"
},
"dependencies": {
"@backstage/backend-common": "^0.23.3",
"@backstage/backend-plugin-api": "^0.7.0",
"@backstage/backend-tasks": "^0.5.27",
"@backstage/catalog-model": "^1.5.0",
"@backstage/config": "^1.2.0",
"@backstage/plugin-catalog-node": "^1.12.4",
"@backstage/backend-dynamic-feature-service": "^0.2.15"
"@backstage/errors": "^1.2.4",
"@backstage/plugin-catalog-node": "^1.12.4"
},
"devDependencies": {
"@backstage/backend-defaults": "0.4.1",
"@backstage/config": "1.2.0",
"@backstage/backend-test-utils": "0.4.4",
"@backstage/cli": "0.26.11",
"@backstage/plugin-catalog-backend": "1.24.0",
"@janus-idp/cli": "1.15.0",
"@types/supertest": "2.0.16",
"msw": "1.3.3",
Expand All @@ -61,7 +58,6 @@
"config.d.ts",
"dist-dynamic/*.*",
"dist-dynamic/dist/**",
"dist-dynamic/alpha/*",
"app-config.janus-idp.yaml"
],
"configSchema": "config.d.ts",
Expand Down
17 changes: 0 additions & 17 deletions plugins/aap-backend/src/alpha.ts

This file was deleted.

36 changes: 20 additions & 16 deletions plugins/aap-backend/src/clients/AapResourceConnector.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
import { JobTemplates } from './types';

export function listJobTemplates(
export async function listJobTemplates(
baseUrl: string,
access_token: string,
): Promise<JobTemplates> {
return fetch(`${baseUrl}/api/v2/job_templates`, {
const res = await fetch(`${baseUrl}/api/v2/job_templates`, {
headers: {
'Content-Type': 'application/json',
Authorization: access_token,
},
method: 'GET',
}).then(async response => {
if (!response.ok) {
throw new Error(response.statusText);
}
const resData = await response.json();
return resData.results as Promise<JobTemplates>;
});

if (!res.ok) {
throw new Error(res.statusText);
}

const data = (await res.json()) as { results: JobTemplates };

return data.results;
}

export function listWorkflowJobTemplates(
export async function listWorkflowJobTemplates(
baseUrl: string,
access_token: string,
): Promise<JobTemplates> {
return fetch(`${baseUrl}/api/v2/workflow_job_templates`, {
const res = await fetch(`${baseUrl}/api/v2/workflow_job_templates`, {
headers: {
'Content-Type': 'application/json',
Authorization: access_token,
},
method: 'GET',
}).then(async response => {
if (!response.ok) {
throw new Error(response.statusText);
}
const resData = await response.json();
return resData.results as Promise<JobTemplates>;
});

if (!res.ok) {
throw new Error(res.statusText);
}

const data = (await res.json()) as { results: JobTemplates };

return data.results;
}
35 changes: 0 additions & 35 deletions plugins/aap-backend/src/dynamic/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/aap-backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './clients';
export { catalogModuleAapResourceEntityProvider as default } from './module';
export * from './providers';
export * from './dynamic/index';
Loading

0 comments on commit c6f967b

Please sign in to comment.