From 2317562e87fe13e98d206085866b089e52a4e8ed Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Tue, 15 Oct 2019 14:16:28 +0200 Subject: [PATCH] fix(core): update --- package-lock.json | 85 +++++++++------------------ package.json | 1 + qenv.yml | 3 + test/test.ts | 22 ++++++- ts/index.ts | 5 +- ts/smartbucket.classes.bucket.ts | 23 +++++++- ts/smartbucket.classes.smartbucket.ts | 35 ++++++----- 7 files changed, 98 insertions(+), 76 deletions(-) create mode 100644 qenv.yml diff --git a/package-lock.json b/package-lock.json index 9cd0f33..51deef6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -107,6 +107,15 @@ "symbol-tree": "^3.2.4" } }, + "@pushrocks/qenv": { + "version": "4.0.6", + "resolved": "https://verdaccio.lossless.one/@pushrocks%2fqenv/-/qenv-4.0.6.tgz", + "integrity": "sha512-4uQyhkXYAcNW+f2ZA0DHok6Sb4i91jGW6Nom47JMIRxrNNs0okqA5AW5tdz4S1NcJO9s+0rx3rrGlGeADygn2Q==", + "requires": { + "@pushrocks/smartfile": "^7.0.6", + "@pushrocks/smartlog": "^2.0.19" + } + }, "@pushrocks/smartcli": { "version": "3.0.7", "resolved": "https://registry.npmjs.org/@pushrocks/smartcli/-/smartcli-3.0.7.tgz", @@ -171,7 +180,6 @@ "version": "7.0.6", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartfile/-/smartfile-7.0.6.tgz", "integrity": "sha512-X1kWg1HSQ/MqasRIHPCf6D9CRrcIrpTjW8KLc4GkApJ/W/IVaKsQkJQfdimlg1uc/9v8AYnoRdiGa51yxyghZA==", - "dev": true, "requires": { "@pushrocks/smarthash": "^2.0.6", "@pushrocks/smartpath": "^4.0.1", @@ -187,7 +195,6 @@ "version": "2.0.6", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmarthash/-/smarthash-2.0.6.tgz", "integrity": "sha512-jHk9srgRLkszk/oPCUOkxTX2Fqu7qKwx13aEeSIBx8UCtFbXPLecJAqEaGEVk1mw9e4Oq0iC6O0jEnxKo5NQwA==", - "dev": true, "requires": { "@pushrocks/smartjson": "^3.0.5", "@pushrocks/smartpromise": "^3.0.2", @@ -199,7 +206,6 @@ "version": "3.0.8", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartjson/-/smartjson-3.0.8.tgz", "integrity": "sha512-EjC3611RSZaZmK+nXxXrYDBxdxYWtrxjOrZtQzbYn0yM33KSCH0sLIAG8B2wYZVAOj4A2pC8mVxFSJ1w3iRFHg==", - "dev": true, "requires": { "@types/fast-json-stable-stringify": "^2.0.0", "fast-json-stable-stringify": "^2.0.0", @@ -210,7 +216,6 @@ "version": "2.0.19", "resolved": "https://registry.npmjs.org/@pushrocks/smartlog/-/smartlog-2.0.19.tgz", "integrity": "sha512-I2mDx7WcUlADYWxu5nNP3NSJv95YrCZoG/rarbEqovK7pJQ9a0aINmIcCHkQeL1VSWvxgvhXwHyV/yNEJ4zh3Q==", - "dev": true, "requires": { "@pushrocks/smartlog-interfaces": "^2.0.5" } @@ -218,8 +223,7 @@ "@pushrocks/smartlog-interfaces": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/@pushrocks/smartlog-interfaces/-/smartlog-interfaces-2.0.5.tgz", - "integrity": "sha512-eLNlRpDwy3E+6v/B6fo/NiAo+UxBO3SxKgIIsgUGbWfVpsyUi0PG2xfVCdhJlhL1AsRRvKglfHSOB8qKE+XCLw==", - "dev": true + "integrity": "sha512-eLNlRpDwy3E+6v/B6fo/NiAo+UxBO3SxKgIIsgUGbWfVpsyUi0PG2xfVCdhJlhL1AsRRvKglfHSOB8qKE+XCLw==" }, "@pushrocks/smartlog-source-ora": { "version": "1.0.8", @@ -253,8 +257,7 @@ "@pushrocks/smartpath": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/@pushrocks/smartpath/-/smartpath-4.0.1.tgz", - "integrity": "sha512-MaI0+uLQPCr2V3WGnbdgb0pWa9xkWyrP4qYcbsHIjeismGLbn9s3jmP/HIXU8LkgzRgaVb+BJxmZJHOwl32DyA==", - "dev": true + "integrity": "sha512-MaI0+uLQPCr2V3WGnbdgb0pWa9xkWyrP4qYcbsHIjeismGLbn9s3jmP/HIXU8LkgzRgaVb+BJxmZJHOwl32DyA==" }, "@pushrocks/smartpromise": { "version": "3.0.6", @@ -265,7 +268,6 @@ "version": "1.1.36", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrequest/-/smartrequest-1.1.36.tgz", "integrity": "sha512-qeTRLFZZ3WOui7TkMNg8eGgZe3J9HG2XoaxR8hW65oX+TBUHcMEwA6EKuBaTWk6WUe/aJmfClw9DjjBnFCqtvQ==", - "dev": true, "requires": { "@pushrocks/smartpromise": "^3.0.5", "@types/form-data": "^2.5.0", @@ -360,8 +362,7 @@ "@types/fast-json-stable-stringify": { "version": "2.0.0", "resolved": "https://verdaccio.lossless.one/@types%2ffast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", - "integrity": "sha512-mky/O83TXmGY39P1H9YbUpjV6l6voRYlufqfFCvel8l1phuy8HRjdWc1rrPuN53ITBJlbyMSV6z3niOySO5pgQ==", - "dev": true + "integrity": "sha512-mky/O83TXmGY39P1H9YbUpjV6l6voRYlufqfFCvel8l1phuy8HRjdWc1rrPuN53ITBJlbyMSV6z3niOySO5pgQ==" }, "@types/figures": { "version": "3.0.1", @@ -376,7 +377,6 @@ "version": "2.5.0", "resolved": "https://verdaccio.lossless.one/@types%2fform-data/-/form-data-2.5.0.tgz", "integrity": "sha512-23/wYiuckYYtFpL+4RPWiWmRQH2BjFuqCUi2+N3amB1a1Drv+i/byTrGvlLwRVLFNAZbwpbQ7JvTK+VCAPMbcg==", - "dev": true, "requires": { "form-data": "*" } @@ -385,7 +385,6 @@ "version": "8.0.0", "resolved": "https://verdaccio.lossless.one/@types%2ffs-extra/-/fs-extra-8.0.0.tgz", "integrity": "sha512-bCtL5v9zdbQW86yexOlXWTEGvLNqWxMFyi7gQA7Gcthbezr2cPSOb8SkESVKA937QD5cIwOFLDFt0MQoXOEr9Q==", - "dev": true, "requires": { "@types/node": "*" } @@ -419,7 +418,6 @@ "version": "2.0.34", "resolved": "https://verdaccio.lossless.one/@types%2fthrough2/-/through2-2.0.34.tgz", "integrity": "sha512-nhRG8+RuG/L+0fAZBQYaRflXKjTrHOKH8MFTChnf+dNVMxA3wHYYrfj0tztK0W51ABXjGfRCDc0vRkecCOrsow==", - "dev": true, "requires": { "@types/node": "*" } @@ -440,7 +438,6 @@ "version": "4.1.0", "resolved": "https://verdaccio.lossless.one/agentkeepalive/-/agentkeepalive-4.1.0.tgz", "integrity": "sha512-CW/n1wxF8RpEuuiq6Vbn9S8m0VSYDMnZESqaJ6F2cWN9fY8rei2qaxweIaRgq+ek8TqfoFIsUjaGNKGGEHElSg==", - "dev": true, "requires": { "debug": "^4.1.0", "depd": "^1.1.2", @@ -451,7 +448,6 @@ "version": "4.1.1", "resolved": "https://verdaccio.lossless.one/debug/-/debug-4.1.1.tgz", "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", - "dev": true, "requires": { "ms": "^2.1.1" } @@ -489,7 +485,6 @@ "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", - "dev": true, "requires": { "sprintf-js": "~1.0.2" } @@ -508,14 +503,12 @@ "asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=", - "dev": true + "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" }, "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", - "dev": true + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" }, "block-stream2": { "version": "2.0.0", @@ -541,7 +534,6 @@ "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -668,7 +660,6 @@ "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dev": true, "requires": { "delayed-stream": "~1.0.0" } @@ -682,8 +673,7 @@ "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, "core-util-is": { "version": "1.0.2", @@ -755,14 +745,12 @@ "delayed-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=", - "dev": true + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" }, "depd": { "version": "1.1.2", "resolved": "https://verdaccio.lossless.one/depd/-/depd-1.1.2.tgz", - "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=", - "dev": true + "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=" }, "diff": { "version": "4.0.1", @@ -820,8 +808,7 @@ "esprima": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", - "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", - "dev": true + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==" }, "esutils": { "version": "2.0.3", @@ -847,8 +834,7 @@ "fast-json-stable-stringify": { "version": "2.0.0", "resolved": "https://verdaccio.lossless.one/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", - "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=", - "dev": true + "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=" }, "figures": { "version": "3.0.0", @@ -872,7 +858,6 @@ "version": "2.5.1", "resolved": "https://verdaccio.lossless.one/form-data/-/form-data-2.5.1.tgz", "integrity": "sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA==", - "dev": true, "requires": { "asynckit": "^0.4.0", "combined-stream": "^1.0.6", @@ -883,7 +868,6 @@ "version": "8.1.0", "resolved": "https://verdaccio.lossless.one/fs-extra/-/fs-extra-8.1.0.tgz", "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==", - "dev": true, "requires": { "graceful-fs": "^4.2.0", "jsonfile": "^4.0.0", @@ -893,8 +877,7 @@ "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", - "dev": true + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, "function-bind": { "version": "1.1.1", @@ -926,7 +909,6 @@ "version": "7.1.4", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz", "integrity": "sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==", - "dev": true, "requires": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -939,8 +921,7 @@ "graceful-fs": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.0.tgz", - "integrity": "sha512-jpSvDPV4Cq/bgtpndIWbI5hmYxhQGHPC4d4cqBPb4DLniCfhJokdXhwhaDuLBGLQdvvRum/UiX6ECVIPvDXqdg==", - "dev": true + "integrity": "sha512-jpSvDPV4Cq/bgtpndIWbI5hmYxhQGHPC4d4cqBPb4DLniCfhJokdXhwhaDuLBGLQdvvRum/UiX6ECVIPvDXqdg==" }, "has": { "version": "1.0.3", @@ -965,7 +946,6 @@ "version": "1.2.1", "resolved": "https://verdaccio.lossless.one/humanize-ms/-/humanize-ms-1.2.1.tgz", "integrity": "sha1-xG4xWaKT9riW2ikxbYtv6Lt5u+0=", - "dev": true, "requires": { "ms": "^2.0.0" } @@ -974,7 +954,6 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "dev": true, "requires": { "once": "^1.3.0", "wrappy": "1" @@ -1056,7 +1035,6 @@ "version": "3.13.1", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz", "integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==", - "dev": true, "requires": { "argparse": "^1.0.7", "esprima": "^4.0.0" @@ -1071,7 +1049,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", - "dev": true, "requires": { "graceful-fs": "^4.1.6" } @@ -1103,8 +1080,7 @@ "lodash.clonedeep": { "version": "4.5.0", "resolved": "https://verdaccio.lossless.one/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", - "integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8=", - "dev": true + "integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8=" }, "log-symbols": { "version": "2.2.0", @@ -1170,7 +1146,6 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "dev": true, "requires": { "brace-expansion": "^1.1.7" } @@ -1226,8 +1201,7 @@ "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, "nice-try": { "version": "1.0.5", @@ -1273,7 +1247,6 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "dev": true, "requires": { "wrappy": "1" } @@ -1371,8 +1344,7 @@ "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", - "dev": true + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" }, "path-key": { "version": "2.0.1", @@ -1553,8 +1525,7 @@ "sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", - "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", - "dev": true + "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=" }, "string-width": { "version": "2.1.1", @@ -1708,8 +1679,7 @@ "universalify": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", - "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", - "dev": true + "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==" }, "util-deprecate": { "version": "1.0.2", @@ -1799,8 +1769,7 @@ "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "dev": true + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, "xml": { "version": "1.0.1", diff --git a/package.json b/package.json index 32cf4f7..ed9f12f 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "tslint-config-prettier": "^1.18.0" }, "dependencies": { + "@pushrocks/qenv": "^4.0.6", "@pushrocks/smartpromise": "^3.0.6", "@types/minio": "^7.0.3", "minio": "^7.0.12" diff --git a/qenv.yml b/qenv.yml new file mode 100644 index 0000000..843591d --- /dev/null +++ b/qenv.yml @@ -0,0 +1,3 @@ +required: + - S3_KEY + - S3_SECRET \ No newline at end of file diff --git a/test/test.ts b/test/test.ts index a2fed0a..68639a0 100644 --- a/test/test.ts +++ b/test/test.ts @@ -1,8 +1,26 @@ import { expect, tap } from '@pushrocks/tapbundle'; +import { Qenv } from '@pushrocks/qenv'; + import * as smartbucket from '../ts/index'; -tap.test('first test', async () => { - console.log('hi'); +const testQenv = new Qenv('./', './.nogit/'); + +let testSmartbucket: smartbucket.SmartBucket; + +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 a bucket', async () => { + await testSmartbucket.createBucket('smartbucket'); +}); + +tap.skip.test('should remove testbucket', async () => { + await testSmartbucket.removeBucket('pushrocks-smartbucket'); }); tap.start(); diff --git a/ts/index.ts b/ts/index.ts index 65d677f..fb22716 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -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'; diff --git a/ts/smartbucket.classes.bucket.ts b/ts/smartbucket.classes.bucket.ts index 288210f..4bba3ce 100644 --- a/ts/smartbucket.classes.bucket.ts +++ b/ts/smartbucket.classes.bucket.ts @@ -1,3 +1,24 @@ import * as plugins from './smartbucket.plugins'; +import { SmartBucket } from './smartbucket.classes.smartbucket'; -export class Bucket {} +export class Bucket { + public static async createFromName(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); + } + } + + public smartbucketRef: SmartBucket; + public name: string; + constructor(smartbucketRef: SmartBucket, bucketName: string) { + this.smartbucketRef = smartbucketRef; + this.name = bucketName; + } +} diff --git a/ts/smartbucket.classes.smartbucket.ts b/ts/smartbucket.classes.smartbucket.ts index 4e39600..1e32f0f 100644 --- a/ts/smartbucket.classes.smartbucket.ts +++ b/ts/smartbucket.classes.smartbucket.ts @@ -1,33 +1,40 @@ import * as plugins from './smartbucket.plugins'; +import { Bucket } from './smartbucket.classes.bucket'; export interface ISmartBucketConfig { - provider: 'digitalocean'; - projectId: string; - bucketName: string; + endpoint: string; + accessKey: string; + accessSecret: string; } export class SmartBucket { public config: ISmartBucketConfig; - public minioClient = new plugins.minio.Client({ - endPoint: 'ams3.digitaloceanspaces.com', - port: 9000, - useSSL: true, - accessKey: 'Q3AM3UQ867SPQQA43P2F', - secretKey: 'zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG' - }); + public minioClient: plugins.minio.Client; /** * the constructor of SmartBucket */ constructor(configArg: ISmartBucketConfig) { 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 + }); } - /** - * initializes the Smartbucket - */ - public async init() { + public async createBucket(bucketName: string) { + await this.minioClient.makeBucket(bucketName, 'ams3').catch(e => console.log(e)); + } + public async removeBucket(bucketName: string) { + await this.minioClient.removeBucket(bucketName).catch(e => console.log(e)); + } + + public async getBucket(bucketName: string) { + return Bucket.getFromName(this, bucketName); } }