Include review comments

Signed-off-by: Dominik Henneke <dominik.henneke@sda-se.com>
This commit is contained in:
Dominik Henneke
2021-04-12 12:02:15 +02:00
parent bc9d62f4f7
commit d541d9fd07
13 changed files with 84 additions and 49 deletions
@@ -85,10 +85,10 @@ beforeEach(() => {
});
describe('AwsS3Publish', () => {
describe('validateConfiguration', () => {
describe('getReadiness', () => {
it('should validate correct config', async () => {
expect(await publisher.validateConfiguration()).toEqual({
isValid: true,
expect(await publisher.getReadiness()).toEqual({
isAvailable: true,
});
});
@@ -112,8 +112,8 @@ describe('AwsS3Publish', () => {
const errorPublisher = AwsS3Publish.fromConfig(mockConfig, logger);
expect(await errorPublisher.validateConfiguration()).toEqual({
isValid: false,
expect(await errorPublisher.getReadiness()).toEqual({
isAvailable: false,
});
});
});
@@ -27,9 +27,9 @@ import { Readable } from 'stream';
import { Logger } from 'winston';
import { getFileTreeRecursively, getHeadersForFileExtension } from './helpers';
import {
ConfigurationValidationResponse,
PublisherBase,
PublishRequest,
ReadinessResponse,
TechDocsMetadata,
} from './types';
@@ -134,7 +134,7 @@ export class AwsS3Publish implements PublisherBase {
* Check if the defined bucket exists. Being able to connect means the configuration is good
* and the storage client will work.
*/
async validateConfiguration(): Promise<ConfigurationValidationResponse> {
async getReadiness(): Promise<ReadinessResponse> {
try {
await this.storageClient
.headBucket({ Bucket: this.bucketName })
@@ -144,7 +144,7 @@ export class AwsS3Publish implements PublisherBase {
`Successfully connected to the AWS S3 bucket ${this.bucketName}.`,
);
return { isValid: true };
return { isAvailable: true };
} catch (error) {
this.logger.error(
`Could not retrieve metadata about the AWS S3 bucket ${this.bucketName}. ` +
@@ -154,7 +154,7 @@ export class AwsS3Publish implements PublisherBase {
);
this.logger.error(`from AWS client library`, error);
return {
isValid: false,
isAvailable: false,
};
}
}
@@ -86,10 +86,10 @@ beforeEach(async () => {
});
describe('publishing with valid credentials', () => {
describe('validateConfiguration', () => {
describe('getReadiness', () => {
it('should validate correct config', async () => {
expect(await publisher.validateConfiguration()).toEqual({
isValid: true,
expect(await publisher.getReadiness()).toEqual({
isAvailable: true,
});
});
@@ -115,8 +115,8 @@ describe('publishing with valid credentials', () => {
logger,
);
expect(await errorPublisher.validateConfiguration()).toEqual({
isValid: false,
expect(await errorPublisher.getReadiness()).toEqual({
isAvailable: false,
});
expect(logger.error).toHaveBeenCalledWith(
@@ -27,9 +27,9 @@ import { default as path, default as platformPath } from 'path';
import { Logger } from 'winston';
import { getFileTreeRecursively, getHeadersForFileExtension } from './helpers';
import {
ConfigurationValidationResponse,
PublisherBase,
PublishRequest,
ReadinessResponse,
TechDocsMetadata,
} from './types';
@@ -93,7 +93,7 @@ export class AzureBlobStoragePublish implements PublisherBase {
this.logger = logger;
}
async validateConfiguration(): Promise<ConfigurationValidationResponse> {
async getReadiness(): Promise<ReadinessResponse> {
try {
const response = await this.storageClient
.getContainerClient(this.containerName)
@@ -101,7 +101,7 @@ export class AzureBlobStoragePublish implements PublisherBase {
if (response._response.status === 200) {
return {
isValid: true,
isAvailable: true,
};
}
@@ -121,7 +121,7 @@ export class AzureBlobStoragePublish implements PublisherBase {
'Refer to https://backstage.io/docs/features/techdocs/using-cloud-storage',
);
return { isValid: false };
return { isAvailable: false };
}
/**
@@ -83,10 +83,10 @@ beforeEach(async () => {
});
describe('GoogleGCSPublish', () => {
describe('validateConfiguration', () => {
describe('getReadiness', () => {
it('should validate correct config', async () => {
expect(await publisher.validateConfiguration()).toEqual({
isValid: true,
expect(await publisher.getReadiness()).toEqual({
isAvailable: true,
});
});
@@ -106,8 +106,8 @@ describe('GoogleGCSPublish', () => {
const errorPublisher = GoogleGCSPublish.fromConfig(mockConfig, logger);
expect(await errorPublisher.validateConfiguration()).toEqual({
isValid: false,
expect(await errorPublisher.getReadiness()).toEqual({
isAvailable: false,
});
});
});
@@ -27,9 +27,9 @@ import path from 'path';
import { Logger } from 'winston';
import { getFileTreeRecursively, getHeadersForFileExtension } from './helpers';
import {
ConfigurationValidationResponse,
PublisherBase,
PublishRequest,
ReadinessResponse,
TechDocsMetadata,
} from './types';
@@ -84,7 +84,7 @@ export class GoogleGCSPublish implements PublisherBase {
* Check if the defined bucket exists. Being able to connect means the configuration is good
* and the storage client will work.
*/
async validateConfiguration(): Promise<ConfigurationValidationResponse> {
async getReadiness(): Promise<ReadinessResponse> {
try {
await this.storageClient.bucket(this.bucketName).getMetadata();
this.logger.info(
@@ -92,7 +92,7 @@ export class GoogleGCSPublish implements PublisherBase {
);
return {
isValid: true,
isAvailable: true,
};
} catch (err) {
this.logger.error(
@@ -103,7 +103,7 @@ export class GoogleGCSPublish implements PublisherBase {
);
this.logger.error(`from GCS client library: ${err.message}`);
return { isValid: false };
return { isAvailable: false };
}
}
@@ -25,10 +25,10 @@ import os from 'os';
import path from 'path';
import { Logger } from 'winston';
import {
ConfigurationValidationResponse,
PublisherBase,
PublishRequest,
PublishResponse,
ReadinessResponse,
TechDocsMetadata,
} from './types';
@@ -66,9 +66,9 @@ export class LocalPublish implements PublisherBase {
this.discovery = discovery;
}
async validateConfiguration(): Promise<ConfigurationValidationResponse> {
async getReadiness(): Promise<ReadinessResponse> {
return {
isValid: true,
isAvailable: true,
};
}
@@ -87,10 +87,10 @@ beforeEach(() => {
});
describe('OpenStackSwiftPublish', () => {
describe('validateConfiguration', () => {
describe('getReadiness', () => {
it('should validate correct config', async () => {
expect(await publisher.validateConfiguration()).toEqual({
isValid: true,
expect(await publisher.getReadiness()).toEqual({
isAvailable: true,
});
});
@@ -118,8 +118,8 @@ describe('OpenStackSwiftPublish', () => {
logger,
);
expect(await errorPublisher.validateConfiguration()).toEqual({
isValid: false,
expect(await errorPublisher.getReadiness()).toEqual({
isAvailable: false,
});
});
});
@@ -25,9 +25,9 @@ import { Readable } from 'stream';
import { Logger } from 'winston';
import { getFileTreeRecursively, getHeadersForFileExtension } from './helpers';
import {
ConfigurationValidationResponse,
PublisherBase,
PublishRequest,
ReadinessResponse,
TechDocsMetadata,
} from './types';
@@ -92,7 +92,7 @@ export class OpenStackSwiftPublish implements PublisherBase {
* Check if the defined container exists. Being able to connect means the configuration is good
* and the storage client will work.
*/
validateConfiguration(): Promise<ConfigurationValidationResponse> {
getReadiness(): Promise<ReadinessResponse> {
return new Promise(resolve => {
this.storageClient.getContainer(this.containerName, (err, container) => {
if (container) {
@@ -100,7 +100,7 @@ export class OpenStackSwiftPublish implements PublisherBase {
`Successfully connected to the OpenStack Swift container ${this.containerName}.`,
);
resolve({
isValid: true,
isAvailable: true,
});
} else {
this.logger.error(
@@ -112,7 +112,7 @@ export class OpenStackSwiftPublish implements PublisherBase {
this.logger.error(`from OpenStack client library: ${err.message}`);
resolve({
isValid: false,
isAvailable: false,
});
}
});
@@ -40,9 +40,9 @@ export type PublishResponse = {
/**
* Result for the validation check.
*/
export type ConfigurationValidationResponse = {
/** Tells whether the configuration is valid. */
isValid: boolean;
export type ReadinessResponse = {
/** If true, the publisher is able to interact with the backing storage. */
isAvailable: boolean;
};
/**
@@ -62,12 +62,12 @@ export type TechDocsMetadata = {
*/
export interface PublisherBase {
/**
* Check if the configuration is valid. This check tries to perform certain checks to see if the
* Check if the publisher is ready. This check tries to perform certain checks to see if the
* publisher is configured correctly and can be used to publish or read documentations.
* The different implementations might e.g. use the provided service credentials to access the
* target or check if a folder/bucket is available.
*/
validateConfiguration(): Promise<ConfigurationValidationResponse>;
getReadiness(): Promise<ReadinessResponse>;
/**
* Store the generated static files onto a storage service (either local filesystem or external service).