Skip to content

Conversation

@kajahanne
Copy link

@kajahanne kajahanne commented Nov 6, 2024

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

  • A changeset describing the change and affected packages. (more info)
  • Added or updated documentation
  • Tests for new functionality and regression tests for bug fixes
  • Screenshots attached (for UI changes)
  • All your commits have a Signed-off-by line in the message. (more info)

@kajahanne kajahanne requested review from a team and backstage-service as code owners November 6, 2024 12:44
@kajahanne kajahanne requested a review from awanlin November 6, 2024 12:44
@backstage-goalie
Copy link
Contributor

Thanks for the contribution!
All commits need to be DCO signed before they are reviewed. Please refer to the the DCO section in CONTRIBUTING.md or the DCO status for more info.

backstage-service and others added 9 commits November 6, 2024 14:06
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>
@deepan10
Copy link
Member

deepan10 commented Nov 7, 2024

Hello @kajahanne

You have to move both frontend & backend plugin in to /workspaces/azure-resources/plugins/ directory with the default version 0.0.0 and create a changeset.

Here is reference PR #711

kajahanne and others added 7 commits November 11, 2024 10:52
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>
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>
@awanlin
Copy link
Contributor

awanlin commented Nov 13, 2024

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. 👍

@deepan10
Copy link
Member

Hello @kajahanne ,

Good to see the plugin (Frontend + Backend). It is good to migrate the backend plugin to align with the New backend system https://backstage.io/docs/backend-system/architecture/index

Also, Can you migrate packages/app and packages/backend so that it gets easier running the plugins locally?

@github-actions
Copy link
Contributor

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!

@github-actions github-actions bot added the stale label Dec 10, 2024
kajahanne and others added 4 commits December 11, 2024 11:12
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>
@github-actions github-actions bot removed the stale label Dec 11, 2024
@awanlin
Copy link
Contributor

awanlin commented Dec 17, 2024

Hi @deepan10 @04kash, looks like the requested changes have been made, can you give it another look, please? 🚀

@awanlin awanlin requested review from 04kash and deepan10 December 20, 2024 13:09
@awanlin
Copy link
Contributor

awanlin commented Dec 20, 2024

Hi @kajahanne, looks like one of the commits have not been signed with the DCO, can you look into that, please?

Copy link
Member

@deepan10 deepan10 left a 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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export * from './service/router';
export * from './service/router';
export {azureResourcesPlugin as default } from './plugin'

* limitations under the License.
*/

import { errorHandler } from '@backstage/backend-common';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { Logger } from 'winston';
import {
LoggerService,
} from '@backstage/backend-plugin-api';

ClientSecretCredential,
DefaultAzureCredential,
} from '@azure/identity';
import { AzureResourceConfig } from '../config';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { AzureResourceConfig } from '../config';
import { MiddlewareFactory } from '@backstage/backend-defaults/rootHttpRouter';
import { AzureResourceConfig } from '../config';

import { AzureResourceConfig } from '../config';

export interface RouterOptions {
logger: Logger;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger: Logger;
logger: LoggerService;

entity?.metadata.annotations?.[AZURE_ANNOTATION_TAG_SELECTOR] ?? '/'
).split('/');

const config = useApi(configApiRef);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const config = useApi(configApiRef);
const config = useApi(configApiRef);
const identityApi = useApi(identityApiRef);

Comment on lines +60 to +62
const response = await fetch(
`${backendUrl}/api/azure-resources/rg/${tagKey}/${tagValue}/secrecommendations`,
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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}` }),
},
}
);

Copy link
Member

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

Copy link
Member

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.

Copy link
Member

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,
Copy link
Member

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.

Suggested change
"private": false,

"main": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"private": false,
Copy link
Member

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.

Suggested change
"private": false,

Comment on lines +9 to +13
```
# From the Backstage root directory
cd packages/backend
yarn add @backstage-community/plugin-azure-resources-backend
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```
# 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

Comment on lines +15 to +37
```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));
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```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();

@github-actions
Copy link
Contributor

github-actions bot commented Jan 5, 2025

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!

@github-actions github-actions bot added the stale label Jan 5, 2025
@github-actions github-actions bot closed this Jan 13, 2025
@Sarabadu
Copy link
Contributor

hey @kajahanne gentle ping, is this still in plan to get merged?

@kajahanne
Copy link
Author

I will start fresh with a new PR, so this one can stay closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants