From 800a2b6e80bb704f8f30452850da5b0676eebd22 Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 3 Mar 2022 17:20:59 +0100 Subject: [PATCH] chore: removal of the deprecations Signed-off-by: blam --- plugins/scaffolder-common/src/TaskSpec.ts | 37 +--- .../src/Template.v1beta2.schema.json | 182 ------------------ .../src/TemplateEntityV1beta2.test.ts | 161 ---------------- .../src/TemplateEntityV1beta2.ts | 65 ------- plugins/scaffolder-common/src/index.ts | 2 - 5 files changed, 1 insertion(+), 446 deletions(-) delete mode 100644 plugins/scaffolder-common/src/Template.v1beta2.schema.json delete mode 100644 plugins/scaffolder-common/src/TemplateEntityV1beta2.test.ts delete mode 100644 plugins/scaffolder-common/src/TemplateEntityV1beta2.ts diff --git a/plugins/scaffolder-common/src/TaskSpec.ts b/plugins/scaffolder-common/src/TaskSpec.ts index 2c7eb26d5b..326bb60ef6 100644 --- a/plugins/scaffolder-common/src/TaskSpec.ts +++ b/plugins/scaffolder-common/src/TaskSpec.ts @@ -16,17 +16,6 @@ import { JsonValue, JsonObject } from '@backstage/types'; -/** - * Metadata about the Template that was the originator of a scaffolder task, as - * stored in the database. - * - * @public - * @deprecated use templateInfo on the spec instead - */ -export type TemplateMetadata = { - name: string; -}; - /** * Information about a template that is stored on a task specification. * Includes a stringified entityRef, and the baseUrl which is usually the relative path of the template definition @@ -51,26 +40,6 @@ export interface TaskStep { if?: string | boolean; } -/** - * A scaffolder task as stored in the database, generated from a v1beta2 - * apiVersion Template. - * - * @public - * @deprecated Please convert your templates to TaskSpecV1beta3 on apiVersion - * scaffolder.backstage.io/v1beta3 - */ -export interface TaskSpecV1beta2 { - apiVersion: 'backstage.io/v1beta2'; - /** @deprecated use templateInfo.baseUrl instead */ - baseUrl?: string; - values: JsonObject; - steps: TaskStep[]; - output: { [name: string]: string }; - /** @deprecated use templateInfo instead */ - metadata?: TemplateMetadata; - templateInfo?: TemplateInfo; -} - /** * A scaffolder task as stored in the database, generated from a v1beta3 * apiVersion Template. @@ -79,13 +48,9 @@ export interface TaskSpecV1beta2 { */ export interface TaskSpecV1beta3 { apiVersion: 'scaffolder.backstage.io/v1beta3'; - /** @deprecated use templateInfo.baseUrl instead */ - baseUrl?: string; parameters: JsonObject; steps: TaskStep[]; output: { [name: string]: JsonValue }; - /** @deprecated use templateInfo instead */ - metadata?: TemplateMetadata; templateInfo?: TemplateInfo; } @@ -94,4 +59,4 @@ export interface TaskSpecV1beta3 { * * @public */ -export type TaskSpec = TaskSpecV1beta2 | TaskSpecV1beta3; +export type TaskSpec = TaskSpecV1beta3; diff --git a/plugins/scaffolder-common/src/Template.v1beta2.schema.json b/plugins/scaffolder-common/src/Template.v1beta2.schema.json deleted file mode 100644 index d68eac936d..0000000000 --- a/plugins/scaffolder-common/src/Template.v1beta2.schema.json +++ /dev/null @@ -1,182 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema", - "$id": "TemplateV1beta2", - "description": "A Template describes a scaffolding task for use with the Scaffolder. It describes the required parameters as well as a series of steps that will be taken to execute the scaffolding task.", - "examples": [ - { - "apiVersion": "backstage.io/v1beta2", - "kind": "Template", - "metadata": { - "name": "react-ssr-template", - "title": "React SSR Template", - "description": "Next.js application skeleton for creating isomorphic web applications.", - "tags": ["recommended", "react"] - }, - "spec": { - "owner": "artist-relations-team", - "type": "website", - "parameters": { - "required": ["name", "description"], - "properties": { - "name": { - "title": "Name", - "type": "string", - "description": "Unique name of the component" - }, - "description": { - "title": "Description", - "type": "string", - "description": "Description of the component" - } - } - }, - "steps": [ - { - "id": "fetch", - "name": "Fetch", - "action": "fetch:plain", - "parameters": { - "url": "./template" - } - }, - { - "id": "publish", - "name": "Publish to GitHub", - "action": "publish:github", - "parameters": { - "repoUrl": "{{ parameters.repoUrl }}" - }, - "if": "{{ parameters.repoUrl }}" - } - ], - "output": { - "catalogInfoUrl": "{{ steps.publish.output.catalogInfoUrl }}" - } - } - } - ], - "allOf": [ - { - "$ref": "Entity" - }, - { - "type": "object", - "required": ["spec"], - "properties": { - "apiVersion": { - "enum": ["backstage.io/v1beta2"] - }, - "kind": { - "enum": ["Template"] - }, - "spec": { - "type": "object", - "required": ["type", "steps"], - "properties": { - "type": { - "type": "string", - "description": "The type of component created by the template. The software catalog accepts any type value, but an organization should take great care to establish a proper taxonomy for these. Tools including Backstage itself may read this field and behave differently depending on its value. For example, a website type component may present tooling in the Backstage interface that is specific to just websites.", - "examples": ["service", "website", "library"], - "minLength": 1 - }, - "parameters": { - "oneOf": [ - { - "type": "object", - "description": "The JSONSchema describing the inputs for the template." - }, - { - "type": "array", - "description": "A list of separate forms to collect parameters.", - "items": { - "type": "object", - "description": "The JSONSchema describing the inputs for the template." - } - } - ] - }, - "steps": { - "type": "array", - "description": "A list of steps to execute.", - "items": { - "type": "object", - "description": "A description of the step to execute.", - "required": ["action"], - "properties": { - "id": { - "type": "string", - "description": "The ID of the step, which can be used to refer to its outputs." - }, - "name": { - "type": "string", - "description": "The name of the step, which will be displayed in the UI during the scaffolding process." - }, - "action": { - "type": "string", - "description": "The name of the action to execute." - }, - "input": { - "type": "object", - "description": "A templated object describing the inputs to the action." - }, - "if": { - "type": ["string", "boolean"], - "description": "A templated condition that skips the step when evaluated to false. If the condition is true or not defined, the step is executed. The condition is true, if the input is not `false`, `undefined`, `null`, `\"\"`, `0`, or `[]`." - } - } - } - }, - "output": { - "type": "object", - "description": "A templated object describing the outputs of the scaffolding task.", - "properties": { - "links": { - "type": "array", - "description": "A list of external hyperlinks, typically pointing to resources created or updated by the template", - "items": { - "type": "object", - "required": [], - "properties": { - "url": { - "type": "string", - "description": "A url in a standard uri format.", - "examples": ["https://github.com/my-org/my-new-repo"], - "minLength": 1 - }, - "entityRef": { - "type": "string", - "description": "An entity reference to an entity in the catalog.", - "examples": ["Component:default/my-app"], - "minLength": 1 - }, - "title": { - "type": "string", - "description": "A user friendly display name for the link.", - "examples": ["View new repo"], - "minLength": 1 - }, - "icon": { - "type": "string", - "description": "A key representing a visual icon to be displayed in the UI.", - "examples": ["dashboard"], - "minLength": 1 - } - } - } - } - }, - "additionalProperties": { - "type": "string" - } - }, - "owner": { - "type": "string", - "description": "The user (or group) owner of the template", - "minLength": 1 - } - } - } - } - } - ] -} diff --git a/plugins/scaffolder-common/src/TemplateEntityV1beta2.test.ts b/plugins/scaffolder-common/src/TemplateEntityV1beta2.test.ts deleted file mode 100644 index f715f3c2b6..0000000000 --- a/plugins/scaffolder-common/src/TemplateEntityV1beta2.test.ts +++ /dev/null @@ -1,161 +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. - */ - -import { - TemplateEntityV1beta2, - templateEntityV1beta2Validator as validator, -} from './TemplateEntityV1beta2'; - -describe('templateEntityV1beta2Validator', () => { - let entity: TemplateEntityV1beta2; - - beforeEach(() => { - entity = { - apiVersion: 'backstage.io/v1beta2', - kind: 'Template', - metadata: { - name: 'test', - }, - spec: { - type: 'website', - parameters: { - required: ['storePath', 'owner'], - properties: { - owner: { - type: 'string', - title: 'Owner', - description: 'Who is going to own this component', - }, - storePath: { - type: 'string', - title: 'Store path', - description: 'GitHub store path in org/repo format', - }, - }, - }, - steps: [ - { - id: 'fetch', - name: 'Fetch', - action: 'fetch:plan', - input: { - url: './template', - }, - if: '{{ parameters.owner }}', - }, - ], - output: { - fetchUrl: '{{ steps.fetch.output.targetUrl }}', - }, - owner: 'team-b@example.com', - }, - }; - }); - - it('happy path: accepts valid data', async () => { - await expect(validator.check(entity)).resolves.toBe(true); - }); - - it('ignores unknown apiVersion', async () => { - (entity as any).apiVersion = 'backstage.io/v1beta0'; - await expect(validator.check(entity)).resolves.toBe(false); - }); - - it('ignores unknown kind', async () => { - (entity as any).kind = 'Wizard'; - await expect(validator.check(entity)).resolves.toBe(false); - }); - - it('rejects missing type', async () => { - delete (entity as any).spec.type; - await expect(validator.check(entity)).rejects.toThrow(/type/); - }); - - it('accepts any other type', async () => { - (entity as any).spec.type = 'hallo'; - await expect(validator.check(entity)).resolves.toBe(true); - }); - - it('accepts missing parameters', async () => { - delete (entity as any).spec.parameters; - await expect(validator.check(entity)).resolves.toBe(true); - }); - - it('accepts missing outputs', async () => { - delete (entity as any).spec.outputs; - await expect(validator.check(entity)).resolves.toBe(true); - }); - - it('rejects empty type', async () => { - (entity as any).spec.type = ''; - await expect(validator.check(entity)).rejects.toThrow(/type/); - }); - - it('rejects missing steps', async () => { - delete (entity as any).spec.steps; - await expect(validator.check(entity)).rejects.toThrow(/steps/); - }); - - it('accepts step with missing id', async () => { - delete (entity as any).spec.steps[0].id; - await expect(validator.check(entity)).resolves.toBe(true); - }); - - it('accepts step with missing name', async () => { - delete (entity as any).spec.steps[0].name; - await expect(validator.check(entity)).resolves.toBe(true); - }); - - it('rejects step with missing action', async () => { - delete (entity as any).spec.steps[0].action; - await expect(validator.check(entity)).rejects.toThrow(/action/); - }); - - it('accepts missing owner', async () => { - delete (entity as any).spec.owner; - await expect(validator.check(entity)).resolves.toBe(true); - }); - - it('rejects empty owner', async () => { - (entity as any).spec.owner = ''; - await expect(validator.check(entity)).rejects.toThrow(/owner/); - }); - - it('rejects wrong type owner', async () => { - (entity as any).spec.owner = 5; - await expect(validator.check(entity)).rejects.toThrow(/owner/); - }); - - it('accepts missing if', async () => { - delete (entity as any).spec.steps[0].if; - await expect(validator.check(entity)).resolves.toBe(true); - }); - - it('accepts boolean in if', async () => { - (entity as any).spec.steps[0].if = true; - await expect(validator.check(entity)).resolves.toBe(true); - }); - - it('accepts empty if', async () => { - (entity as any).spec.steps[0].if = ''; - await expect(validator.check(entity)).resolves.toBe(true); - }); - - it('rejects wrong type if', async () => { - (entity as any).spec.steps[0].if = 5; - await expect(validator.check(entity)).rejects.toThrow(/if/); - }); -}); diff --git a/plugins/scaffolder-common/src/TemplateEntityV1beta2.ts b/plugins/scaffolder-common/src/TemplateEntityV1beta2.ts deleted file mode 100644 index 280caec52f..0000000000 --- a/plugins/scaffolder-common/src/TemplateEntityV1beta2.ts +++ /dev/null @@ -1,65 +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. - */ - -import { - Entity, - entityKindSchemaValidator, - KindValidator, -} from '@backstage/catalog-model'; -import { JsonObject } from '@backstage/types'; -import schema from './Template.v1beta2.schema.json'; - -/** - * Backstage catalog Template kind Entity. Templates are used by the Scaffolder - * plugin to create new entities, such as Components. - * - * @public - * @deprecated Please convert your templates to TemplateEntityV1beta3 on - * apiVersion scaffolder.backstage.io/v1beta3 - */ -export interface TemplateEntityV1beta2 extends Entity { - apiVersion: 'backstage.io/v1beta2'; - kind: 'Template'; - spec: { - type: string; - parameters?: JsonObject | JsonObject[]; - steps: Array<{ - id?: string; - name?: string; - action: string; - input?: JsonObject; - if?: string | boolean; - }>; - output?: { [name: string]: string }; - owner?: string; - }; -} - -const validator = entityKindSchemaValidator(schema); - -/** - * Entity data validator for {@link TemplateEntityV1beta2}. - * - * @public - * @deprecated Please convert your templates to TemplateEntityV1beta3 on - * apiVersion scaffolder.backstage.io/v1beta3 - */ -export const templateEntityV1beta2Validator: KindValidator = { - // TODO(freben): Emulate the old KindValidator until we fix that type - async check(data: Entity) { - return validator(data) === data; - }, -}; diff --git a/plugins/scaffolder-common/src/index.ts b/plugins/scaffolder-common/src/index.ts index e74a5f988f..521e678ab6 100644 --- a/plugins/scaffolder-common/src/index.ts +++ b/plugins/scaffolder-common/src/index.ts @@ -21,7 +21,5 @@ */ export * from './TaskSpec'; -export { templateEntityV1beta2Validator } from './TemplateEntityV1beta2'; -export type { TemplateEntityV1beta2 } from './TemplateEntityV1beta2'; export { templateEntityV1beta3Validator } from './TemplateEntityV1beta3'; export type { TemplateEntityV1beta3 } from './TemplateEntityV1beta3';