Skip to content
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

mta - Removed usages and references of @backstage/backend-common #1964

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions workspaces/mta/.changeset/fuzzy-lizards-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@backstage-community/backstage-plugin-catalog-backend-module-mta-entity-provider': patch
'@backstage-community/backstage-plugin-scaffolder-backend-module-mta': patch
---

Removed usages and references of `@backstage/backend-common`
7 changes: 7 additions & 0 deletions workspaces/mta/.changeset/thirty-seas-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@backstage-community/backstage-plugin-mta-backend': patch
---

Deprecated `createRouter` and its router options in favour of the new backend system.

Removed usages and references of `@backstage/backend-common`
1 change: 0 additions & 1 deletion workspaces/mta/packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"@backstage-community/backstage-plugin-catalog-backend-module-mta-entity-provider": "workspace:^",
"@backstage-community/backstage-plugin-mta-backend": "workspace:^",
"@backstage-community/backstage-plugin-scaffolder-backend-module-mta": "workspace:^",
"@backstage/backend-common": "^0.21.7",
"@backstage/backend-defaults": "^0.3.3",
"@backstage/backend-dynamic-feature-service": "^0.2.15",
"@backstage/backend-tasks": "^0.5.22",
Expand Down
8 changes: 0 additions & 8 deletions workspaces/mta/packages/backend/src/index.test.ts

This file was deleted.

