-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1569 from RoadieHQ/add-gravitar-plugin
add gravatar catalog processor
- Loading branch information
Showing
11 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
plugins/backend/catalog-backend-module-gravitar/.eslintrc.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# @roadiehq/catalog-backend-module-gravatar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
17
plugins/backend/catalog-backend-module-gravitar/config.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
56
plugins/backend/catalog-backend-module-gravitar/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
17
plugins/backend/catalog-backend-module-gravitar/src/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
36 changes: 36 additions & 0 deletions
36
plugins/backend/catalog-backend-module-gravitar/src/processors/GravatarProcessor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
plugins/backend/catalog-backend-module-gravitar/src/processors/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
17
plugins/backend/catalog-backend-module-gravitar/src/setupTests.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {}; |