diff --git a/plugins/scaffolder-backend/package.json b/plugins/scaffolder-backend/package.json index 907efde362..1838738c01 100644 --- a/plugins/scaffolder-backend/package.json +++ b/plugins/scaffolder-backend/package.json @@ -38,6 +38,7 @@ "@backstage/cli": "^0.1.1-alpha.8", "@types/fs-extra": "^9.0.1", "@types/supertest": "^2.0.8", - "supertest": "^4.0.2" + "supertest": "^4.0.2", + "yaml": "^1.10.0" } } diff --git a/plugins/scaffolder-backend/src/scaffolder/prepare/file.ts b/plugins/scaffolder-backend/src/scaffolder/prepare/file.ts index f3b69cc361..d7d21baa29 100644 --- a/plugins/scaffolder-backend/src/scaffolder/prepare/file.ts +++ b/plugins/scaffolder-backend/src/scaffolder/prepare/file.ts @@ -13,3 +13,37 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +// import fs from 'fs-extra'; +import fs from 'fs'; +import { + TemplateEntityV1alpha1, + LOCATION_ANNOTATION, +} from '@backstage/catalog-model'; +import { InputError } from '@backstage/backend-common'; +import { PreparerBase } from './types'; + +export class FilePreparer implements PreparerBase { + async prepare(template: TemplateEntityV1alpha1): Promise { + const location = template?.metadata?.annotations?.[LOCATION_ANNOTATION]; + + const [locationType, actualLocation] = (location ?? '').split(/:(.+)/); + if (locationType !== 'file') { + throw new InputError( + `Wrong location type: ${locationType}, should be 'file'`, + ); + } + + if (!actualLocation) { + throw new InputError( + `Couldn't parse location for template: ${template.metadata.name}`, + ); + } + + const templateId = template.metadata.name; + + const tempDir = await fs.promises.mkdtemp(templateId); + + // await fs.copy(actualLocation, tempDir); + return tempDir; + } +} diff --git a/plugins/scaffolder-backend/src/scaffolder/prepare/preparers.ts b/plugins/scaffolder-backend/src/scaffolder/prepare/preparers.ts index dc3e318926..97db3a3100 100644 --- a/plugins/scaffolder-backend/src/scaffolder/prepare/preparers.ts +++ b/plugins/scaffolder-backend/src/scaffolder/prepare/preparers.ts @@ -15,7 +15,10 @@ */ import { PreparerBase, RemoteLocation, PreparerBuilder } from './types'; -import { TemplateEntityV1alpha1 } from '@backstage/catalog-model'; +import { + TemplateEntityV1alpha1, + LOCATION_ANNOTATION, +} from '@backstage/catalog-model'; export class Preparers implements PreparerBuilder { private preparerMap = new Map(); @@ -38,8 +41,7 @@ export class Preparers implements PreparerBuilder { private getPreparerKeyFromEntity( entity: TemplateEntityV1alpha1, ): RemoteLocation { - const annotation = - entity.metadata.annotations?.['backstage.io/managed-by-location'] ?? ''; + const annotation = entity.metadata.annotations?.[LOCATION_ANNOTATION] ?? ''; const [key] = annotation?.split(':'); if (!key) { diff --git a/plugins/scaffolder-backend/src/service/router.ts b/plugins/scaffolder-backend/src/service/router.ts index 57ac1413fc..74507d528c 100644 --- a/plugins/scaffolder-backend/src/service/router.ts +++ b/plugins/scaffolder-backend/src/service/router.ts @@ -35,7 +35,7 @@ export async function createRouter( router.post('/v1/jobs', async (_, res) => { // TODO(blam): Actually make this function work - // res.status(201).json({ accepted: true }); + res.status(201).json({ accepted: true }); const mockEntity: TemplateEntityV1alpha1 = { apiVersion: 'backstage.io/v1alpha1', diff --git a/plugins/scaffolder-backend/test/mock-failing-template-dir/mock-template-2/template-info.json b/plugins/scaffolder-backend/test/mock-failing-template-dir/mock-template-2/template-info.json deleted file mode 100644 index 47f83f9f5c..0000000000 --- a/plugins/scaffolder-backend/test/mock-failing-template-dir/mock-template-2/template-info.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "id": "mock-template-2", - "name": "mockmannen", - "description": "mock template for building stuff in backstage", - "ownerId": "blam" -} diff --git a/plugins/scaffolder-backend/test/mock-failing-template-dir/mock-template/template-info.json b/plugins/scaffolder-backend/test/mock-failing-template-dir/mock-template/template-info.json deleted file mode 100644 index 9a3458fba1..0000000000 --- a/plugins/scaffolder-backend/test/mock-failing-template-dir/mock-template/template-info.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "id": "mock-template", - "name": "mockmannen", - "description": "mock template for building stuff in backstage", - "ownerId": "blam", - -} diff --git a/plugins/scaffolder-backend/test/mock-multiple-templates-dir/mock-template-2/template-info.json b/plugins/scaffolder-backend/test/mock-multiple-templates-dir/mock-template-2/template-info.json deleted file mode 100644 index 47f83f9f5c..0000000000 --- a/plugins/scaffolder-backend/test/mock-multiple-templates-dir/mock-template-2/template-info.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "id": "mock-template-2", - "name": "mockmannen", - "description": "mock template for building stuff in backstage", - "ownerId": "blam" -} diff --git a/plugins/scaffolder-backend/test/mock-multiple-templates-dir/mock-template/template-info.json b/plugins/scaffolder-backend/test/mock-multiple-templates-dir/mock-template/template-info.json deleted file mode 100644 index e0d323c987..0000000000 --- a/plugins/scaffolder-backend/test/mock-multiple-templates-dir/mock-template/template-info.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "id": "mock-template", - "name": "mockmannen", - "description": "mock template for building stuff in backstage", - "ownerId": "blam" -} diff --git a/plugins/scaffolder-backend/test/mock-simple-template-dir/mock-template/template-info.json b/plugins/scaffolder-backend/test/mock-simple-template-dir/mock-template/template-info.json deleted file mode 100644 index e0d323c987..0000000000 --- a/plugins/scaffolder-backend/test/mock-simple-template-dir/mock-template/template-info.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "id": "mock-template", - "name": "mockmannen", - "description": "mock template for building stuff in backstage", - "ownerId": "blam" -}