Fix user entity not being fetched for scaffolder dry runner
Signed-off-by: Stephen Glass <stephen@stephen.glass>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder-backend': patch
|
||||
---
|
||||
|
||||
Fix user entity not being fetched for scaffolder dry runner
|
||||
@@ -38,12 +38,17 @@ import {
|
||||
BackstageCredentials,
|
||||
resolveSafeChildPath,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import type { UserEntity } from '@backstage/catalog-model';
|
||||
|
||||
interface DryRunInput {
|
||||
spec: TaskSpec;
|
||||
secrets?: TaskSecrets;
|
||||
directoryContents: SerializedFile[];
|
||||
credentials: BackstageCredentials;
|
||||
user?: {
|
||||
entity?: UserEntity;
|
||||
ref?: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface DryRunResult {
|
||||
|
||||
@@ -691,6 +691,34 @@ data: {"id":1,"taskId":"a-random-id","type":"completion","createdAt":"","body":{
|
||||
expect(subscriber!.closed).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /v2/dry-run', () => {
|
||||
it('should get user entity', async () => {
|
||||
const mockToken = mockCredentials.user.token();
|
||||
const mockTemplate = getMockTemplate();
|
||||
|
||||
const catalogSpy = jest.spyOn(catalogClient, 'getEntityByRef');
|
||||
|
||||
await request(app)
|
||||
.post('/v2/dry-run')
|
||||
.set('Authorization', `Bearer ${mockToken}`)
|
||||
.send({
|
||||
template: mockTemplate,
|
||||
values: {
|
||||
requiredParameter1: 'required-value-1',
|
||||
requiredParameter2: 'required-value-2',
|
||||
},
|
||||
directoryContents: [],
|
||||
});
|
||||
|
||||
expect(catalogSpy).toHaveBeenCalledTimes(1);
|
||||
|
||||
expect(catalogSpy).toHaveBeenCalledWith(
|
||||
'user:default/mock',
|
||||
expect.anything(),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('providing an identity api', () => {
|
||||
|
||||
@@ -730,6 +730,14 @@ export async function createRouter(
|
||||
targetPluginId: 'catalog',
|
||||
});
|
||||
|
||||
const userEntityRef = auth.isPrincipal(credentials, 'user')
|
||||
? credentials.principal.userEntityRef
|
||||
: undefined;
|
||||
|
||||
const userEntity = userEntityRef
|
||||
? await catalogClient.getEntityByRef(userEntityRef, { token })
|
||||
: undefined;
|
||||
|
||||
for (const parameters of [template.spec.parameters ?? []].flat()) {
|
||||
const result = validate(body.values, parameters);
|
||||
if (!result.valid) {
|
||||
@@ -750,6 +758,10 @@ export async function createRouter(
|
||||
steps,
|
||||
output: template.spec.output ?? {},
|
||||
parameters: body.values as JsonObject,
|
||||
user: {
|
||||
entity: userEntity as UserEntity,
|
||||
ref: userEntityRef,
|
||||
},
|
||||
},
|
||||
directoryContents: (body.directoryContents ?? []).map(file => ({
|
||||
path: file.path,
|
||||
|
||||
Reference in New Issue
Block a user