documentation added
Signed-off-by: Mert Can Bilgiç <mert.bilgic@trendyol.com>
This commit is contained in:
committed by
Mert Can Bilgiç
parent
32fac33d8d
commit
cebda81000
@@ -16,7 +16,7 @@
|
||||
import fs from 'fs-extra';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import { ObjectWritableMock, BufferReadableMock } from 'stream-mock';
|
||||
import { EventEmitter } from 'events';
|
||||
|
||||
const rootDir = os.platform() === 'win32' ? 'C:\\rootDir' : '/rootDir';
|
||||
|
||||
@@ -61,16 +61,44 @@ class PkgCloudStorageClient {
|
||||
}
|
||||
}
|
||||
|
||||
upload() {
|
||||
return new ObjectWritableMock();
|
||||
upload({ remote }: { remote: string }) {
|
||||
const filePath = path.join(rootDir, remote);
|
||||
|
||||
const emitter = new EventEmitter();
|
||||
|
||||
process.nextTick(() => {
|
||||
if (fs.existsSync(filePath)) {
|
||||
emitter.emit('success');
|
||||
(emitter as any).end = () => true;
|
||||
} else {
|
||||
emitter.emit(
|
||||
'error',
|
||||
new Error(`The file ${filePath} does not exist !`),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
return emitter;
|
||||
}
|
||||
|
||||
download() {
|
||||
const stringify = JSON.stringify({
|
||||
"site_description": 'site_content',
|
||||
"site_name": "backstage"
|
||||
download({ remote }: { remote: string }) {
|
||||
const filePath = path.join(rootDir, remote);
|
||||
|
||||
const emitter = new EventEmitter();
|
||||
|
||||
process.nextTick(() => {
|
||||
if (fs.existsSync(filePath)) {
|
||||
emitter.emit('data', Buffer.from(fs.readFileSync(filePath)));
|
||||
emitter.emit('end');
|
||||
} else {
|
||||
emitter.emit(
|
||||
'error',
|
||||
new Error(`The file ${filePath} does not exist !`),
|
||||
);
|
||||
}
|
||||
});
|
||||
return new BufferReadableMock([stringify]);
|
||||
|
||||
return emitter;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@backstage/techdocs-common",
|
||||
"description": "Common functionalities for TechDocs, to be shared between techdocs-backend plugin and techdocs-cli",
|
||||
"version": "0.4.2",
|
||||
"version": "0.5.0",
|
||||
"main": "src/index.ts",
|
||||
"types": "src/index.ts",
|
||||
"private": false,
|
||||
@@ -58,7 +58,6 @@
|
||||
"p-limit": "^3.1.0",
|
||||
"pkgcloud": "^2.2.0",
|
||||
"recursive-readdir": "^2.2.2",
|
||||
"stream-mock": "^2.0.5",
|
||||
"winston": "^3.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -111,14 +111,12 @@ describe('OpenStackSwiftPublish', () => {
|
||||
const entity = createMockEntity();
|
||||
const entityRootDir = getEntityRootDir(entity);
|
||||
|
||||
setTimeout(async () => {
|
||||
expect(
|
||||
await publisher.publish({
|
||||
entity,
|
||||
directory: entityRootDir,
|
||||
}),
|
||||
).toBeUndefined()
|
||||
}, 5000);
|
||||
expect(
|
||||
await publisher.publish({
|
||||
entity,
|
||||
directory: entityRootDir,
|
||||
}),
|
||||
).toBeUndefined()
|
||||
});
|
||||
|
||||
it('should fail to publish a directory', async () => {
|
||||
|
||||
@@ -49,7 +49,7 @@ export class OpenStackSwiftPublish implements PublisherBase {
|
||||
} catch (error) {
|
||||
throw new Error(
|
||||
"Since techdocs.publisher.type is set to 'openStackSwift' in your app config, " +
|
||||
'techdocs.publisher.openStackSwift.containerName is required.',
|
||||
'techdocs.publisher.openStackSwift.containerName is required.',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -59,8 +59,8 @@ export class OpenStackSwiftPublish implements PublisherBase {
|
||||
|
||||
const storageClient = storage.createClient({
|
||||
provider: 'openstack',
|
||||
username: openStackSwiftConfig.getString('username'),
|
||||
password: openStackSwiftConfig.getString('password'),
|
||||
username: openStackSwiftConfig.getString('credentials.username'),
|
||||
password: openStackSwiftConfig.getString('credentials.password'),
|
||||
authUrl: openStackSwiftConfig.getString('authUrl'),
|
||||
keystoneAuthVersion:
|
||||
openStackSwiftConfig.getOptionalString('keystoneAuthVersion') || 'v3',
|
||||
@@ -80,9 +80,9 @@ export class OpenStackSwiftPublish implements PublisherBase {
|
||||
} else {
|
||||
logger.error(
|
||||
`Could not retrieve metadata about the OpenStack Swift container ${containerName}. ` +
|
||||
'Make sure the container exists. Also make sure that authentication is setup either by ' +
|
||||
'explicitly defining credentials and region in techdocs.publisher.openStackSwift in app config or ' +
|
||||
'by using environment variables. Refer to https://backstage.io/docs/features/techdocs/using-cloud-storage',
|
||||
'Make sure the container exists. Also make sure that authentication is setup either by ' +
|
||||
'explicitly defining credentials and region in techdocs.publisher.openStackSwift in app config or ' +
|
||||
'by using environment variables. Refer to https://backstage.io/docs/features/techdocs/using-cloud-storage',
|
||||
);
|
||||
|
||||
logger.error(`from OpenStack client library: ${err.message}`);
|
||||
@@ -139,15 +139,15 @@ export class OpenStackSwiftPublish implements PublisherBase {
|
||||
|
||||
// Rate limit the concurrent execution of file uploads to batches of 10 (per publish)
|
||||
const uploadFile = limiter(() =>
|
||||
new Promise((res, rej) => {
|
||||
const writeStream = this.storageClient.upload(params);
|
||||
new Promise((res, rej) => {
|
||||
const writeStream = this.storageClient.upload(params);
|
||||
|
||||
writeStream.on('error', rej);
|
||||
writeStream.on('error', rej);
|
||||
|
||||
writeStream.on('success', res);
|
||||
writeStream.on('success', res);
|
||||
|
||||
readStream.pipe(writeStream);
|
||||
}),
|
||||
readStream.pipe(writeStream);
|
||||
}),
|
||||
);
|
||||
uploadPromises.push(uploadFile);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user