Compare commits

..

14 Commits

Author SHA1 Message Date
fbac742db2 1.0.11 2019-10-16 15:21:02 +02:00
3456459456 fix(core): update 2019-10-16 15:21:02 +02:00
c4374da42a 1.0.10 2019-10-15 20:00:00 +02:00
7ba61904ee fix(core): update 2019-10-15 20:00:00 +02:00
f5da38592e 1.0.9 2019-10-15 19:23:06 +02:00
caf0566020 fix(core): update 2019-10-15 19:23:06 +02:00
c333533c63 1.0.8 2019-10-15 14:16:29 +02:00
2317562e87 fix(core): update 2019-10-15 14:16:28 +02:00
9f0b1dab55 1.0.7 2019-10-14 23:53:42 +02:00
9b84cf8bc0 fix(core): update 2019-10-14 23:53:41 +02:00
d966e29b8c 1.0.6 2019-10-14 20:55:25 +02:00
ec9551a772 fix(core): update 2019-10-14 20:55:25 +02:00
8462536b6a 1.0.5 2019-10-14 20:55:08 +02:00
2250f9f1cc fix(core): update 2019-10-14 20:55:07 +02:00
15 changed files with 1432 additions and 730 deletions

View File

@ -38,22 +38,34 @@ snyk:
# test stage # test stage
# ==================== # ====================
testLTS: testStable:
stage: test stage: test
script: script:
- npmci npm prepare - npmci npm prepare
- npmci node install lts - npmci node install stable
- npmci npm install - npmci npm install
- npmci npm test - npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- priv
testBuild:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv - notpriv
release: release:
stage: release stage: release
script: script:
- npmci node install lts - npmci node install stable
- npmci npm publish - npmci npm publish
only: only:
- tags - tags
@ -69,6 +81,7 @@ codequality:
allow_failure: true allow_failure: true
script: script:
- npmci command npm install -g tslint typescript - npmci command npm install -g tslint typescript
- npmci npm prepare
- npmci npm install - npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts" - npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags: tags:
@ -86,9 +99,9 @@ trigger:
- notpriv - notpriv
pages: pages:
image: hosttoday/ht-docker-node:npmci
stage: metadata stage: metadata
script: script:
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc - npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare - npmci npm prepare
- npmci npm install - npmci npm install

29
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,29 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "current file",
"type": "node",
"request": "launch",
"args": [
"${relativeFile}"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "test.ts",
"type": "node",
"request": "launch",
"args": [
"test/test.ts"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
}
]
}

20
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,20 @@
{
"json.schemas": [
{
"fileMatch": ["/npmextra.json"],
"schema": {
"type": "object",
"properties": {
"npmci": {
"type": "object",
"description": "settings for npmci"
},
"gitzone": {
"type": "object",
"description": "settings for gitzone"
}
}
}
}
]
}

View File

