Skip to content

Commit

Permalink
Merge pull request #1569 from RoadieHQ/add-gravitar-plugin
Browse files Browse the repository at this point in the history
add gravatar catalog processor
  • Loading branch information
punkle authored Aug 26, 2024
2 parents 15316ef + a336282 commit 8e1c44b
Show file tree
Hide file tree
Showing 11 changed files with 189 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@roadiehq/rag-ai-backend-embeddings-openai": "^0.2.7",
"@roadiehq/rag-ai-backend-retrieval-augmenter": "^0.3.7",
"@roadiehq/rag-ai-storage-pgvector": "^0.1.5",
"@roadiehq/catalog-backend-module-gravatar": "^1.0.0",
"@roadiehq/scaffolder-backend-module-http-request": "^4.3.2",
"@roadiehq/scaffolder-backend-module-utils": "^2.0.0",
"@roadiehq/scaffolder-backend-module-aws": "^2.4.24",
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/plugins/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
} from '@roadiehq/catalog-backend-module-aws';
import { OktaOrgEntityProvider } from '@roadiehq/catalog-backend-module-okta';
import { Duration } from 'luxon';
import { GravatarProcessor } from '@roadiehq/catalog-backend-module-gravatar';

export default async function createPlugin(
env: PluginEnvironment,
Expand Down Expand Up @@ -99,6 +100,7 @@ export default async function createPlugin(
}
}

builder.addProcessor(new GravatarProcessor());
builder.addProcessor(new ScaffolderEntitiesProcessor());

const { processingEngine, router } = await builder.build();
Expand Down
17 changes: 17 additions & 0 deletions plugins/backend/catalog-backend-module-gravitar/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright 2022 Larder Software Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

module.exports = require('@backstage/cli/config/eslint-factory')(__dirname);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @roadiehq/catalog-backend-module-gravatar
9 changes: 9 additions & 0 deletions plugins/backend/catalog-backend-module-gravitar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Catalog Backend Module for Gravatar

The `@roadiehq/catalog-backend-module-gravatar` package provides a custom Backstage catalog processor that automatically adds a Gravatar profile picture to `User` entities in the Backstage catalog. The processor computes the Gravatar URL based on the user's email address and populates the `spec.profile.picture` field with this URL.

## Features

- **Automatic Gravatar URL Generation**: The processor generates a Gravatar URL for each user based on their email address using the MD5 hash.
- **Profile Picture Population**: The generated Gravatar URL is added to the `spec.profile.picture` field of `User` entities.
- **Seamless Integration**: This processor integrates easily with the Backstage catalog processing pipeline.
17 changes: 17 additions & 0 deletions plugins/backend/catalog-backend-module-gravitar/config.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright 2021 Larder Software Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export interface Config {}
56 changes: 56 additions & 0 deletions plugins/backend/catalog-backend-module-gravitar/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"name": "@roadiehq/catalog-backend-module-gravatar",
"description": "A set of Backstage catalog providers for gravatar",
"version": "1.0.0",
"main": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"exports": {
".": "./src/index.ts",
"./package.json": "./package.json"
},
"backstage": {
"role": "backend-plugin-module"
},
"homepage": "https://roadie.io",
"repository": {
"type": "git",
"url": "https://github.com/RoadieHQ/roadie-backstage-plugins",
"directory": "plugins/catalog-backend-module-gravatar"
},
"keywords": [
"backstage"
],
"scripts": {
"build": "backstage-cli package build",
"lint": "backstage-cli package lint",
"test": "backstage-cli package test",
"prepack": "backstage-cli package prepack",
"postpack": "backstage-cli package postpack",
"clean": "backstage-cli package clean",
"start": "backstage-cli package start"
},
"dependencies": {
"@backstage/backend-common": "^0.21.7",
"@backstage/catalog-client": "^1.6.4",
"@backstage/backend-plugin-api": "^0.6.17",
"@backstage/backend-tasks": "^0.5.22",
"@backstage/catalog-model": "^1.4.5",
"@backstage/config": "^1.2.0",
"@backstage/errors": "^1.2.4",
"@backstage/plugin-catalog-backend": "^1.21.1",
"@backstage/plugin-catalog-node": "^1.11.1",
"@backstage/types": "^1.1.1",
"winston": "^3.2.1"
},
"devDependencies": {
"@backstage/cli": "^0.26.4",
"@types/lodash": "^4.14.151",
"yaml": "^2.2.2"
},
"files": [
"dist",
"config.d.ts"
],
"configSchema": "config.d.ts"
}
17 changes: 17 additions & 0 deletions plugins/backend/catalog-backend-module-gravitar/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright 2022 Larder Software Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export * from './processors';
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2024 Larder Software Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import crypto from 'crypto';
import { CatalogProcessor } from '@backstage/plugin-catalog-node';
import { Entity, isUserEntity } from '@backstage/catalog-model';

export class GravatarProcessor implements CatalogProcessor {
getProcessorName() {
return 'GravatarProcessor';
}

async preProcessEntity(entity: Entity) {
if (isUserEntity(entity) && entity.spec?.profile?.email) {
const email = entity.spec.profile.email.trim().toLowerCase();
const hash = crypto.createHash('md5').update(email).digest('hex');
const gravatarUrl = `https://www.gravatar.com/avatar/${hash}`;

entity.spec.profile.picture = gravatarUrl;
}

return entity;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright 2024 Larder Software Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export { GravatarProcessor } from './GravatarProcessor';
17 changes: 17 additions & 0 deletions plugins/backend/catalog-backend-module-gravitar/src/setupTests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright 2022 Larder Software Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export {};

0 comments on commit 8e1c44b

Please sign in to comment.