diff --git a/plugins/scaffolder-backend/src/lib/catalog/CatalogEntityClient.ts b/plugins/scaffolder-backend/src/lib/catalog/CatalogEntityClient.ts index 56b82760bd..ed8b28552d 100644 --- a/plugins/scaffolder-backend/src/lib/catalog/CatalogEntityClient.ts +++ b/plugins/scaffolder-backend/src/lib/catalog/CatalogEntityClient.ts @@ -21,6 +21,7 @@ import { NotFoundError, PluginEndpointDiscovery, } from '@backstage/backend-common'; +import { CatalogEntityRequestOptions } from './types'; /** * A catalog client tailored for reading out entity data from the catalog. @@ -40,9 +41,10 @@ export class CatalogEntityClient { * Throws a NotFoundError or ConflictError if 0 or multiple templates are found. */ async findTemplate( - token: string | undefined, templateName: string, + options?: CatalogEntityRequestOptions, ): Promise { + const token = options?.token; const { items: templates } = (await this.catalogClient.getEntities( { filter: { diff --git a/plugins/scaffolder-backend/src/lib/catalog/types.ts b/plugins/scaffolder-backend/src/lib/catalog/types.ts new file mode 100644 index 0000000000..188efbd9d0 --- /dev/null +++ b/plugins/scaffolder-backend/src/lib/catalog/types.ts @@ -0,0 +1,32 @@ +/* + * Copyright 2021 Spotify AB + * + * 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. + */ +/* + * 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. + */ + +export type CatalogEntityRequestOptions = { + token: string | undefined; +}; diff --git a/plugins/scaffolder-backend/src/service/router.ts b/plugins/scaffolder-backend/src/service/router.ts index 25b8c6e6f9..cf10643de3 100644 --- a/plugins/scaffolder-backend/src/service/router.ts +++ b/plugins/scaffolder-backend/src/service/router.ts @@ -104,10 +104,9 @@ export async function createRouter( // Forward authorization from client const user = req.user as BackstageIdentity; - const template = await entityClient.findTemplate( - user?.idToken, - templateName, - ); + const template = await entityClient.findTemplate(templateName, { + token: user?.idToken, + }); const validationResult: ValidatorResult = validate( values,