25 changes: 0 additions & 25 deletions workspaces/mta/packages/backend/src/types.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@
"tsc": "tsc"
},
"dependencies": {
"@backstage/backend-common": "^0.23.3",
"@backstage/backend-dynamic-feature-service": "^0.2.15",
"@backstage/backend-plugin-api": "^0.6.18",
"@backstage/catalog-model": "^1.5.0",
"@backstage/config": "^1.2.0",
"@backstage/plugin-catalog-common": "^1.0.22",
"@backstage/plugin-catalog-node": "^1.12.4",
"openid-client": "^5.6.5",
"winston": "^3.13.0"
"openid-client": "^5.6.5"
},
"devDependencies": {
"@backstage/backend-test-utils": "^0.3.6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
createBackendModule,
} from '@backstage/backend-plugin-api';
import { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node/alpha';
import { loggerToWinstonLogger } from '@backstage/backend-common';
import { MTAProvider } from './provider/MTAEntityProvider';
/**
* A backend module that integrates with the catalog to provide MTA entities.
Expand All @@ -22,11 +21,7 @@ export const catalogModuleMtaEntityProvider = createBackendModule({
},
async init({ config, catalog, logger, scheduler }) {
catalog.addEntityProvider(
MTAProvider.newProvider(
config,
loggerToWinstonLogger(logger),
scheduler,
),
MTAProvider.newProvider(config, logger, scheduler),
);
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@ import {
EntityProvider,
EntityProviderConnection,
} from '@backstage/plugin-catalog-node';
import { Logger } from 'winston';
import { SchedulerService } from '@backstage/backend-plugin-api';
//
import { LoggerService, SchedulerService } from '@backstage/backend-plugin-api';

/**
* Provides entities from fictional frobs service.
* Provides entities from MTA service.
*/
export class MTAProvider implements EntityProvider {
private connection?: EntityProviderConnection;
private readonly config: Config;
private readonly logger: Logger;
private readonly logger: LoggerService;
private readonly scheduler: SchedulerService;

static newProvider(
config: Config,
logger: Logger,
logger: LoggerService,
scheduler: SchedulerService,
): MTAProvider {
const p = new MTAProvider(config, logger, scheduler);
Expand All @@ -31,20 +30,22 @@ export class MTAProvider implements EntityProvider {

return p;
}
/** [1] */
constructor(config: Config, logger: Logger, scheduler: SchedulerService) {

constructor(
config: Config,
logger: LoggerService,
scheduler: SchedulerService,
) {
this.config = config;
this.logger = logger;
this.scheduler = scheduler;
this.run = this.run.bind(this);
}

/** [2] */
getProviderName(): string {
return `MTAProvider`;
}

/** [3] */
async connect(connection: EntityProviderConnection): Promise<void> {
this.logger.info('connecting');
this.connection = connection;
Expand Down Expand Up @@ -83,63 +84,7 @@ export class MTAProvider implements EntityProvider {
}
}

// if (!this.connection) {
// throw new Error('Not initialized');
// }
// this.logger.info('here');
async authenticate() {
// try {
// // const baseURLAuth = `${this.config.getString(
// // 'mta.url',
// // )}/auth/realms/${this.config.getString('mta.providerAuth.realm')}`;
// const baseUrl = this.config.getString('mta.url');
// const baseUrlHub = `${baseUrl}/hub`;
// const baseUrlMta = `${baseUrl}`;
// const realm = this.config.getString('mta.providerAuth.realm');
// const clientID = this.config.getString('mta.providerAuth.clientID');
// const secret = this.config.getString('mta.providerAuth.secret');
// const baseURLAuth = `${baseUrl}/auth/realms/${realm}`;
// this.logger.info(`Discovering issuer from ${baseURLAuth}`);

// // const mtaAuthIssuer = await Issuer.discover(baseURLAuth);
// custom.setHttpOptionsDefaults({
// timeout: 5000, // Adjust the timeout to 5000ms or higher based on your requirements
// });

// try {
// const mtaAuthIssuer = await Issuer.discover(baseURLAuth);
// this.logger.info('Issuer discovered successfully');

// const authClient = new mtaAuthIssuer.Client({
// client_id: this.config.getString('mta.providerAuth.clientID'),
// client_secret: this.config.getString('mta.providerAuth.secret'),
// response_types: ['code'],
// });

// this.logger.info('Client created successfully');

// const code_verifier = generators.codeVerifier();
// const code_challenge = generators.codeChallenge(code_verifier);

// this.logger.info('Attempting to obtain grant');

// const grant = await authClient.grant({
// grant_type: 'client_credentials',
// });

// this.logger.info('Grant obtained successfully');

// return grant;
// } catch (error) {
// this.logger.error(
// `Initial discovery failed: ${error.message}, retrying...`,
// );
// // Implement retry logic here
// }
// } catch (error) {
// this.logger.error(`Authentication error: ${error.message}`);
// throw new Error(`Failed to authenticate: ${error.message}`);
// }
const baseUrl = this.config.getString('mta.url');
const realm = this.config.getString('mta.providerAuth.realm');
const clientID = this.config.getString('mta.providerAuth.clientID');
Expand Down Expand Up @@ -297,117 +242,3 @@ export class MTAProvider implements EntityProvider {
this.logger.info('Data refresh triggered for entities.');
}
}

// const getResponse = await fetch(`${baseUrlHub}/applications`, {
// credentials: 'include',
// headers: {
// Accept: 'application/json, text/plain, */*',
// Authorization: `Bearer ${tokenSet.access_token}`,
// },
// method: 'GET',
// });

// if (getResponse.status !== 200) {
// this.logger.info(
// `unable to call hub ${getResponse.status} message ${JSON.stringify(
// await getResponse.text(),
// )}`,
// );
// return;
// }
// const j = await getResponse.json();
// if (!Array.isArray(j)) {
// this.logger.info('expecting array of applications');
// return;
// }

// this.logger.info(`status: ${getResponse.status} json ${JSON.stringify(j)}`);
// mapApplicationToEntity

// await this.connection
// .applyMutation({
// type: 'full',
// entities: j.map(application => {
// const name = application.name.replace(/ /g, '-');
// const encodedAppName = encodeURIComponent(
// JSON.stringify(application.name),
// ); // Ensure the application name is URI-encoded
// const issuesUrl = `${baseUrlMta}/issues?i%3Afilters=%7B%22application.name%22%3A%5B${encodedAppName}%5D%7D&i%3AitemsPerPage=10&i%3ApageNumber=1&i%3AsortColumn=description&i%3AsortDirection=asc`;

// return {
// key: application.id,
// locationKey: this.getProviderName(),
// entity: {
// apiVersion: 'backstage.io/v1alpha1',
// kind: 'Component',
// metadata: {
// annotations: {
// 'backstage.io/managed-by-location': `url:${baseUrlMta}/application/${application.id}`,
// 'backstage.io/managed-by-origin-location': `url:${baseUrlMta}/application/${application.id}`,
// 'issues-url': `${issuesUrl}`,
// },
// name: name,
// id: application.id,
// namespace: 'default',
// application: application,
// },
// spec: {
// type: 'service',
// lifecycle: 'experimental',
// owner: 'unknown',
// },
// },
// };
// }),
// })
// .then(() => {
// console.log('REFRESHING');
// this.logger.info('refreshing');
// this.connection?.refresh({
// keys: j.map(application => application.id),
// });
// })
// .catch(e => {
// this.logger.info(`error applying mutation ${e}`);
// });
// }
// }
// const baseUrl = this.config.getString('mta.url');
// const baseUrlHub = `${baseUrl}/hub`;
// const baseUrlMta = `${baseUrl}`;
// const realm = this.config.getString('mta.providerAuth.realm');
// const clientID = this.config.getString('mta.providerAuth.clientID');
// const secret = this.config.getString('mta.providerAuth.secret');
// const baseURLAuth = `${baseUrl}/auth/realms/${realm}`;
// const mtaAuthIssuer = await Issuer.discover(baseURLAuth);
// const authClient = new mtaAuthIssuer.Client({
// client_id: clientID,
// client_secret: secret,
// response_types: ['code'],
// });
// const code_verifier = generators.codeVerifier();
// const code_challenge = generators.codeChallenge(code_verifier);

// const tokenSet = await authClient.grant({
// grant_type: 'client_credentials',
// });
// if (!tokenSet.access_token) {
// this.logger.info('unable to access hub');
// }

// console.log({
// code_verifier,
// code_challenge,
// tokenSet,
// baseURLAuth,
// baseUrlHub,
// });

// this.logger.info({
// code_verifier,
// code_challenge,
// tokenSet,
// baseURLAuth,
// baseUrlHub,
// });
// }
16 changes: 8 additions & 8 deletions workspaces/mta/plugins/mta-backend/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@
```ts

import { BackendFeatureCompat } from '@backstage/backend-plugin-api';
import { CacheService } from '@backstage/backend-plugin-api';
import { Config } from '@backstage/config';
import { DatabaseService } from '@backstage/backend-plugin-api';
import express from 'express';
import { HttpAuthService } from '@backstage/backend-plugin-api';
import { Logger } from 'winston';
import { PluginCacheManager } from '@backstage/backend-common';
import { PluginDatabaseManager } from '@backstage/backend-common';
import { LoggerService } from '@backstage/backend-plugin-api';
import { UserInfoService } from '@backstage/backend-plugin-api';

// @public (undocumented)
// @public @deprecated (undocumented)
export function createRouter(options: RouterOptions): Promise<express.Router>;

// @public (undocumented)
const mtaPlugin: BackendFeatureCompat;
export default mtaPlugin;

// @public (undocumented)
// @public @deprecated (undocumented)
export interface RouterOptions {
// (undocumented)
cache: PluginCacheManager;
cache: CacheService;
// (undocumented)
config: Config;
// (undocumented)
database: PluginDatabaseManager;
database: DatabaseService;
// (undocumented)
httpAuth: HttpAuthService;
// (undocumented)
logger: Logger;
logger: LoggerService;
// (undocumented)
userInfo: UserInfoService;
}
Expand Down
4 changes: 1 addition & 3 deletions workspaces/mta/plugins/mta-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"tsc": "tsc"
},
"dependencies": {
"@backstage/backend-common": "^0.23.3",
"@backstage/backend-defaults": "^0.5.0",
"@backstage/backend-dynamic-feature-service": "^0.2.15",
"@backstage/backend-plugin-api": "^0.8.0",
"@backstage/config": "^1.2.0",
Expand All @@ -46,11 +46,9 @@
"knex": "^3.1.0",
"node-fetch": "^2.6.7",
"openid-client": "^5.6.4",
"winston": "^3.2.1",
"yn": "^4.0.0"
},
"devDependencies": {
"@backstage/backend-defaults": "^0.5.0",
"@backstage/cli": "^0.26.11",
"@backstage/plugin-auth-backend": "^0.23.0",
"@backstage/plugin-auth-backend-module-guest-provider": "^0.2.0",
Expand Down
Loading
Loading