Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Taking Codacy suggestions into account #16 #30

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 52 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,64 +13,62 @@ Making open cloud easily accessible and managed.

## 🚀 Install

```
```
npm install nodecloud
or
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 | - | - |

# ✌️ How to setup
* \*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

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;
```
Expand All @@ -79,64 +77,65 @@ 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
```

## ✒️ Run unit tests

```
```
$ yarn test
```

## 📜 License

MIT

4 changes: 2 additions & 2 deletions examples/compute/aws-ec2.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ const params = {

ec2
.stop(params)
.then(res => {
.then((res) => {
console.log(res);
})
.catch(err => {
.catch((err) => {
console.log(err);
});
4 changes: 2 additions & 2 deletions examples/compute/aws-ecs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
2 changes: 1 addition & 1 deletion examples/compute/google.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ gceCompute
.then(res => {
// console.log(res);
})
.catch(err => {
.catch((err) => {
console.log(err);
});
2 changes: 1 addition & 1 deletion examples/database/aws-dynamodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
4 changes: 2 additions & 2 deletions examples/database/aws-rds.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
4 changes: 2 additions & 2 deletions examples/database/google-datastore.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const params = {

gcd
.createItem(params)
.then(res => {
.then((res) => {
console.log(res);
})
.catch(err => {
.catch((err) => {
console.error(err);
});
4 changes: 2 additions & 2 deletions examples/network/aws-directconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
});
4 changes: 2 additions & 2 deletions examples/network/aws-elb.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ const params = {

elb
.create(params)
.then(res => {
.then((res) => {
console.log(res);
})
.catch(err => {
.catch((err) => {
console.error(err);
});
4 changes: 2 additions & 2 deletions examples/network/aws-route53.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const params = {

route53
.createZone(params)
.then(res => {
.then((res) => {
console.log(res);
})
.catch(err => {
.catch((err) => {
console.error(err);
});
4 changes: 2 additions & 2 deletions examples/network/google-dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const params = {

gceDNS
.createZone()
.then(res => {
.then((res) => {
console.log(res);
})
.catch(err => {
.catch((err) => {
console.error(err);
});
4 changes: 2 additions & 2 deletions examples/storage/aws-s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
});
4 changes: 2 additions & 2 deletions examples/storage/aws.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
});
4 changes: 2 additions & 2 deletions examples/storage/google-object-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ gcsBucket
regional: true
}
})
.then(res => {
.then((res) => {
console.log(res);
})
.catch(err => {
.catch((err) => {
console.log(err);
});
6 changes: 3 additions & 3 deletions lib/core/base-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ 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."
);
}

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");
}
Expand Down
4 changes: 2 additions & 2 deletions lib/core/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const baseProvider = require("./base-provider");
const BaseProvider = require("./base-provider");

/**
* Factory for getting providers
* @constructor
* @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 = {
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const core = require('./core');
const core = require("./core");

module.exports = core;
14 changes: 7 additions & 7 deletions test/core/base-provider.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
Loading