@pagerduty/backstage-plugin-entity-processor 0.1.0-next.2 → 0.1.0-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +41 -12
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +3 -3
package/dist/index.cjs.js
CHANGED
|
@@ -12,12 +12,14 @@ var __publicField = (obj, key, value) => {
|
|
|
12
12
|
return value;
|
|
13
13
|
};
|
|
14
14
|
class PagerDutyEntityProcessor {
|
|
15
|
-
|
|
16
|
-
// return entity.kind === 'Component';
|
|
17
|
-
// }
|
|
18
|
-
constructor(logger) {
|
|
15
|
+
constructor({ logger, store }) {
|
|
19
16
|
__publicField(this, "logger");
|
|
17
|
+
__publicField(this, "store");
|
|
18
|
+
__publicField(this, "shouldProcessEntity", (entity) => {
|
|
19
|
+
return entity.kind === "Component";
|
|
20
|
+
});
|
|
20
21
|
this.logger = logger;
|
|
22
|
+
this.store = store;
|
|
21
23
|
}
|
|
22
24
|
getProcessorName() {
|
|
23
25
|
return "PagerDutyEntityProcessor";
|
|
@@ -26,17 +28,39 @@ class PagerDutyEntityProcessor {
|
|
|
26
28
|
// return new PagerDutyEntityProcessor();
|
|
27
29
|
// }
|
|
28
30
|
async preProcessEntity(entity) {
|
|
29
|
-
this.
|
|
30
|
-
|
|
31
|
-
entity.metadata.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
if (this.shouldProcessEntity(entity)) {
|
|
32
|
+
this.logger.info(`Processing entity: ${entity.metadata.name}`);
|
|
33
|
+
const mapping = await this.store.findEntityMappingByEntityRef(entity.metadata.uid);
|
|
34
|
+
if (mapping) {
|
|
35
|
+
this.logger.info(`Found mapping for entity: ${entity.metadata.name}`);
|
|
36
|
+
entity.metadata.annotations["pagerduty.com/service-id"] = mapping.serviceId;
|
|
37
|
+
} else {
|
|
38
|
+
this.logger.info(`No mapping found for entity: ${entity.metadata.name}`);
|
|
39
|
+
}
|
|
35
40
|
}
|
|
36
41
|
return entity;
|
|
37
42
|
}
|
|
38
43
|
}
|
|
39
44
|
|
|
45
|
+
const migrationsDir = backendPluginApi.resolvePackagePath("@pagerduty/backstage-plugin-backend", "migrations");
|
|
46
|
+
class PagerDutyBackendDatabase {
|
|
47
|
+
constructor(db) {
|
|
48
|
+
this.db = db;
|
|
49
|
+
}
|
|
50
|
+
static async create(knex, options) {
|
|
51
|
+
if (options == null ? void 0 : options.skipMigrations) {
|
|
52
|
+
await knex.migrate.latest({
|
|
53
|
+
directory: migrationsDir
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return new PagerDutyBackendDatabase(knex);
|
|
57
|
+
}
|
|
58
|
+
async findEntityMappingByEntityRef(entityRef) {
|
|
59
|
+
const rawEntity = await this.db("pagerduty_entity_mapping").where("entityRef", entityRef).first();
|
|
60
|
+
return rawEntity;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
40
64
|
const pagerDutyEntityProcessor = backendPluginApi.createBackendModule({
|
|
41
65
|
pluginId: "catalog",
|
|
42
66
|
moduleId: "pagerduty-entity-processor",
|
|
@@ -44,10 +68,15 @@ const pagerDutyEntityProcessor = backendPluginApi.createBackendModule({
|
|
|
44
68
|
env.registerInit({
|
|
45
69
|
deps: {
|
|
46
70
|
logger: backendPluginApi.coreServices.logger,
|
|
71
|
+
database: backendPluginApi.coreServices.database,
|
|
47
72
|
catalog: alpha.catalogProcessingExtensionPoint
|
|
48
73
|
},
|
|
49
|
-
async init({ logger, catalog }) {
|
|
50
|
-
|
|
74
|
+
async init({ logger, database, catalog }) {
|
|
75
|
+
const store = await PagerDutyBackendDatabase.create(
|
|
76
|
+
await database.getClient(),
|
|
77
|
+
{ skipMigrations: true }
|
|
78
|
+
);
|
|
79
|
+
catalog.addProcessor(new PagerDutyEntityProcessor({ logger, store }));
|
|
51
80
|
}
|
|
52
81
|
});
|
|
53
82
|
}
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/processor/PagerDutyEntityProcessor.ts","../src/module.ts"],"sourcesContent":["import { LoggerService } from \"@backstage/backend-plugin-api\";\nimport { Entity } from \"@backstage/catalog-model\";\nimport { CatalogProcessor } from \"@backstage/plugin-catalog-node\";\n\n/**\n * A function which given an entity, determines if it should be processed for linguist tags.\n * @public\n */\
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/processor/PagerDutyEntityProcessor.ts","../src/db/PagerDutyBackendDatabase.ts","../src/module.ts"],"sourcesContent":["import { LoggerService } from \"@backstage/backend-plugin-api\";\nimport { Entity } from \"@backstage/catalog-model\";\nimport { CatalogProcessor } from \"@backstage/plugin-catalog-node\";\nimport { PagerDutyBackendStore } from \"../db\";\n\n/**\n * A function which given an entity, determines if it should be processed for linguist tags.\n * @public\n */\nexport type ShouldProcessEntity = (entity: Entity) => boolean;\n\nexport interface PagerDutyEntityProcessorOptions {\n logger: LoggerService;\n store: PagerDutyBackendStore;\n};\n\nexport class PagerDutyEntityProcessor implements CatalogProcessor {\n private logger: LoggerService;\n private store: PagerDutyBackendStore;\n private shouldProcessEntity: ShouldProcessEntity = (entity: Entity) => {\n return entity.kind === 'Component';\n }\n\n constructor({ logger, store }: PagerDutyEntityProcessorOptions) {\n this.logger = logger;\n this.store = store;\n }\n\n getProcessorName(): string {\n return \"PagerDutyEntityProcessor\";\n }\n\n // static fromConfig(): PagerDutyEntityProcessor {\n // return new PagerDutyEntityProcessor();\n // }\n\n async preProcessEntity(entity: Entity): Promise<Entity> {\n if (this.shouldProcessEntity(entity)) {\n this.logger.info(`Processing entity: ${entity.metadata.name}`);\n\n const mapping = await this.store.findEntityMappingByEntityRef(entity.metadata.uid!);\n\n if (mapping) {\n this.logger.info(`Found mapping for entity: ${entity.metadata.name}`);\n entity.metadata.annotations![\"pagerduty.com/service-id\"] = mapping.serviceId;\n } else {\n this.logger.info(`No mapping found for entity: ${entity.metadata.name}`);\n } \n }\n\n return entity;\n }\n}","import { resolvePackagePath } from \"@backstage/backend-plugin-api\";\nimport { Knex } from 'knex';\n\nexport type RawDbEntityResultRow = {\n id: string;\n entityRef: string;\n serviceId: string;\n processedDate?: Date;\n};\n\n/** @public */\nexport interface PagerDutyBackendStore {\n findEntityMappingByEntityRef(entityRef: string): Promise<RawDbEntityResultRow | undefined>\n}\n\nconst migrationsDir = resolvePackagePath(\"@pagerduty/backstage-plugin-backend\", \"migrations\");\n\ntype Options = {\n skipMigrations?: boolean;\n};\n\n/** @public */\nexport class PagerDutyBackendDatabase implements PagerDutyBackendStore {\n static async create(knex: Knex, options?: Options): Promise<PagerDutyBackendStore> {\n if(options?.skipMigrations) {\n await knex.migrate.latest({\n directory: migrationsDir,\n });\n }\n\n return new PagerDutyBackendDatabase(knex);\n }\n\n constructor(private readonly db: Knex) { }\n\n async findEntityMappingByEntityRef(entityRef: string): Promise<RawDbEntityResultRow | undefined> {\n const rawEntity = await this.db<RawDbEntityResultRow>('pagerduty_entity_mapping')\n .where('entityRef', entityRef)\n .first();\n\n return rawEntity;\n }\n}","import { coreServices, createBackendModule } from \"@backstage/backend-plugin-api\";\nimport { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node/alpha';\nimport { PagerDutyEntityProcessor } from \"./processor\";\nimport { PagerDutyBackendDatabase, PagerDutyBackendStore } from \"./db/PagerDutyBackendDatabase\";\n\n\n\n/** @public */\nexport const pagerDutyEntityProcessor = createBackendModule({\n pluginId: 'catalog',\n moduleId: 'pagerduty-entity-processor',\n register(env) {\n env.registerInit({\n deps: {\n logger: coreServices.logger,\n database: coreServices.database,\n catalog: catalogProcessingExtensionPoint,\n },\n async init({ logger, database, catalog }) {\n\n const store: PagerDutyBackendStore = await PagerDutyBackendDatabase.create(\n await database.getClient(),\n { skipMigrations: true },\n );\n\n catalog.addProcessor(new PagerDutyEntityProcessor({ logger, store}));\n },\n });\n },\n});\n"],"names":["resolvePackagePath","createBackend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BAAyB,CAAA,MAAA;AAAA,UAChE,MAAM,SAAS,SAAU,EAAA;AAAA,UACzB,EAAE,gBAAgB,IAAK,EAAA;AAAA,SAC3B,CAAA;AAEA,QAAA,OAAA,CAAQ,aAAa,IAAI,wBAAA,CAAyB,EAAE,MAAQ,EAAA,KAAA,EAAM,CAAC,CAAA,CAAA;AAAA,OACvE;AAAA,KACH,CAAA,CAAA;AAAA,GACL;AACJ,CAAC;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
2
2
|
|
|
3
3
|
/** @public */
|
|
4
|
-
declare const pagerDutyEntityProcessor:
|
|
4
|
+
declare const pagerDutyEntityProcessor: _backstage_backend_plugin_api.BackendFeatureCompat;
|
|
5
5
|
|
|
6
6
|
export { pagerDutyEntityProcessor as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pagerduty/backstage-plugin-entity-processor",
|
|
3
|
-
"version": "0.1.0-next.
|
|
3
|
+
"version": "0.1.0-next.3",
|
|
4
4
|
"main": "dist/index.cjs.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@backstage/backend-common": "^0.21.6",
|
|
26
26
|
"@backstage/backend-defaults": "^0.2.16",
|
|
27
|
-
"@backstage/backend-plugin-api": "^0.6.
|
|
27
|
+
"@backstage/backend-plugin-api": "^0.6.20",
|
|
28
28
|
"@backstage/config": "^1.2.0",
|
|
29
29
|
"@backstage/plugin-catalog-node": "^1.12.2",
|
|
30
|
-
"@pagerduty/backstage-plugin-common": "
|
|
30
|
+
"@pagerduty/backstage-plugin-common": "0.1.5-next.8",
|
|
31
31
|
"@rjsf/core": "^5.14.3",
|
|
32
32
|
"node-fetch": "^2.6.7",
|
|
33
33
|
"winston": "^3.2.1",
|