@ -1,8 +1,6 @@
{ {
"npmci": { "npmci": {
"npmGlobalTools": [ "npmGlobalTools": []
"npmts"
]
}, },
"gitzone": { "gitzone": {
"module": { "module": {

1867
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,34 +1,38 @@
{ {
"name": "@pushrocks/smartbucket", "name": "@pushrocks/smartbucket",
"version": "1.0.4", "version": "1.0.11",
"description": "simple cloud independent object storage", "description": "simple cloud independent object storage",
"main": "dist/index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts", "typings": "dist/index.d.ts",
"author": "Lossless GmbH", "author": "Lossless GmbH",
"license": "UNLICENSED", "license": "UNLICENSED",
"scripts": { "scripts": {
"test": "(npmts)", "test": "tstest test/",
"format": "(gitzone format)", "format": "(gitzone format)",
"build": "echo \"Not needed for now\"" "build": "echo \"Not needed for now\""
}, },
"devDependencies": { "devDependencies": {
"@pushrocks/tapbundle": "^3.0.11", "@gitzone/tsbuild": "^2.1.17",
"tslint": "^5.18.0", "@gitzone/tstest": "^1.0.28",
"@pushrocks/tapbundle": "^3.0.13",
"tslint": "^5.20.0",
"tslint-config-prettier": "^1.18.0" "tslint-config-prettier": "^1.18.0"
}, },
"dependencies": { "dependencies": {
"@google-cloud/storage": "^3.0.2", "@pushrocks/qenv": "^4.0.6",
"@pushrocks/smartpromise": "^3.0.2", "@pushrocks/smartpromise": "^3.0.6",
"@types/minio": "^7.0.2", "@pushrocks/streamfunction": "^1.0.24",
"minio": "^7.0.10" "@types/minio": "^7.0.3",
"minio": "^7.0.12"
}, },
"private": true, "private": false,
"files": [ "files": [
"ts/*", "ts/**/*",
"ts_web/*", "ts_web/**/*",
"dist/*", "dist/**/*",
"dist_web/*", "dist_web/**/*",
"assets/*", "dist_ts_web/**/*",
"assets/**/*",
"cli.js", "cli.js",
"npmextra.json", "npmextra.json",
"readme.md" "readme.md"

3
qenv.yml Normal file
View File

@ -0,0 +1,3 @@
required:
- S3_KEY
- S3_SECRET

View File

@ -21,6 +21,6 @@ simple cloud independent object storage
For further information read the linked docs at the top of this readme. For further information read the linked docs at the top of this readme.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh) > MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html) | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://maintainedby.lossless.com) [![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

View File

@ -1,8 +1,47 @@
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@pushrocks/tapbundle';
import { Qenv } from '@pushrocks/qenv';
import * as smartbucket from '../ts/index'; import * as smartbucket from '../ts/index';
tap.test('first test', async () => { const testQenv = new Qenv('./', './.nogit/');
console.log('hi');
let testSmartbucket: smartbucket.SmartBucket;
let myBucket: smartbucket.Bucket;
tap.test('should create a valid smartbucket', async () => {
testSmartbucket = new smartbucket.SmartBucket({
accessKey: testQenv.getEnvVarOnDemand('S3_KEY'),
accessSecret: testQenv.getEnvVarOnDemand('S3_SECRET'),
endpoint: 'ams3.digitaloceanspaces.com'
});
}); });
tap.skip.test('should create testbucket', async () => {
await testSmartbucket.createBucket('smartbucket');
});
tap.skip.test('should remove testbucket', async () => {
await testSmartbucket.removeBucket('pushrocks-smartbucket');
});
tap.test('should get a bucket', async () => {
myBucket = await testSmartbucket.getBucketByName('smartbucket');
expect(myBucket).to.be.instanceOf(smartbucket.Bucket);
expect(myBucket.name).to.equal('smartbucket');
});
tap.test('should store data in bucket', async () => {
await myBucket.store('hithere/socool.txt', 'hi there!');
});
tap.test('should get data in bucket', async () => {
const fileString = await myBucket.get('hithere/socool.txt');
console.log(fileString);
});
tap.test('should delete data in bucket', async () => {
await myBucket.remove('hithere/socool.txt');
});
tap.start(); tap.start();

View File

@ -1 +1,4 @@
import * as plugins from './smartbucket.plugins'; export * from './smartbucket.classes.smartbucket';
export * from './smartbucket.classes.bucket';
export * from './smartbucket.classes.directory';
export * from './smartbucket.classes.file';

View File

@ -0,0 +1,79 @@
import * as plugins from './smartbucket.plugins';
import { SmartBucket } from './smartbucket.classes.smartbucket';
export class Bucket {
public static async getBucketByName(smartbucketRef: SmartBucket, bucketNameArg: string) {
const buckets = await smartbucketRef.minioClient.listBuckets();
const foundBucket = buckets.find(bucket => {
return bucket.name === bucketNameArg;
});
if (foundBucket) {
console.log(`bucket with name ${bucketNameArg} exists.`)
console.log(`Taking this as base for new Bucket instance`);
return new this(smartbucketRef, bucketNameArg);
} else {
return null;
}
}
public static async createBucketByName(smartbucketRef: SmartBucket, bucketName: string) {
await smartbucketRef.minioClient.makeBucket(bucketName, 'ams3').catch(e => console.log(e));
return new Bucket(smartbucketRef, bucketName);
}
public static async removeBucketByName(smartbucketRef: SmartBucket, bucketName: string) {
await smartbucketRef.minioClient.removeBucket(bucketName).catch(e => console.log(e));
}
public smartbucketRef: SmartBucket;
public name: string;
constructor(smartbucketRef: SmartBucket, bucketName: string) {
this.smartbucketRef = smartbucketRef;
this.name = bucketName;
}
/**
* store file
*/
public async store(pathArg: string, fileContent: string) {
const streamIntake = new plugins.streamfunction.Intake();
const putPromise = this.smartbucketRef.minioClient.putObject(this.name, pathArg, streamIntake.getReadable()).catch(e => console.log(e));
streamIntake.pushData(fileContent);
streamIntake.signalEnd();
await putPromise;
}
/**
* get file
*/
public async get(pathArg: string) {
const done = plugins.smartpromise.defer();
const fileStream = await this.smartbucketRef.minioClient.getObject(this.name, pathArg).catch(e => console.log(e));
let completeFile: string = '';
const duplexStream = plugins.streamfunction.createDuplexStream<Buffer, Buffer>(async (chunk) => {
const chunkString = chunk.toString();
completeFile += chunkString;
return chunk;
}, async (cb) => {
done.resolve();
return Buffer.from('');
});
if (!fileStream) {
return null;
}
fileStream.pipe(duplexStream);
await done.promise;
return completeFile;
}
/**
* removeObject
*/
public async remove (pathArg: string) {
await this.smartbucketRef.minioClient.removeObject(this.name, pathArg);
}
}

View File

@ -0,0 +1,3 @@
import * as plugins from './smartbucket.plugins';
export class Directory {}

View File

@ -0,0 +1,3 @@
import * as plugins from './smartbucket.plugins';
export class File {}

View File

@ -1,30 +1,41 @@
import * as plugins from './smartbucket.plugins'; import * as plugins from './smartbucket.plugins';
import { Bucket } from './smartbucket.classes.bucket';
export interface ISmartBucketConfig { export interface ISmartBucketConfig {
provider: 'google'; endpoint: string;
projectId: string; accessKey: string;
bucketName: string; accessSecret: string;
} }
export class SmartBucket { export class SmartBucket {
config: ISmartBucketConfig; public config: ISmartBucketConfig;
private _googleBucket;
public minioClient: plugins.minio.Client;
/** /**
* the constructor of SmartBucket * the constructor of SmartBucket
*/ */
constructor(configArg: ISmartBucketConfig) { constructor(configArg: ISmartBucketConfig) {
this.config = configArg; this.config = configArg;
this.minioClient = new plugins.minio.Client({
endPoint: this.config.endpoint,
port: 443,
useSSL: true,
accessKey: this.config.accessKey,
secretKey: this.config.accessSecret
});
} }
/** public async createBucket(bucketNameArg: string) {
* initializes the Smartbucket const bucket = await Bucket.createBucketByName(this, bucketNameArg);
*/ return bucket;
async init() {
if (this.config.provider === 'google') {
const storage = new plugins.googleCloudStorage.Storage({
projectId: this.config.projectId
});
storage.createBucket(this.config.bucketName, () => {});
} }
public async removeBucket(bucketName: string) {
await Bucket.removeBucketByName(this, bucketName);
}
public async getBucketByName(bucketName: string) {
return Bucket.getBucketByName(this, bucketName);
} }
} }

View File

@ -1,9 +1,11 @@
import * as smartpromise from '@pushrocks/smartpromise'; import * as smartpromise from '@pushrocks/smartpromise';
import * as streamfunction from '@pushrocks/streamfunction';
export { smartpromise }; export { smartpromise, streamfunction };
// third party scope // third party scope
import * as googleCloudStorage from '@google-cloud/storage';
import * as minio from 'minio'; import * as minio from 'minio';
export { googleCloudStorage }; export {
minio
};