@pagerduty/backstage-plugin-entity-processor 0.1.0-next.7 → 0.1.0-next.9
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 +3 -1
- package/dist/index.cjs.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -30,8 +30,10 @@ class PagerDutyEntityProcessor {
|
|
|
30
30
|
async postProcessEntity(entity) {
|
|
31
31
|
if (this.shouldProcessEntity(entity)) {
|
|
32
32
|
this.logger.info(`Processing entity: ${JSON.stringify(entity)}`);
|
|
33
|
+
const entityRef = `${entity.kind}:${entity.metadata.namespace}/${entity.metadata.name}`.toLowerCase();
|
|
34
|
+
this.logger.info(`Looking for entity mapping with ref: ${entityRef}`);
|
|
33
35
|
try {
|
|
34
|
-
const mapping = await this.store.findEntityMappingByEntityRef(
|
|
36
|
+
const mapping = await this.store.findEntityMappingByEntityRef(entityRef);
|
|
35
37
|
if (mapping) {
|
|
36
38
|
this.logger.info(`Found mapping for entity: ${entity.metadata.name}`);
|
|
37
39
|
entity.metadata.annotations["pagerduty.com/service-id"] = mapping.serviceId;
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 postProcessEntity(entity: Entity): Promise<Entity> {\n if (this.shouldProcessEntity(entity)) {\n this.logger.info(`Processing entity: ${JSON.stringify(entity)}`);\n\n try{\n const mapping = await this.store.findEntityMappingByEntityRef(
|
|
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 postProcessEntity(entity: Entity): Promise<Entity> {\n if (this.shouldProcessEntity(entity)) {\n this.logger.info(`Processing entity: ${JSON.stringify(entity)}`);\n\n const entityRef = `${entity.kind}:${entity.metadata.namespace}/${entity.metadata.name}`.toLowerCase();\n this.logger.info(`Looking for entity mapping with ref: ${entityRef}`);\n \n try{\n const mapping = await this.store.findEntityMappingByEntityRef(entityRef);\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 } catch (error) {\n this.logger.error(`Error processing entity: ${entity.metadata.name}`);\n this.logger.error(JSON.stringify(error));\n } \n }\n\n return entity;\n }\n}","import { 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\n\n/** @public */\nexport class PagerDutyBackendDatabase implements PagerDutyBackendStore {\n static async create(knex: Knex): Promise<PagerDutyBackendStore> {\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 );\n\n catalog.addProcessor(new PagerDutyEntityProcessor({ logger, store}));\n },\n });\n },\n});\n"],"names":["createBackendModule","coreServices","catalogProcessingExtensionPoint"],"mappings":";;;;;;;;;;;;;AAgBO,MAAM,wBAAqD,CAAA;AAAA,EAO9D,WAAY,CAAA,EAAE,MAAQ,EAAA,KAAA,EAA0C,EAAA;AANhE,IAAQ,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA,CAAA;AACR,IAAQ,aAAA,CAAA,IAAA,EAAA,OAAA,CAAA,CAAA;AACR,IAAQ,aAAA,CAAA,IAAA,EAAA,qBAAA,EAA2C,CAAC,MAAmB,KAAA;AACnE,MAAA,OAAO,OAAO,IAAS,KAAA,WAAA,CAAA;AAAA,KAC3B,CAAA,CAAA;AAGI,IAAA,IAAA,CAAK,MAAS,GAAA,MAAA,CAAA;AACd,IAAA,IAAA,CAAK,KAAQ,GAAA,KAAA,CAAA;AAAA,GACjB;AAAA,EAEA,gBAA2B,GAAA;AACvB,IAAO,OAAA,0BAAA,CAAA;AAAA,GACX;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,kBAAkB,MAAiC,EAAA;AACrD,IAAI,IAAA,IAAA,CAAK,mBAAoB,CAAA,MAAM,CAAG,EAAA;AAClC,MAAA,IAAA,CAAK,OAAO,IAAK,CAAA,CAAA,mBAAA,EAAsB,KAAK,SAAU,CAAA,MAAM,CAAC,CAAE,CAAA,CAAA,CAAA;AAE/D,MAAA,MAAM,SAAY,GAAA,CAAA,EAAG,MAAO,CAAA,IAAI,CAAI,CAAA,EAAA,MAAA,CAAO,QAAS,CAAA,SAAS,CAAI,CAAA,EAAA,MAAA,CAAO,QAAS,CAAA,IAAI,GAAG,WAAY,EAAA,CAAA;AACpG,MAAA,IAAA,CAAK,MAAO,CAAA,IAAA,CAAK,CAAwC,qCAAA,EAAA,SAAS,CAAE,CAAA,CAAA,CAAA;AAEpE,MAAG,IAAA;AACC,QAAA,MAAM,OAAU,GAAA,MAAM,IAAK,CAAA,KAAA,CAAM,6B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