Merge pull request #9488 from backstage/freben/move-template
move `TemplateEntityV1beta2` to `@backstage/plugin-scaffolder-common`
This commit is contained in:
@@ -29,7 +29,7 @@ import { SpawnOptionsWithoutStdio } from 'child_process';
|
||||
import { TaskSpec } from '@backstage/plugin-scaffolder-common';
|
||||
import { TaskSpecV1beta2 } from '@backstage/plugin-scaffolder-common';
|
||||
import { TaskSpecV1beta3 } from '@backstage/plugin-scaffolder-common';
|
||||
import { TemplateEntityV1beta2 } from '@backstage/catalog-model';
|
||||
import { TemplateEntityV1beta2 } from '@backstage/plugin-scaffolder-common';
|
||||
import { TemplateMetadata } from '@backstage/plugin-scaffolder-common';
|
||||
import { UrlReader } from '@backstage/backend-common';
|
||||
import { Writable } from 'stream';
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { TemplateEntityV1beta2 } from '@backstage/catalog-model';
|
||||
import { TemplateEntityV1beta2 } from '@backstage/plugin-scaffolder-common';
|
||||
import { CatalogApi } from '@backstage/catalog-client';
|
||||
import { ConflictError, NotFoundError } from '@backstage/errors';
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import {
|
||||
parseEntityRef,
|
||||
RELATION_OWNED_BY,
|
||||
RELATION_OWNER_OF,
|
||||
entityKindSchemaValidator,
|
||||
} from '@backstage/catalog-model';
|
||||
import {
|
||||
CatalogProcessor,
|
||||
@@ -30,18 +29,16 @@ import {
|
||||
} from '@backstage/plugin-catalog-backend';
|
||||
import {
|
||||
TemplateEntityV1beta3,
|
||||
templateEntityV1beta3Schema,
|
||||
templateEntityV1beta3Validator,
|
||||
} from '@backstage/plugin-scaffolder-common';
|
||||
|
||||
/** @public */
|
||||
export class ScaffolderEntitiesProcessor implements CatalogProcessor {
|
||||
private readonly validators = [
|
||||
entityKindSchemaValidator(templateEntityV1beta3Schema),
|
||||
];
|
||||
private readonly validators = [templateEntityV1beta3Validator];
|
||||
|
||||
async validateEntityKind(entity: Entity): Promise<boolean> {
|
||||
for (const validator of this.validators) {
|
||||
if (validator(entity)) {
|
||||
if (await validator.check(entity)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,5 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export * from './actions';
|
||||
export * from './tasks';
|
||||
|
||||
@@ -36,7 +36,7 @@ import {
|
||||
UrlReaders,
|
||||
} from '@backstage/backend-common';
|
||||
import { CatalogApi } from '@backstage/catalog-client';
|
||||
import { TemplateEntityV1beta2 } from '@backstage/catalog-model';
|
||||
import { TemplateEntityV1beta2 } from '@backstage/plugin-scaffolder-common';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import express from 'express';
|
||||
import request from 'supertest';
|
||||
|
||||
@@ -20,11 +20,15 @@ import {
|
||||
UrlReader,
|
||||
} from '@backstage/backend-common';
|
||||
import { CatalogApi } from '@backstage/catalog-client';
|
||||
import { Entity, TemplateEntityV1beta2 } from '@backstage/catalog-model';
|
||||
import { stringifyEntityRef } from '@backstage/catalog-model';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { Config } from '@backstage/config';
|
||||
import { InputError, NotFoundError } from '@backstage/errors';
|
||||
import { ScmIntegrations } from '@backstage/integration';
|
||||
import { TemplateEntityV1beta3 } from '@backstage/plugin-scaffolder-common';
|
||||
import {
|
||||
TemplateEntityV1beta2,
|
||||
TemplateEntityV1beta3,
|
||||
} from '@backstage/plugin-scaffolder-common';
|
||||
import express from 'express';
|
||||
import Router from 'express-promise-router';
|
||||
import { validate } from 'jsonschema';
|
||||
@@ -190,9 +194,18 @@ export async function createRouter(
|
||||
let taskSpec: TaskSpec;
|
||||
|
||||
if (isSupportedTemplate(template)) {
|
||||
if (template.apiVersion === 'backstage.io/v1beta2') {
|
||||
logger.warn(
|
||||
`Scaffolding ${stringifyEntityRef(
|
||||
template,
|
||||
)} with deprecated apiVersion ${
|
||||
template.apiVersion
|
||||
}. Please migrate the template to backstage.io/v1beta3. https://backstage.io/docs/features/software-templates/migrating-from-v1beta2-to-v1beta3`,
|
||||
);
|
||||
}
|
||||
|
||||
for (const parameters of [template.spec.parameters ?? []].flat()) {
|
||||
const result = validate(values, parameters);
|
||||
|
||||
if (!result.valid) {
|
||||
res.status(400).json({ errors: result.errors });
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user