From f3e160bcd103143031438ebfaed1d7c8cb8e36e9 Mon Sep 17 00:00:00 2001 From: rajitha1998 Date: Tue, 7 Jan 2020 00:37:57 +0530 Subject: [PATCH 1/3] Taking codacy suggestions into account --- README.md | 2 +- examples/compute/aws-ec2.js | 4 ++-- examples/compute/aws-ecs.js | 4 ++-- examples/compute/google.js | 2 +- examples/database/aws-dynamodb.js | 2 +- examples/database/aws-rds.js | 4 ++-- examples/database/google-datastore.js | 4 ++-- examples/network/aws-directconnect.js | 4 ++-- examples/network/aws-elb.js | 4 ++-- examples/network/aws-route53.js | 4 ++-- examples/network/google-dns.js | 4 ++-- examples/storage/aws-s3.js | 4 ++-- examples/storage/aws.js | 4 ++-- examples/storage/google-object-storage.js | 4 ++-- lib/core/base-provider.js | 6 +++--- lib/core/index.js | 4 ++-- lib/index.js | 2 +- test/core/base-provider.js | 14 +++++++------- test/providers.js | 10 +++++----- 19 files changed, 43 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index 6506aa3c..0c4d42a3 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ yarn add nodecloud | Security/ Authorization | IAM | AWS IAM | - | - | - | - | | Utilities | Apps management | - | - | WebApps | - | - | -# ✌️ How to setup +## ✌️ How to setup Make sure you have `.nc.config.js` file in the project root. diff --git a/examples/compute/aws-ec2.js b/examples/compute/aws-ec2.js index 68ec05d2..2b6a2310 100644 --- a/examples/compute/aws-ec2.js +++ b/examples/compute/aws-ec2.js @@ -15,9 +15,9 @@ const params = { ec2 .stop(params) - .then(res => { + .then((res) => { console.log(res); }) - .catch(err => { + .catch((err) => { console.log(err); }); diff --git a/examples/compute/aws-ecs.js b/examples/compute/aws-ecs.js index 24d79246..c267004c 100644 --- a/examples/compute/aws-ecs.js +++ b/examples/compute/aws-ecs.js @@ -14,9 +14,9 @@ const params = { // describe ECS clusters ecs .describeClusters(params) - .then(res => { + .then((res) => { console.log(res); }) - .catch(err => { + .catch((err) => { console.error(err); }); diff --git a/examples/compute/google.js b/examples/compute/google.js index 0f3f98ff..8818a8cc 100644 --- a/examples/compute/google.js +++ b/examples/compute/google.js @@ -27,6 +27,6 @@ gceCompute .then(res => { // console.log(res); }) - .catch(err => { + .catch((err) => { console.log(err); }); diff --git a/examples/database/aws-dynamodb.js b/examples/database/aws-dynamodb.js index 6ad9cb24..670b3379 100644 --- a/examples/database/aws-dynamodb.js +++ b/examples/database/aws-dynamodb.js @@ -17,7 +17,7 @@ const params = { TableName: "Test" }; -dynamoDB.createItem(params).then(res => { +dynamoDB.createItem(params).then((res) => { assert.equal(res.ConsumedCapacity.TableName, "Test"); done(); }); diff --git a/examples/database/aws-rds.js b/examples/database/aws-rds.js index a92ffcee..c3bcf865 100644 --- a/examples/database/aws-rds.js +++ b/examples/database/aws-rds.js @@ -19,9 +19,9 @@ const params = { // create DB instance rds .createDBInstance(params) - .then(res => { + .then((res) => { console.log(res); }) - .catch(err => { + .catch((err) => { console.error(err); }); diff --git a/examples/database/google-datastore.js b/examples/database/google-datastore.js index c2d7f71d..8faabf90 100644 --- a/examples/database/google-datastore.js +++ b/examples/database/google-datastore.js @@ -16,9 +16,9 @@ const params = { gcd .createItem(params) - .then(res => { + .then((res) => { console.log(res); }) - .catch(err => { + .catch((err) => { console.error(err); }); diff --git a/examples/network/aws-directconnect.js b/examples/network/aws-directconnect.js index 549f6b8f..4b7e69e3 100644 --- a/examples/network/aws-directconnect.js +++ b/examples/network/aws-directconnect.js @@ -17,9 +17,9 @@ const params = { // create connection awsDc .createConnection(params) - .then(res => { + .then((res) => { console.log(`Connection created ! ${res}`); }) - .catch(err => { + .catch((err) => { console.error(`Oops something happened ${err}`); }); diff --git a/examples/network/aws-elb.js b/examples/network/aws-elb.js index 54f4824b..c0aa64bb 100644 --- a/examples/network/aws-elb.js +++ b/examples/network/aws-elb.js @@ -23,9 +23,9 @@ const params = { elb .create(params) - .then(res => { + .then((res) => { console.log(res); }) - .catch(err => { + .catch((err) => { console.error(err); }); diff --git a/examples/network/aws-route53.js b/examples/network/aws-route53.js index 42d5aca5..dffce245 100644 --- a/examples/network/aws-route53.js +++ b/examples/network/aws-route53.js @@ -18,9 +18,9 @@ const params = { route53 .createZone(params) - .then(res => { + .then((res) => { console.log(res); }) - .catch(err => { + .catch((err) => { console.error(err); }); diff --git a/examples/network/google-dns.js b/examples/network/google-dns.js index 3828c3ea..e5a3e37d 100644 --- a/examples/network/google-dns.js +++ b/examples/network/google-dns.js @@ -16,9 +16,9 @@ const params = { gceDNS .createZone() - .then(res => { + .then((res) => { console.log(res); }) - .catch(err => { + .catch((err) => { console.error(err); }); diff --git a/examples/storage/aws-s3.js b/examples/storage/aws-s3.js index cdb2c687..d32e0993 100644 --- a/examples/storage/aws-s3.js +++ b/examples/storage/aws-s3.js @@ -18,9 +18,9 @@ const params = { console.log("creating bucket"); s3.create(params) - .then(res => { + .then((res) => { console.log(`Bucket created ! ${res}`); }) - .catch(err => { + .catch((err) => { console.error(`Oops something happened ${err}`); }); diff --git a/examples/storage/aws.js b/examples/storage/aws.js index d2b95ce1..cef0ad08 100644 --- a/examples/storage/aws.js +++ b/examples/storage/aws.js @@ -19,9 +19,9 @@ console.log("creating ebs image"); // create AWS ESB image ebs .create(params) - .then(res => { + .then((res) => { console.log(`All done ! ${res}`); }) - .catch(err => { + .catch((err) => { console.error(`Oops something happened ${err}`); }); diff --git a/examples/storage/google-object-storage.js b/examples/storage/google-object-storage.js index 12e9c9f9..5961b5ec 100644 --- a/examples/storage/google-object-storage.js +++ b/examples/storage/google-object-storage.js @@ -14,9 +14,9 @@ gcsBucket regional: true } }) - .then(res => { + .then((res) => { console.log(res); }) - .catch(err => { + .catch((err) => { console.log(err); }); diff --git a/lib/core/base-provider.js b/lib/core/base-provider.js index c35413d7..cc3104e5 100644 --- a/lib/core/base-provider.js +++ b/lib/core/base-provider.js @@ -18,7 +18,7 @@ class Provider { * @param {Object} {provider - Type of provider - can be found here '/aws/provider'} */ getProviders(options) { - if (ncConfig === undefined) { + if (ncConfig) { throw new Error( "Provider config file not found. Please create a config file in project root." ); @@ -26,13 +26,13 @@ class Provider { let providersToLoad = {}; - if (options !== undefined && options.hasOwnProperty("overrideProviders")) { + if (options && options.hasOwnProperty("overrideProviders")) { ncConfig.map(provider => { const module = provider.plugin; providersToLoad[provider.tag] = module(provider.configPath); }); } else { - ncConfig.map(provider => { + ncConfig.map((provider) => { if (!validProviders.includes(provider.name)) { throw new Error("Provider not supported"); } diff --git a/lib/core/index.js b/lib/core/index.js index be3cabf7..1e929b7b 100644 --- a/lib/core/index.js +++ b/lib/core/index.js @@ -1,4 +1,4 @@ -const baseProvider = require("./base-provider"); +const BaseProvider = require("./base-provider"); /** * Factory for getting providers @@ -6,7 +6,7 @@ const baseProvider = require("./base-provider"); * @param {Object} {overrideProviders - Override supported list of providers: /lib/core/providers-list.js} */ function getProviders(options) { - return new baseProvider(options); + return new BaseProvider(options); } module.exports = { diff --git a/lib/index.js b/lib/index.js index cee2b133..f979d2ff 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,3 +1,3 @@ -const core = require('./core'); +const core = require("./core"); module.exports = core; diff --git a/test/core/base-provider.js b/test/core/base-provider.js index 0b90b39d..ec1fad5f 100644 --- a/test/core/base-provider.js +++ b/test/core/base-provider.js @@ -1,16 +1,16 @@ -const chai = require('chai'); +const chai = require("chai"); const assert = chai.assert; -const ncProvider = require('../../lib/core/base-provider'); -const providers = require('../../lib/providers'); +const NcProvider = require("../../lib/core/base-provider"); +const providers = require("../../lib/providers"); -describe('Base provider', () => { - it('should return AWS provider', (done) => { - const ncAWS = new ncProvider( +describe("Base provider", () => { + it("should return AWS provider", (done) => { + const ncAWS = new NcProvider( providers.AWS, null, ); - assert.typeOf(ncAWS, 'object'); + assert.typeOf(ncAWS, "object"); done(); }); }); diff --git a/test/providers.js b/test/providers.js index 06fcf270..55251925 100644 --- a/test/providers.js +++ b/test/providers.js @@ -1,10 +1,10 @@ -const chai = require('chai'); +const chai = require("chai"); const assert = chai.assert; -const providers = require('../lib/core/providers'); +const providers = require("../lib/core/providers"); -describe('Providers list', () => { - it('should check for providers', (done) => { - assert.typeOf(providers, 'object'); +describe("Providers list", () => { + it("should check for providers", (done) => { + assert.typeOf(providers, "object"); done(); }); }); From 9b7d7ecb10f3f156e2d4523b6a91a2152614d4bd Mon Sep 17 00:00:00 2001 From: rajitha1998 Date: Tue, 7 Jan 2020 01:05:38 +0530 Subject: [PATCH 2/3] formating the read me file using a markdown formatter --- README.md | 101 +++++++++++++++++++++++++++--------------------------- 1 file changed, 50 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 0c4d42a3..0bb33639 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Making open cloud easily accessible and managed. ## 🚀 Install -``` +``` npm install nodecloud or yarn add nodecloud @@ -21,31 +21,31 @@ yarn add nodecloud ## 📘 Service Providers -- AliCloud -- Amazon Web Services (AWS) -- Azure -- DigitalOcean -- Google Cloud Platform (GCP) +* AliCloud +* Amazon Web Services (AWS) +* Azure +* DigitalOcean +* Google Cloud Platform (GCP) ## 📟 Service Types -- \*yet to be implemented - -| Service Category | Service | AWS | GCP | Azure | DigitalOcean | AliCloud -| ----------------------- | ---------------- | -------------- | --------------------------------- | --------------------------- | ----------------------- | ----------------------- | -| Compute | IaaS | EC2 | Compute Engine | Virtual Machine | Droplets | ECS | -| | Containers | ECS | - | - | - | - | -| | Kubernetes\* | EKS | Kubernetes Engine | AKS | DO Kubernetes* | - | -| Storage | Object Storage | S3 | Cloud Storage | Blob, Queue, Table, Files\* | Spaces* | Bucket (OSS) & Table Store* | -| | Block Storage | EBS | Persistent Disks | - | Volumes | - | -| Networking | Load Balancer | ELB | GC Load Balancing\* | Virtual Networks | DO Load Balancers | SLB | -| | Peering | Direct Connect | Direct Peering*, Carrier Peering* | Azure API | - | - | -| | DNS | Route53 | Google DNS | Azure DNS\* | DO DNS* | Alibaba DNS | -| Databases | RDBMS | RDS | Cloud SQL\* | Azure Database | Managed Postgres* | Apsara RDS | -| | NoSQL: key-value | DynamoDB | Cloud Datastore | - | - | Apsara for MongoDB | -| | NoSQL: indexed | - | Cloud Datastore | - | - | - | -| Security/ Authorization | IAM | AWS IAM | - | - | - | - | -| Utilities | Apps management | - | - | WebApps | - | - | +* \*yet to be implemented + +| Service Category | Service | AWS | GCP | Azure | DigitalOcean | AliCloud | +|-------------------------|------------------|----------------|-----------------------------------|-----------------------------|-------------------|-----------------------------| +| Compute | IaaS | EC2 | Compute Engine | Virtual Machine | Droplets | ECS | +| | Containers | ECS | - | - | - | - | +| | Kubernetes\* | EKS | Kubernetes Engine | AKS | DO Kubernetes* | - | +| Storage | Object Storage | S3 | Cloud Storage | Blob, Queue, Table, Files\* | Spaces* | Bucket (OSS) & Table Store* | +| | Block Storage | EBS | Persistent Disks | - | Volumes | - | +| Networking | Load Balancer | ELB | GC Load Balancing\* | Virtual Networks | DO Load Balancers | SLB | +| | Peering | Direct Connect | Direct Peering*, Carrier Peering* | Azure API | - | - | +| | DNS | Route53 | Google DNS | Azure DNS\* | DO DNS* | Alibaba DNS | +| Databases | RDBMS | RDS | Cloud SQL\* | Azure Database | Managed Postgres* | Apsara RDS | +| | NoSQL: key-value | DynamoDB | Cloud Datastore | - | - | Apsara for MongoDB | +| | NoSQL: indexed | - | Cloud Datastore | - | - | - | +| Security/ Authorization | IAM | AWS IAM | - | - | - | - | +| Utilities | Apps management | - | - | WebApps | - | - | ## ✌️ How to setup @@ -54,23 +54,21 @@ Make sure you have `.nc.config.js` file in the project root. Content of `.nc.config.js` file is assumed as the following structure. It is an array of supported providers. -1. `name` : Provider identifier, this can be used to identify the plugin at a glance. -2. `tag` : Tag name that will be used to load the given provider internally. -3. `plugin` : Plugin module +1. `name` : Provider identifier, this can be used to identify the plugin at a glance. +2. `tag` : Tag name that will be used to load the given provider internally. +3. `plugin` : Plugin module This config file can contain array of objects for all providers and all will be loaded. Supported values for `name` : aws, azure, alicloud, digitalocean, google -```js +``` js const nodeCloudAwsPlugin = require("nodecloud-aws-plugin"); -const providers = [ - { +const providers = [{ name: "aws", tag: "aws", plugin: nodeCloudAwsPlugin - } -]; +}]; module.exports = providers; ``` @@ -79,53 +77,53 @@ module.exports = providers; ## 📣 Usage -```js +``` js const nodeCloud = require("nodecloud"); const optionsProvider = { - overrideProviders: false + overrideProviders: false }; const ncProviders = nodeCloud.getProviders(optionsProvider); const options = { - apiVersion: "2016-11-15" + apiVersion: "2016-11-15" }; const params = { - ImageId: "ami-10fd7020", // amzn-ami-2011.09.1.x86_64-ebs - InstanceType: "t1.micro", - MinCount: 1, - MaxCount: 1 + ImageId: "ami-10fd7020", // amzn-ami-2011.09.1.x86_64-ebs + InstanceType: "t1.micro", + MinCount: 1, + MaxCount: 1 }; const instanceParams = { - Key: "Name", - Value: "Node Cloud demo" + Key: "Name", + Value: "Node Cloud demo" }; const ec2 = ncProviders.aws.compute(options); ec2 - .createInstance(params, instanceParams) - .then(res => { - console.log(`All done ! ${res}`); - }) - .catch(err => { - console.log(`Oops something happened ${err}`); - }); + .createInstance(params, instanceParams) + .then(res => { + console.log( `All done ! ${res}` ); + }) + .catch(err => { + console.log( `Oops something happened ${err}` ); + }); ``` ## Override providers NodeCloud officialy supports AWS, GCP, Azure, DigitalOcean and AliCloud. If you want to use a community driven plugin override the providers list as follows. -```js +``` js const nodeCloud = require("nodecloud"); const options = { - overrideProviders: true + overrideProviders: true }; const ncProviders = nodeCloud.getProviders(options); ``` ## 💻 Development setup -``` +``` $ git clone https://github.com/cloudlibz/nodecloud $ cd nodecloud $ yarn install @@ -133,10 +131,11 @@ $ yarn install ## ✒️ Run unit tests -``` +``` $ yarn test ``` ## 📜 License MIT + From 99fe29bc19d6b5c9f7f152bf6ebe80317fcd9d04 Mon Sep 17 00:00:00 2001 From: rajitha1998 Date: Sat, 25 Jan 2020 18:48:37 +0530 Subject: [PATCH 3/3] formatting code with prettier --- .prettierrc | 1 + examples/compute/google.js | 2 +- lib/core/base-provider.js | 2 +- test/core/base-provider.js | 5 +---- 4 files changed, 4 insertions(+), 6 deletions(-) create mode 100644 .prettierrc diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000..ca82cc39 --- /dev/null +++ b/.prettierrc @@ -0,0 +1 @@ +{ "arrowParens": "always" } diff --git a/examples/compute/google.js b/examples/compute/google.js index 8818a8cc..6eddb2b1 100644 --- a/examples/compute/google.js +++ b/examples/compute/google.js @@ -24,7 +24,7 @@ gceCompute .list({ maxResults: 1 }) - .then(res => { + .then((res) => { // console.log(res); }) .catch((err) => { diff --git a/lib/core/base-provider.js b/lib/core/base-provider.js index cc3104e5..676ddc6e 100644 --- a/lib/core/base-provider.js +++ b/lib/core/base-provider.js @@ -27,7 +27,7 @@ class Provider { let providersToLoad = {}; if (options && options.hasOwnProperty("overrideProviders")) { - ncConfig.map(provider => { + ncConfig.map((provider) => { const module = provider.plugin; providersToLoad[provider.tag] = module(provider.configPath); }); diff --git a/test/core/base-provider.js b/test/core/base-provider.js index ec1fad5f..756dfb2f 100644 --- a/test/core/base-provider.js +++ b/test/core/base-provider.js @@ -5,10 +5,7 @@ const providers = require("../../lib/providers"); describe("Base provider", () => { it("should return AWS provider", (done) => { - const ncAWS = new NcProvider( - providers.AWS, - null, - ); + const ncAWS = new NcProvider(providers.AWS, null); assert.typeOf(ncAWS, "object"); done();