swift publisher

Signed-off-by: Mert Can Bilgiç <mert.bilgic@trendyol.com>
This commit is contained in:
erdoganoksuz
2021-02-24 12:00:29 +03:00
committed by Mert Can Bilgiç
parent a7c5e8a009
commit de313a1c94
5 changed files with 77 additions and 5 deletions
@@ -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<void> {
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<Promise<unknown>> = [];
for (const filePath of allFilesToUpload) {
@@ -169,6 +172,8 @@ export class OpenStackSwiftPublish implements PublisherBase {
async fetchTechDocsMetadata(
entityName: EntityName,
): Promise<TechDocsMetadata> {
console.log(entityName, 'fetchTechDocsMetadata hey');
try {
return await new Promise<TechDocsMetadata>(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<boolean> {
try {
console.log(entity, 'hasDocsBeenGenerated hey');
const entityRootDir = `${entity.metadata.namespace}/${entity.kind}/${entity.metadata.name}`;
this.storageClient.getFile(
this.containerName,
@@ -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);
@@ -23,7 +23,8 @@ export type PublisherType =
| 'local'
| 'googleGcs'
| 'awsS3'
| 'azureBlobStorage';
| 'azureBlobStorage'
| 'openStackSwift';
export type PublishRequest = {
entity: Entity;
+1 -1
View File
@@ -33,7 +33,7 @@ export interface Config {
* Techdocs publisher information
*/
publisher: {
type: 'local' | 'googleGcs' | 'awsS3';
type: 'local' | 'googleGcs' | 'awsS3' | 'openStackSwift';
};
/**
+56
View File
@@ -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';