scaffolder-backend: add InternalTaskSecrets
Signed-off-by: Vincenzo Scamporlino <vincenzos@spotify.com>
This commit is contained in:
@@ -28,7 +28,7 @@ import {
|
||||
TaskCompletionState,
|
||||
TaskContext,
|
||||
} from '@backstage/plugin-scaffolder-node';
|
||||
import { TaskStore } from './types';
|
||||
import { InternalTaskSecrets, TaskStore } from './types';
|
||||
import { readDuration } from './helper';
|
||||
import {
|
||||
AuthService,
|
||||
@@ -179,8 +179,10 @@ export class TaskManager implements TaskContext {
|
||||
}
|
||||
|
||||
async getInitiatorCredentials(): Promise<BackstageCredentials> {
|
||||
if (this.task.secrets && this.task.secrets.initiatorCredentials) {
|
||||
return JSON.parse(this.task.secrets.initiatorCredentials);
|
||||
const secrets = this.task.secrets as InternalTaskSecrets;
|
||||
|
||||
if (secrets && secrets.__initiatorCredentials) {
|
||||
return JSON.parse(secrets.__initiatorCredentials);
|
||||
}
|
||||
if (!this.auth) {
|
||||
throw new Error(
|
||||
|
||||
@@ -228,3 +228,10 @@ export type TaskTrackType = {
|
||||
action: TemplateAction<JsonObject>,
|
||||
) => Promise<void>;
|
||||
};
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type InternalTaskSecrets = TaskSecrets & {
|
||||
__initiatorCredentials: string;
|
||||
};
|
||||
|
||||
@@ -88,6 +88,7 @@ import {
|
||||
IdentityApi,
|
||||
IdentityApiGetIdentityRequest,
|
||||
} from '@backstage/plugin-auth-node';
|
||||
import { InternalTaskSecrets } from '../scaffolder/tasks/types';
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -523,14 +524,16 @@ export async function createRouter(
|
||||
},
|
||||
};
|
||||
|
||||
const secrets: InternalTaskSecrets = {
|
||||
...req.body.secrets,
|
||||
backstageToken: token,
|
||||
__initiatorCredentials: JSON.stringify(credentials),
|
||||
};
|
||||
|
||||
const result = await taskBroker.dispatch({
|
||||
spec: taskSpec,
|
||||
createdBy: userEntityRef,
|
||||
secrets: {
|
||||
...req.body.secrets,
|
||||
backstageToken: token,
|
||||
initiatorCredentials: JSON.stringify(credentials),
|
||||
},
|
||||
secrets,
|
||||
});
|
||||
|
||||
res.status(201).json({ id: result.taskId });
|
||||
|
||||
Reference in New Issue
Block a user