-
Notifications
You must be signed in to change notification settings - Fork 480
Migrate Azure Resource plugin #1856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Thanks for the contribution! |
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Signed-off-by: Kaja Hannestad <kaja.hannestad@vipps.no>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Signed-off-by: Kaja Hannestad <kaja.hannestad@vipps.no>
…ackstage#1826) Signed-off-by: Nowacki, Kacper <kacper.nowacki@dynatrace.com> Co-authored-by: Nick Boldt <nboldt@redhat.com> Signed-off-by: Kaja Hannestad <kaja.hannestad@vipps.no>
Signed-off-by: Kaja Hannestad <kaja.hannestad@vipps.no>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Signed-off-by: Kaja Hannestad <kaja.hannestad@vipps.no>
Signed-off-by: Kashish Mittal <kmittal@redhat.com> Signed-off-by: Kaja Hannestad <kaja.hannestad@vipps.no>
…ckstage#1850) Signed-off-by: Christoph Jerolimov <jerolimov+git@redhat.com> Signed-off-by: Kaja Hannestad <kaja.hannestad@vipps.no>
…namic plugin build step (backstage#1849) Signed-off-by: Christoph Jerolimov <jerolimov+git@redhat.com> Signed-off-by: Kaja Hannestad <kaja.hannestad@vipps.no>
…amic plugin build step (backstage#1848) Signed-off-by: Christoph Jerolimov <jerolimov+git@redhat.com> Signed-off-by: Kaja Hannestad <kaja.hannestad@vipps.no>
7cec930 to
d62c3fe
Compare
|
Hello @kajahanne You have to move both frontend & backend plugin in to Here is reference PR #711 |
Signed-off-by: Kaja Hannestad <kaja.hannestad@vipps.no>
…e/community-plugins into migrate-azure-resources
Signed-off-by: Kaja Hannestad <kaja.hannestad@vipps.no>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Signed-off-by: Kaja Hannestad <kaja.hannestad@vipps.no>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Signed-off-by: Kaja Hannestad <kaja.hannestad@vipps.no>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Signed-off-by: Kaja Hannestad <kaja.hannestad@vipps.no>
|
Hi @deepan10, can you give this a review please? Once you have approved I'll give it another look over. Hi @kajahanne, as @deepan10 will be helping own this plugin I'd like them to review it first, just wanting to keep you in the loop as to how the review process will work. 👍 |
|
Hello @kajahanne , Good to see the plugin (Frontend + Backend). It is good to migrate the backend plugin to align with the Also, Can you migrate |
workspaces/azure-resources/plugins/backstage-azure-resources-backend/src/service/router.ts
Outdated
Show resolved
Hide resolved
workspaces/azure-resources/plugins/backstage-azure-resources-backend/src/service/router.ts
Outdated
Show resolved
Hide resolved
workspaces/azure-resources/plugins/backstage-azure-resources-backend/README.md
Outdated
Show resolved
Hide resolved
|
This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If the PR was closed and you want it re-opened, let us know and we'll re-open the PR so that you can continue the contribution! |
Co-authored-by: Kashish Mittal <113269381+04kash@users.noreply.github.com> Signed-off-by: kajahanne <93928338+kajahanne@users.noreply.github.com>
…ackend/README.md Co-authored-by: Deepankumar <deepan0433@gmail.com> Signed-off-by: kajahanne <93928338+kajahanne@users.noreply.github.com>
…ackend/src/service/router.ts Co-authored-by: Deepankumar <deepan0433@gmail.com> Signed-off-by: kajahanne <93928338+kajahanne@users.noreply.github.com>
…ackend/src/service/router.ts Co-authored-by: Deepankumar <deepan0433@gmail.com> Signed-off-by: kajahanne <93928338+kajahanne@users.noreply.github.com>
|
Hi @kajahanne, looks like one of the commits have not been signed with the DCO, can you look into that, please? |
deepan10
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @kajahanne ,
To migrate to the new backend system add the below in to workspaces/azure-resources/plugins/backstage-azure-resoures-backend/src/plugin.ts. Also look at the review comments and DSO of your commits.
import {
coreServices,
createBackendPlugin,
} from '@backstage/backend-plugin-api';
import { createRouter } from './service/router';
/**
*
* @public
*/
export const azureResourcesPlugin = createBackendPlugin({
pluginId: 'azure-resources',
register(env) {
env.registerInit({
deps: {
httpRouter: coreServices.httpRouter,
logger: coreServices.logger,
config: coreServices.rootConfig,
},
async init({
config,
logger,
httpRouter,
}) {
httpRouter.use(
await createRouter({
config,
logger
}),
);
httpRouter.addAuthPolicy({
path: '/health',
allow: 'unauthenticated',
});
},
});
},
});Note: We need to use the createApiFactory with API Refs in frontend plugin to align with the Backstage common practices. As an initial version let the frontend call directly identityApiRef & discoveryApiRef.
| * limitations under the License. | ||
| */ | ||
|
|
||
| export * from './service/router'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| export * from './service/router'; | |
| export * from './service/router'; | |
| export {azureResourcesPlugin as default } from './plugin' |
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { errorHandler } from '@backstage/backend-common'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| import { errorHandler } from '@backstage/backend-common'; |
| import { errorHandler } from '@backstage/backend-common'; | ||
| import express from 'express'; | ||
| import Router from 'express-promise-router'; | ||
| import { Logger } from 'winston'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| import { Logger } from 'winston'; | |
| import { | |
| LoggerService, | |
| } from '@backstage/backend-plugin-api'; |
| ClientSecretCredential, | ||
| DefaultAzureCredential, | ||
| } from '@azure/identity'; | ||
| import { AzureResourceConfig } from '../config'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| import { AzureResourceConfig } from '../config'; | |
| import { MiddlewareFactory } from '@backstage/backend-defaults/rootHttpRouter'; | |
| import { AzureResourceConfig } from '../config'; |
| import { AzureResourceConfig } from '../config'; | ||
|
|
||
| export interface RouterOptions { | ||
| logger: Logger; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| logger: Logger; | |
| logger: LoggerService; |
| entity?.metadata.annotations?.[AZURE_ANNOTATION_TAG_SELECTOR] ?? '/' | ||
| ).split('/'); | ||
|
|
||
| const config = useApi(configApiRef); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| const config = useApi(configApiRef); | |
| const config = useApi(configApiRef); | |
| const identityApi = useApi(identityApiRef); |
| const response = await fetch( | ||
| `${backendUrl}/api/azure-resources/rg/${tagKey}/${tagValue}/secrecommendations`, | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| const response = await fetch( | |
| `${backendUrl}/api/azure-resources/rg/${tagKey}/${tagValue}/secrecommendations`, | |
| ); | |
| const { token: accessToken } = await identityApi.getCredentials(); | |
| const response = await fetch( | |
| `${backendUrl}/api/azure-resources/rg/${tagKey}/${tagValue}/secrecommendations`, { | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| ...(accessToken && { Authorization: `Bearer ${accessToken}` }), | |
| }, | |
| } | |
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to delete this file, since its not required
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to delete this file, Since it is not needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to delete this file, Since it is not needed.
| "main": "src/index.ts", | ||
| "types": "src/index.ts", | ||
| "license": "Apache-2.0", | ||
| "private": false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this line, Since this meant to be public.
| "private": false, |
| "main": "src/index.ts", | ||
| "types": "src/index.ts", | ||
| "license": "Apache-2.0", | ||
| "private": false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this line, Since this meant to be public.
| "private": false, |
| ``` | ||
| # From the Backstage root directory | ||
| cd packages/backend | ||
| yarn add @backstage-community/plugin-azure-resources-backend | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ``` | |
| # From the Backstage root directory | |
| cd packages/backend | |
| yarn add @backstage-community/plugin-azure-resources-backend | |
| ``` | |
| ```bash | |
| # From the Backstage root directory | |
| yarn --cwd packages/backend add @backstage-community/plugin-azure-resources-backend |
| ```TypeScript | ||
| /// ./packages/backend/src/plugins/azure-resources-backend.ts | ||
| import { createRouter } from '@backstage-community/plugin-azure-resources-backend'; | ||
| import { Router } from 'express'; | ||
| import { PluginEnvironment } from '../types'; | ||
|
|
||
| export default async function createPlugin( | ||
| env: PluginEnvironment, | ||
| ): Promise<Router> { | ||
| return await createRouter({ | ||
| logger: env.logger, | ||
| config: env.config, | ||
| }); | ||
| } | ||
| ``` | ||
|
|
||
| ```TypeScript | ||
| /// ./packages/backend/src/index.ts | ||
|
|
||
| import azureResourcesBackend from './plugins/azure-resources-backend'; | ||
| const azureResourcesBackendEnv = useHotMemoize(module, () => createEnv('azure-resources-backend')); | ||
| apiRouter.use('/azure-resources', await azureResourcesBackend(azureResourcesBackendEnv)); | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ```TypeScript | |
| /// ./packages/backend/src/plugins/azure-resources-backend.ts | |
| import { createRouter } from '@backstage-community/plugin-azure-resources-backend'; | |
| import { Router } from 'express'; | |
| import { PluginEnvironment } from '../types'; | |
| export default async function createPlugin( | |
| env: PluginEnvironment, | |
| ): Promise<Router> { | |
| return await createRouter({ | |
| logger: env.logger, | |
| config: env.config, | |
| }); | |
| } | |
| ``` | |
| ```TypeScript | |
| /// ./packages/backend/src/index.ts | |
| import azureResourcesBackend from './plugins/azure-resources-backend'; | |
| const azureResourcesBackendEnv = useHotMemoize(module, () => createEnv('azure-resources-backend')); | |
| apiRouter.use('/azure-resources', await azureResourcesBackend(azureResourcesBackendEnv)); | |
| ``` | |
| ### New Backend System | |
| This backend plugin has support for the [new backend system](https://backstage.io/docs/backend-system/), here's how you can set that up: | |
| In your `packages/backend/src/index.ts` make the following changes: | |
| ```diff | |
| import { createBackend } from '@backstage/backend-defaults'; | |
| const backend = createBackend(); | |
| // ... other feature additions | |
| +backend.add(import('@backstage-community/plugin-azure-resources-backend')); | |
| // ... | |
| backend.start(); |
|
This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If the PR was closed and you want it re-opened, let us know and we'll re-open the PR so that you can continue the contribution! |
|
hey @kajahanne gentle ping, is this still in plan to get merged? |
|
I will start fresh with a new PR, so this one can stay closed. |
Hey, I just made a Pull Request!
I raised this pull request to move the Azure Resources plugin from repos https://github.com/vippsas/backstage-azure-resources-backend and https://github.com/vippsas/backstage-azure-resource-frontend to the backstage/community-plugins repo so it is easy to manage, collaborate & improve with the Backstage community and standards.
This move also includes handing over ownership of this plugin to @deepan10.
✔️ Checklist
Signed-off-byline in the message. (more info)