diff --git a/packages/nc-gui/static/plugins/scaleway.png b/packages/nc-gui/static/plugins/scaleway.png new file mode 100644 index 0000000000..342a50f686 Binary files /dev/null and b/packages/nc-gui/static/plugins/scaleway.png differ diff --git a/packages/nocodb/src/lib/noco/plugins/NcPluginMgr.ts b/packages/nocodb/src/lib/noco/plugins/NcPluginMgr.ts index 84b6e122e9..54c2ee9eef 100644 --- a/packages/nocodb/src/lib/noco/plugins/NcPluginMgr.ts +++ b/packages/nocodb/src/lib/noco/plugins/NcPluginMgr.ts @@ -24,6 +24,7 @@ import MattermostPluginConfig from "../../../plugins/mattermost"; import DiscordPluginConfig from "../../../plugins/discord"; import TwilioWhatsappPluginConfig from "../../../plugins/twilioWhatsapp"; import TwilioPluginConfig from "../../../plugins/twilio"; +import ScalewayPluginConfig from "../../../plugins/scaleway"; import Noco from "../Noco"; import Local from "./adapters/storage/Local"; @@ -45,6 +46,7 @@ const defaultPlugins = [ LinodePluginConfig, UpcloudPluginConfig, SMTPPluginConfig, + ScalewayPluginConfig, ] class NcPluginMgr { @@ -129,4 +131,27 @@ class NcPluginMgr { } -export default NcPluginMgr; \ No newline at end of file +export default NcPluginMgr; + +/** + * @copyright Copyright (c) 2021, Xgene Cloud Ltd + * + * @author Pranav C Balan + * @author Bhanu P Chaudhary + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ \ No newline at end of file diff --git a/packages/nocodb/src/plugins/scaleway/ScalewayObjectStorage.ts b/packages/nocodb/src/plugins/scaleway/ScalewayObjectStorage.ts new file mode 100644 index 0000000000..99b1dca9e0 --- /dev/null +++ b/packages/nocodb/src/plugins/scaleway/ScalewayObjectStorage.ts @@ -0,0 +1,118 @@ +import AWS from "aws-sdk"; +import fs from "fs"; +import path from "path"; +import {IStorageAdapter, XcFile} from "nc-plugin"; + +export default class ScalewayObjectStorage implements IStorageAdapter { + + private s3Client: AWS.S3; + private input: any; + + constructor(input: any) { + this.input = input; + } + + + async fileCreate(key: string, file: XcFile): Promise { + + const uploadParams: any = { + ACL: 'public-read' + }; + return new Promise((resolve, reject) => { + // Configure the file stream and obtain the upload parameters + const fileStream = fs.createReadStream(file.path); + fileStream.on('error', (err) => { + console.log('File Error', err); + reject(err); + }); + + uploadParams.Body = fileStream; + uploadParams.Key = key; + + // call S3 to retrieve upload file to specified bucket + this.s3Client.upload(uploadParams, (err, data) => { + if (err) { + console.log("Error", err); + reject(err); + } + if (data) { + resolve(data.Location); + } + }); + }); + } + + public async fileDelete(_path: string): Promise { + return Promise.resolve(undefined); + } + + public async fileRead(key: string): Promise { + return new Promise((resolve, reject) => { + this.s3Client.getObject({Key: key} as any, (err, data) => { + if (err) { + return reject(err); + } + if (!data?.Body) { + return reject(data); + } + return resolve(data.Body); + }); + }); + } + + public async init(): Promise { + const s3Options: any = { + params: {Bucket: this.input.bucket}, + region: this.input.region + }; + + s3Options.accessKeyId = this.input.access_key + s3Options.secretAccessKey = this.input.access_secret; + + s3Options.endpoint = new AWS.Endpoint(`s3.${this.input.region}.scw.cloud`); + + this.s3Client = new AWS.S3(s3Options); + } + + public async test(): Promise { + try { + const tempFile = path.join(process.cwd(), 'temp.txt'); + const createStream = fs.createWriteStream(tempFile); + createStream.end(); + await this.fileCreate('/test.txt', { + path: tempFile, + mimetype: '', + originalname: 'temp.txt', + size: '' + }); + fs.unlinkSync(tempFile); + return true; + } catch (e) { + throw e; + } + } + +} + + +/** + * @copyright Copyright (c) 2021, Bhanu P Chaudhary + * + * @author Bhanu P Chaudhary + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ \ No newline at end of file diff --git a/packages/nocodb/src/plugins/scaleway/ScalewayObjectStoragePlugin.ts b/packages/nocodb/src/plugins/scaleway/ScalewayObjectStoragePlugin.ts new file mode 100644 index 0000000000..446f63a58d --- /dev/null +++ b/packages/nocodb/src/plugins/scaleway/ScalewayObjectStoragePlugin.ts @@ -0,0 +1,43 @@ +import {IStorageAdapter, XcStoragePlugin} from "nc-plugin"; +import ScalewayObjectStorage from "./ScalewayObjectStorage"; + + +class ScalewayObjectStoragePlugin extends XcStoragePlugin { + + private static storageAdapter: ScalewayObjectStorage; + + public getAdapter(): IStorageAdapter { + return ScalewayObjectStoragePlugin.storageAdapter; + } + + public async init(config: any): Promise { + ScalewayObjectStoragePlugin.storageAdapter = new ScalewayObjectStorage(config); + await ScalewayObjectStoragePlugin.storageAdapter.init(); + } + +} + +export default ScalewayObjectStoragePlugin; + + +/** + * @copyright Copyright (c) 2021, Bhanu P Chaudhary + * + * @author Bhanu P Chaudhary + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ \ No newline at end of file diff --git a/packages/nocodb/src/plugins/scaleway/index.ts b/packages/nocodb/src/plugins/scaleway/index.ts new file mode 100644 index 0000000000..f99689e9b8 --- /dev/null +++ b/packages/nocodb/src/plugins/scaleway/index.ts @@ -0,0 +1,80 @@ +import {XcPluginConfig} from "nc-plugin"; +import ScalewayObjectStoragePlugin from "./ScalewayObjectStoragePlugin"; +import {XcActionType, XcType} from "nc-common"; + +const config: XcPluginConfig = { + builder: ScalewayObjectStoragePlugin, + title: 'Scaleway Object Storage', + version: '0.0.1', + logo: 'plugins/scaleway.png', + tags: 'Storage', + description: 'S3-compatible Scaleway Object Storage makes it easy and more affordable to store and access data on Scaleway Cloud Platform infrastructure. The service also gives a 75GB free storage and external outgoing transfer on Object Storage every month', + inputs: { + title: 'Configure Scaleway Object Storage', + items: [{ + key: 'bucket', + label: 'Bucket Name', + placeholder: 'Bucket Name', + type: XcType.SingleLineText, + required: true + }, { + key: 'region', + label: 'Region', + placeholder: 'Region', + type: XcType.SingleLineText, + required: true + }, { + key: 'access_key', + label: 'Access Key', + placeholder: 'Access Key', + type: XcType.SingleLineText, + required: true + }, { + key: 'access_secret', + label: 'Access Secret', + placeholder: 'Access Secret', + type: XcType.Password, + required: true + },], + actions: [{ + label: 'Test', + placeholder: 'Test', + key: 'test', + actionType: XcActionType.TEST, + type: XcType.Button + }, { + label: 'Save', + placeholder: 'Save', + key: 'save', + actionType: XcActionType.SUBMIT, + type: XcType.Button + },], + msgOnInstall: 'Successfully installed and attachment will be stored in Scaleway Object Storage', + msgOnUninstall: '', + }, + category: 'Storage', +} + +export default config; + +/** + * @copyright Copyright (c) 2021, Bhanu P Chaudhary + * + * @author Bhanu P Chaudhary + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ \ No newline at end of file