Use request options

This commit is contained in:
Erik Larsson
2021-01-30 04:14:17 +01:00
parent 320708e171
commit 9729d9e572
3 changed files with 38 additions and 5 deletions
@@ -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<TemplateEntityV1alpha1> {
const token = options?.token;
const { items: templates } = (await this.catalogClient.getEntities(
{
filter: {
@@ -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;
};
@@ -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,