From de313a1c9490de15b9ad1116222da74d5629a8ba Mon Sep 17 00:00:00 2001 From: erdoganoksuz Date: Wed, 24 Feb 2021 12:00:29 +0300 Subject: [PATCH] swift publisher MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mert Can BilgiƧ --- .../src/stages/publish/openStackSwift.ts | 15 ++++- .../src/stages/publish/publish.ts | 6 ++ .../src/stages/publish/types.ts | 3 +- plugins/techdocs-backend/config.d.ts | 2 +- plugins/techdocs/config.d.ts | 56 +++++++++++++++++++ 5 files changed, 77 insertions(+), 5 deletions(-) diff --git a/packages/techdocs-common/src/stages/publish/openStackSwift.ts b/packages/techdocs-common/src/stages/publish/openStackSwift.ts index 3331033f66..b174122789 100644 --- a/packages/techdocs-common/src/stages/publish/openStackSwift.ts +++ b/packages/techdocs-common/src/stages/publish/openStackSwift.ts @@ -103,16 +103,19 @@ export class OpenStackSwiftPublish implements PublisherBase { this.logger = logger; } + public myName: string = 'hey'; + /** - * Upload all the files from the generated `directory` to the S3 bucket. + * Upload all the files from the generated `directory` to the OpenStack Swift container. * Directory structure used in the bucket is - entityNamespace/entityKind/entityName/index.html */ async publish({ entity, directory }: PublishRequest): Promise { + console.log(entity, directory, 'Publish hey'); try { - // Note: S3 manages creation of parent directories if they do not exist. + // Note: OpenStack Swift manages creation of parent directories if they do not exist. // So collecting path of only the files is good enough. const allFilesToUpload = await getFileTreeRecursively(directory); - + console.log(allFilesToUpload, entity, 'hey'); const limiter = createLimiter(10); const uploadPromises: Array> = []; for (const filePath of allFilesToUpload) { @@ -169,6 +172,8 @@ export class OpenStackSwiftPublish implements PublisherBase { async fetchTechDocsMetadata( entityName: EntityName, ): Promise { + console.log(entityName, 'fetchTechDocsMetadata hey'); + try { return await new Promise(async (resolve, reject) => { const entityRootDir = `${entityName.namespace}/${entityName.kind}/${entityName.name}`; @@ -208,6 +213,8 @@ export class OpenStackSwiftPublish implements PublisherBase { return async (req, res) => { // Trim the leading forward slash // filePath example - /default/Component/documented-component/index.html + console.log('docsRouter hey'); + const filePath = req.path.replace(/^\//, ''); // Files with different extensions (CSS, HTML) need to be served with different headers @@ -241,6 +248,8 @@ export class OpenStackSwiftPublish implements PublisherBase { */ async hasDocsBeenGenerated(entity: Entity): Promise { try { + console.log(entity, 'hasDocsBeenGenerated hey'); + const entityRootDir = `${entity.metadata.namespace}/${entity.kind}/${entity.metadata.name}`; this.storageClient.getFile( this.containerName, diff --git a/packages/techdocs-common/src/stages/publish/publish.ts b/packages/techdocs-common/src/stages/publish/publish.ts index a4e33a2d9c..f70a5f7626 100644 --- a/packages/techdocs-common/src/stages/publish/publish.ts +++ b/packages/techdocs-common/src/stages/publish/publish.ts @@ -22,6 +22,7 @@ import { LocalPublish } from './local'; import { GoogleGCSPublish } from './googleStorage'; import { AwsS3Publish } from './awsS3'; import { AzureBlobStoragePublish } from './azureBlobStorage'; +import { OpenStackSwiftPublish } from './openStackSwift'; type factoryOptions = { logger: Logger; @@ -53,6 +54,11 @@ export class Publisher { 'Creating Azure Blob Storage Container publisher for TechDocs', ); return AzureBlobStoragePublish.fromConfig(config, logger); + case 'openStackSwift': + logger.info( + 'Creating OpenStack Swift Container publisher for TechDocs', + ); + return OpenStackSwiftPublish.fromConfig(config, logger); case 'local': logger.info('Creating Local publisher for TechDocs'); return new LocalPublish(config, logger, discovery); diff --git a/packages/techdocs-common/src/stages/publish/types.ts b/packages/techdocs-common/src/stages/publish/types.ts index 5e953deb81..f0ecb3cb2b 100644 --- a/packages/techdocs-common/src/stages/publish/types.ts +++ b/packages/techdocs-common/src/stages/publish/types.ts @@ -23,7 +23,8 @@ export type PublisherType = | 'local' | 'googleGcs' | 'awsS3' - | 'azureBlobStorage'; + | 'azureBlobStorage' + | 'openStackSwift'; export type PublishRequest = { entity: Entity; diff --git a/plugins/techdocs-backend/config.d.ts b/plugins/techdocs-backend/config.d.ts index 5a323f244a..c704014b14 100644 --- a/plugins/techdocs-backend/config.d.ts +++ b/plugins/techdocs-backend/config.d.ts @@ -33,7 +33,7 @@ export interface Config { * Techdocs publisher information */ publisher: { - type: 'local' | 'googleGcs' | 'awsS3'; + type: 'local' | 'googleGcs' | 'awsS3' | 'openStackSwift'; }; /** diff --git a/plugins/techdocs/config.d.ts b/plugins/techdocs/config.d.ts index 1c49833d68..c4fe4a47db 100644 --- a/plugins/techdocs/config.d.ts +++ b/plugins/techdocs/config.d.ts @@ -85,6 +85,62 @@ export interface Config { region?: string; }; } + | { + type: 'openStackSwift'; + + /** + * Required when 'type' is set to awsS3 + */ + openStackSwift?: { + /** + * (Optional) Credentials used to access a storage bucket. + * If not set, environment variables or aws config file will be used to authenticate. + * @see https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/loading-node-credentials-environment.html + * @see https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/loading-node-credentials-shared.html + * @visibility secret + */ + /** + * (Required) Cloud Storage Container Name + * @visibility backend + */ + containerName: string; + /** + * (Required) Root user name + * @visibility backend + */ + username: string; + /** + * (Required) Root user password + * @visibility backend + */ + password: string; // required + /** + * (Required) Auth url sometimes OpenStack uses different port check your OpenStack apis. + * @visibility backend + */ + authUrl: string; + /** + * (Required) Auth version + * @visibility backend + */ + keystoneAuthVersion: string; + /** + * (Required) Domaind Id + * @visibility backend + */ + domainId: string; + /** + * (Required) Domaind Name + * @visibility backend + */ + domainName: 'Default'; + /** + * (Required) Region + * @visibility backend + */ + region: 'earth'; + }; + } | { type: 'azureBlobStorage';