Skip to content

Commit

Permalink
feat(slack): Support new backend system (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolaik committed Apr 10, 2024
1 parent 66f86b1 commit f4e20db
Show file tree
Hide file tree
Showing 6 changed files with 470 additions and 8 deletions.
8 changes: 8 additions & 0 deletions plugins/slack-catalog-backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ Enriches existing `User` entities with information from Slack, notably the user'

#### Installation

Add the following to your `packages/backend/index.ts`:

```ts
backend.add(import('@seatgeek/backstage-plugin-slack-catalog-backend'));
```

##### Legacy backend system

Add the following to your `packages/backend/catalog.ts`:

```ts
Expand Down
2 changes: 2 additions & 0 deletions plugins/slack-catalog-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
},
"dependencies": {
"@backstage/backend-common": "^0.20.1",
"@backstage/backend-plugin-api": "^0.6.16",
"@backstage/catalog-model": "^1.4.3",
"@backstage/config": "^1.1.1",
"@backstage/plugin-catalog-common": "^1.0.20",
"@backstage/plugin-catalog-node": "^1.11.0",
"@slack/web-api": "^7.0.2",
"winston": "^3.2.1"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { SystemEntity, UserEntity } from '@backstage/catalog-model';
import { WebClient } from '@slack/web-api';
import * as winston from 'winston';

import { SlackUserProcessor } from './SlackUserProcessor';

jest.mock('@slack/web-api', () => {
Expand Down
1 change: 1 addition & 0 deletions plugins/slack-catalog-backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
* Licensed under the terms of the Apache-2.0 license. See LICENSE file in project root for terms.
*/
export { SlackUserProcessor } from './SlackUserProcessor';
export { catalogModuleSlackUserProcessor as default } from './module';
43 changes: 43 additions & 0 deletions plugins/slack-catalog-backend/src/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright SeatGeek
* Licensed under the terms of the Apache-2.0 license. See LICENSE file in project root for terms.
*/
import { loggerToWinstonLogger } from '@backstage/backend-common';
import {
coreServices,
createBackendModule,
} from '@backstage/backend-plugin-api';
import { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node/alpha';
import { WebClient } from '@slack/web-api';

import { SlackUserProcessor } from './SlackUserProcessor';

export const catalogModuleSlackUserProcessor = createBackendModule({
pluginId: 'catalog', // name of the plugin that the module is targeting
moduleId: 'slack-catalog-backend',
register(env) {
env.registerInit({
deps: {
catalog: catalogProcessingExtensionPoint,
logger: coreServices.logger,
config: coreServices.rootConfig,
},
async init({ catalog, logger, config }) {
// Log warning if no token is set
const slackToken = config.getOptionalString('slackCatalog.token');
if (!slackToken) {
logger.warn(
'No token provided for SlackUserProcessor, skipping Slack user lookup',
);
return;
}
catalog.addProcessor(
new SlackUserProcessor(
new WebClient(slackToken),
loggerToWinstonLogger(logger),
),
);
},
});
},
});
Loading

0 comments on commit f4e20db

Please sign in to comment.