techdocs: Use googleGcs for publisher type instead of google_gcs

This commit is contained in:
Himanshu Mishra
2020-12-09 18:58:12 +01:00
parent 9d08ef8f46
commit 24bcdd0829
11 changed files with 61 additions and 49 deletions
+1 -1
View File
@@ -17,4 +17,4 @@ instead of
An instance of `publisher` can either be a local filesystem publisher or a Google Cloud Storage publisher.
Read more about the configs here https://backstage.io/docs/features/techdocs/configuration
(You will also have to update `techdocs.storage.type` to `local` or `google_gcs`. And `techdocs.builder` to either `local` or `external`.)
(You will also have to update `techdocs.storage.type` to `local` or `googleGcs`. And `techdocs.builder` to either `local` or `external`.)
+1 -1
View File
@@ -76,7 +76,7 @@ techdocs:
generators:
techdocs: 'docker' # Alternatives - 'local'
publisher:
type: 'local' # Alternatives - 'google_gcs'. Read documentation for using alternatives.
type: 'local' # Alternatives - 'googleGcs'. Read documentation for using alternatives.
sentry:
organization: my-company
+4 -4
View File
@@ -50,16 +50,16 @@ techdocs:
publisher:
# techdocs.publisher.type can be - 'local' or 'google_gcs' (aws_s3, azure_storage, etc. to be available as well).
# techdocs.publisher.type can be - 'local' or 'googleGcs' (awsS3, azureStorage, etc. to be available as well).
# When set to 'local', techdocs-backend will create a 'static' directory at its root to store generated documentation files.
# When set to 'google_gcs', techdocs-backend will use a Google Cloud Storage Bucket to store generated documentation files.
# When set to 'googleGcs', techdocs-backend will use a Google Cloud Storage Bucket to store generated documentation files.
type: 'local'
# Required when techdocs.publisher.type is set to 'google_gcs'. Skip otherwise.
# Required when techdocs.publisher.type is set to 'googleGcs'. Skip otherwise.
google:
googleGcs:
# An API key is required to write to a storage bucket.
pathToKey: '/path/to/google_application_credentials.json',
+10 -10
View File
@@ -22,24 +22,24 @@ for the latest instructions on the following steps involving GCP.
**1. Set `techdocs.publisher.type` config in your `app-config.yaml`**
Set `techdocs.publisher.type` to `'google_gcs'`.
Set `techdocs.publisher.type` to `'googleGcs'`.
```yaml
techdocs:
publisher:
type: 'google_gcs'
type: 'googleGcs'
```
**2. GCP (Google Cloud Platform) Project**
Create or choose a dedicated GCP project. Set
`techdocs.publisher.google.projectId` to the project ID.
`techdocs.publisher.googleGcs.projectId` to the project ID.
```yaml
techdocs:
publisher:
type: 'google_gcs'
google:
type: 'googleGcs'
googleGcs:
projectId: 'gcp-project-id
```
@@ -58,13 +58,13 @@ IAM & Admin console), and create a new key. Use JSON format for the key.
A `<GCP-PROJECT-ID-random-uid>.json` file will be downloaded. This is the secret
key TechDocs will use to make API calls. Make it available in your Backstage
server and/or your local development server and set it in the app config
`techdocs.publisher.google.pathToKey`.
`techdocs.publisher.googleGcs.pathToKey`.
```yaml
techdocs:
publisher:
type: 'google_gcs'
google:
type: 'googleGcs'
googleGcs:
projectId: 'gcp-project-id'
pathToKey: '/path/to/google_application_credentials.json'
```
@@ -80,8 +80,8 @@ Set the name of the bucket to `techdocs.publisher
```yaml
techdocs:
publisher:
type: 'google_gcs'
google:
type: 'googleGcs'
googleGcs:
projectId: 'gcp-project-id'
pathToKey: '/path/to/google_application_credentials.json'
bucketName: 'name-of-techdocs-storage-bucket'
@@ -49,8 +49,8 @@ beforeEach(() => {
techdocs: {
requestUrl: 'http://localhost:7000',
publisher: {
type: 'google_gcs',
google: {
type: 'googleGcs',
googleGcs: {
pathToKey: '/path/to/google-application-credentials.json',
projectId: 'gcp-project-id',
bucketName: 'bucketName',
@@ -29,13 +29,13 @@ export class GoogleGCSPublish implements PublisherBase {
let projectId = '';
let bucketName = '';
try {
pathToKey = config.getString('techdocs.publisher.google.pathToKey');
projectId = config.getString('techdocs.publisher.google.projectId');
bucketName = config.getString('techdocs.publisher.google.bucketName');
pathToKey = config.getString('techdocs.publisher.googleGcs.pathToKey');
projectId = config.getString('techdocs.publisher.googleGcs.projectId');
bucketName = config.getString('techdocs.publisher.googleGcs.bucketName');
} catch (error) {
throw new Error(
"Since techdocs.publisher.type is set to 'google_gcs' in your app config, " +
'pathToKey, projectId and bucketName are required in techdocs.publisher.google ' +
"Since techdocs.publisher.type is set to 'googleGcs' in your app config, " +
'pathToKey, projectId and bucketName are required in techdocs.publisher.googleGcs ' +
'required to authenticate with Google Cloud Storage.',
);
}
@@ -59,7 +59,7 @@ export class GoogleGCSPublish implements PublisherBase {
logger.error(
`Could not retrieve metadata about the GCS bucket ${bucketName} in the GCP project ${projectId}. ` +
'Make sure the GCP project and the bucket exists and the access key located at the path ' +
"techdocs.publisher.google.pathToKey defined in app config has the role 'Storage Object Creator'. " +
"techdocs.publisher.googleGcs.pathToKey defined in app config has the role 'Storage Object Creator'. " +
'Refer to https://backstage.io/docs/features/techdocs/using-cloud-storage',
);
throw new Error(`from GCS client library: ${reason.message}`);
@@ -77,8 +77,8 @@ describe('Publisher', () => {
techdocs: {
requestUrl: 'http://localhost:7000',
publisher: {
type: 'google_gcs',
google: {
type: 'googleGcs',
googleGcs: {
pathToKey: '/path/to/google-application-credentials.json',
projectId: 'gcp-project-id',
bucketName: 'bucketName',
@@ -36,7 +36,7 @@ export class Publisher {
) ?? 'local') as PublisherType;
switch (publisherType) {
case 'google_gcs':
case 'googleGcs':
logger.info('Creating Google Storage Bucket publisher for TechDocs');
return GoogleGCSPublish.fromConfig(config, logger);
case 'local':
@@ -19,7 +19,7 @@ import express from 'express';
/**
* Key for all the different types of TechDocs publishers that are supported.
*/
export type PublisherType = 'local' | 'google_gcs';
export type PublisherType = 'local' | 'googleGcs';
export type PublishRequest = {
entity: Entity;
@@ -115,7 +115,7 @@ export async function createRouter({
} catch (err) {
throw new Error(
'Unable to get techdocs.publisher.type in your app config. Set it to either ' +
"'local', 'google_gcs' or other support storage providers. Read more here " +
"'local', 'googleGcs' or other support storage providers. Read more here " +
'https://backstage.io/docs/features/techdocs/architecture',
);
}
@@ -136,7 +136,7 @@ export async function createRouter({
if (!(await docsBuilder.docsUpToDate())) {
await docsBuilder.build();
}
} else if (publisherType === 'google_gcs') {
} else if (publisherType === 'googleGcs') {
// This block should be valid for all external storage implementations. So no need to duplicate in future,
// add the publisher type in the list here.
if (!(await publisher.hasDocsBeenGenerated(entity))) {
+31 -19
View File
@@ -85,32 +85,44 @@
"visibility": "frontend"
},
"publisher": {
"type": "object",
"properties": {
"type": {
"type": "string",
"visibility": "backend"
},
"google": {
"oneOf": [
{
"type": "object",
"properties": {
"pathToKey": {
"type": {
"type": "string",
"visibility": "secret"
"const": "local",
"visibility": "backend"
}
}
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "googleGcs",
"visibility": "backend"
},
"projectId": {
"type": "string",
"visibility": "secret"
},
"bucketName": {
"type": "string",
"visibility": "secret"
"googleGcs": {
"type": "object",
"properties": {
"pathToKey": {
"type": "string",
"visibility": "secret"
},
"projectId": {
"type": "string",
"visibility": "secret"
},
"bucketName": {
"type": "string",
"visibility": "secret"
}
}
}
}
}
},
"required": [
"type"
]
}
},