chore: fix up to work with the other code

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2022-05-11 11:40:20 +02:00
parent eb0f2f1a5e
commit eb7c53a005
7 changed files with 10 additions and 61 deletions
@@ -1,38 +0,0 @@
/*
* Copyright 2020 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// @ts-check
/**
* @param {import('knex').Knex} knex
*/
exports.up = async function up(knex) {
await knex.schema.alterTable('tasks', table => {
table
.text('created_by')
.nullable()
.comment('an entity ref of the user that created the task');
});
};
/**
* @param {import('knex').Knex} knex
*/
exports.down = async function down(knex) {
await knex.schema.alterTable('tasks', table => {
table.dropColumn('created_by');
});
};
@@ -100,7 +100,7 @@ export class DatabaseTaskStore implements TaskStore {
id: result.id,
spec: JSON.parse(result.spec),
status: result.status,
createdBy: result.created_by,
createdBy: result.created_by ?? undefined,
lastHeartbeatAt:
typeof result.last_heartbeat_at === 'string'
? DateTime.fromSQL(result.last_heartbeat_at, {
@@ -156,8 +156,6 @@ export class DatabaseTaskStore implements TaskStore {
secrets: options.secrets ? JSON.stringify(options.secrets) : undefined,
created_by: options.createdBy ?? null,
status: 'open',
created_by:
('createdBy' in options.spec && options.spec.createdBy) || null,
});
return { taskId };
}
@@ -15,6 +15,7 @@
*/
import { getVoidLogger, DatabaseManager } from '@backstage/backend-common';
import { UserEntity } from '@backstage/catalog-model';
import { ConfigReader } from '@backstage/config';
import { TaskSpec } from '@backstage/plugin-scaffolder-common';
import { DatabaseTaskStore } from './DatabaseTaskStore';
@@ -220,7 +221,9 @@ describe('StorageTaskBroker', () => {
it('should list only tasks createdBy a specific user', async () => {
const broker = new StorageTaskBroker(storage, logger);
const { taskId } = await broker.dispatch({
spec: { createdBy: 'user:default/foo' } as TaskSpec,
spec: {
user: { ref: 'user:default/foo', entity: {} as UserEntity },
} as TaskSpec,
});
const task = await storage.getTask(taskId);
@@ -49,7 +49,6 @@ export type SerializedTask = {
lastHeartbeatAt?: string;
createdBy?: string;
secrets?: TaskSecrets;
createdBy: string | null;
};
/**
@@ -129,19 +129,6 @@ export async function createRouter(
actionsToRegister.forEach(action => actionRegistry.register(action));
workers.forEach(worker => worker.start());
const getUserEntityRefFromToken = (backstageToken: string) => {
try {
const [_header, payload, _signature] = backstageToken.split('.');
const parsedToken = JSON.parse(Buffer.from(payload, 'base64').toString());
return parsedToken.sub;
} catch (e) {
logger.warn('Could not parse token from request to create template');
logger.debug(e);
return null;
}
};
router
.get(
'/v2/templates/:namespace/:kind/:name/parameter-schema',
@@ -220,8 +207,6 @@ export async function createRouter(
const baseUrl = getEntityBaseUrl(template);
const createdBy = token && getUserEntityRefFromToken(token);
const taskSpec: TaskSpec = {
apiVersion: template.apiVersion,
steps: template.spec.steps.map((step, index) => ({
@@ -243,7 +228,6 @@ export async function createRouter(
}),
baseUrl,
},
createdBy,
};
const result = await taskBroker.dispatch({
@@ -109,7 +109,7 @@ const ListTaskPageContent = (props: MyTaskPageProps) => {
title: 'Owner',
field: 'createdBy',
render: row => (
<OwnerEntityColumn entityRef={row.spec?.createdBy} />
<OwnerEntityColumn entityRef={row.spec?.user?.ref} />
),
},
{
@@ -39,7 +39,10 @@ export const OwnerEntityColumn = ({ entityRef }: { entityRef?: string }) => {
return (
<Link to={catalogEntityRoute(parseEntityRef(entityRef || ''))}>
<ListItemText
primary={(value as UserEntity)?.spec?.profile?.displayName}
primary={
(value as UserEntity)?.spec?.profile?.displayName ??
value?.metadata.name
}
/>
</Link>
);