added credentials field to LocationAnalyzer's analyzeLocation method
Signed-off-by: Kashish Mittal <kmittal@redhat.com>
This commit is contained in:
@@ -17,7 +17,10 @@
|
||||
import { NotAllowedError } from '@backstage/errors';
|
||||
import { catalogLocationCreatePermission } from '@backstage/plugin-catalog-common/alpha';
|
||||
import { AuthorizeResult } from '@backstage/plugin-permission-common';
|
||||
import { PermissionsService } from '@backstage/backend-plugin-api';
|
||||
import {
|
||||
BackstageCredentials,
|
||||
PermissionsService,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { LocationAnalyzer } from '@backstage/plugin-catalog-node';
|
||||
import { AnalyzeLocationRequest } from '@backstage/plugin-catalog-common';
|
||||
import { AnalyzeLocationResponse } from '@backstage/plugin-catalog-common';
|
||||
@@ -30,6 +33,7 @@ export class AuthorizedLocationAnalyzer implements LocationAnalyzer {
|
||||
|
||||
async analyzeLocation(
|
||||
request: AnalyzeLocationRequest,
|
||||
credentials: BackstageCredentials,
|
||||
): Promise<AnalyzeLocationResponse> {
|
||||
const authorizeDecision = (
|
||||
await this.permissionApi.authorize(
|
||||
@@ -38,12 +42,12 @@ export class AuthorizedLocationAnalyzer implements LocationAnalyzer {
|
||||
permission: catalogLocationCreatePermission,
|
||||
},
|
||||
],
|
||||
{ credentials: request.credentials },
|
||||
{ credentials: credentials },
|
||||
)
|
||||
)[0];
|
||||
if (authorizeDecision.result !== AuthorizeResult.ALLOW) {
|
||||
throw new NotAllowedError();
|
||||
}
|
||||
return this.service.analyzeLocation(request);
|
||||
return this.service.analyzeLocation(request, credentials);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -303,10 +303,10 @@ export async function createRouter(
|
||||
});
|
||||
const credentials = await httpAuth.credentials(req);
|
||||
const parsedBody = schema.parse(body);
|
||||
const analyzeLocationRequest = { ...parsedBody, credentials };
|
||||
try {
|
||||
const output = await locationAnalyzer.analyzeLocation(
|
||||
analyzeLocationRequest,
|
||||
parsedBody,
|
||||
credentials,
|
||||
);
|
||||
res.status(200).json(output);
|
||||
} catch (err) {
|
||||
|
||||
@@ -56,7 +56,6 @@
|
||||
"test": "backstage-cli package test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@backstage/backend-plugin-api": "workspace:^",
|
||||
"@backstage/catalog-model": "workspace:^",
|
||||
"@backstage/plugin-permission-common": "workspace:^",
|
||||
"@backstage/plugin-search-common": "workspace:^"
|
||||
|
||||
@@ -17,13 +17,11 @@
|
||||
import { LocationSpec } from '../common';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { RecursivePartial } from './RecursivePartial';
|
||||
import { BackstageCredentials } from '@backstage/backend-plugin-api';
|
||||
|
||||
/** @public */
|
||||
export type AnalyzeLocationRequest = {
|
||||
location: LocationSpec;
|
||||
catalogFilename?: string;
|
||||
credentials: BackstageCredentials;
|
||||
};
|
||||
|
||||
/** @public */
|
||||
|
||||
@@ -172,6 +172,7 @@ export type EntityRelationSpec = {
|
||||
export type LocationAnalyzer = {
|
||||
analyzeLocation(
|
||||
location: AnalyzeLocationRequest,
|
||||
credentials: BackstageCredentials
|
||||
): Promise<AnalyzeLocationResponse>;
|
||||
};
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
} from '@backstage/plugin-catalog-common';
|
||||
import { JsonValue } from '@backstage/types';
|
||||
import { CatalogProcessorEmit } from '../api';
|
||||
import { BackstageCredentials } from '@backstage/backend-plugin-api';
|
||||
|
||||
/**
|
||||
* Entities that are not yet processed.
|
||||
@@ -66,6 +67,7 @@ export type LocationAnalyzer = {
|
||||
*/
|
||||
analyzeLocation(
|
||||
location: AnalyzeLocationRequest,
|
||||
credentials: BackstageCredentials,
|
||||
): Promise<AnalyzeLocationResponse>;
|
||||
};
|
||||
|
||||
|
||||
@@ -5742,7 +5742,6 @@ __metadata:
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@backstage/plugin-catalog-common@workspace:plugins/catalog-common"
|
||||
dependencies:
|
||||
"@backstage/backend-plugin-api": "workspace:^"
|
||||
"@backstage/catalog-model": "workspace:^"
|
||||
"@backstage/cli": "workspace:^"
|
||||
"@backstage/plugin-permission-common": "workspace:^"
|
||||
|
||||
Reference in New Issue
Block a user