Merge pull request #13050 from tragiclifestories/gcs-project-id

Add projectId config option to GCS techdocs publisher
This commit is contained in:
Anders Näsman
2022-09-06 13:11:49 +02:00
committed by GitHub
4 changed files with 46 additions and 2 deletions
@@ -16,7 +16,12 @@
import { Entity, CompoundEntityRef } from '@backstage/catalog-model';
import { Config } from '@backstage/config';
import { assertError } from '@backstage/errors';
import { File, FileExistsResponse, Storage } from '@google-cloud/storage';
import {
File,
FileExistsResponse,
Storage,
StorageOptions,
} from '@google-cloud/storage';
import express from 'express';
import JSON5 from 'json5';
import path from 'path';
@@ -83,6 +88,9 @@ export class GoogleGCSPublish implements PublisherBase {
const credentials = config.getOptionalString(
'techdocs.publisher.googleGcs.credentials',
);
const projectId = config.getOptionalString(
'techdocs.publisher.googleGcs.projectId',
);
let credentialsJson: any = {};
if (credentials) {
try {
@@ -94,11 +102,17 @@ export class GoogleGCSPublish implements PublisherBase {
}
}
const clientOpts: StorageOptions = {};
if (projectId) {
clientOpts.projectId = projectId;
}
const storageClient = new Storage({
...(credentials && {
projectId: credentialsJson.project_id,
credentials: credentialsJson,
}),
...clientOpts,
});
const legacyPathCasing =