Skip to content
This repository was archived by the owner on Nov 22, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all 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
19 changes: 19 additions & 0 deletions examples/cdn/aws-cloud-front.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const nodecloud = require('../../lib');

const ncAWS = nodecloud.getProvider("AWS", process.env.ncconf);

const options = {
apiVersion: "2016-11-15"
};

const cloudFront = ncAWS.cdn(options);

const params = {
MaxItems: '100'
};

cloudFront.listDistributions(params).then(res => {
console.log(JSON.stringify(res));
}).catch(err => {
console.error(err);
});
127 changes: 127 additions & 0 deletions lib/cdn/aws-cloud-fornt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
const helpers = require('../core/helpers');

const { checkParams } = helpers;

class CloudFront {
/**
* CloudFront constructor
* @constructor
* @param {object} aws - AWS SDK
* @param {object} options - { apiVersion }
*/
constructor(aws, options) {
this._AWS = aws;
if (options) {
this._apiVersion = options.apiVersion;
this._cloudFront = new this._AWS.CloudFront({
apiVersion: this._apiVersion,
});
} else {
this._cloudFront = new this._AWS.CloudFront();
}
}
/**
* Create Cloud Distribution
* @createDistribution
* @param {object} params
*/
createDistribution(params) {
checkParams(params);
return new Promise((resolve, reject) => {
this._cloudFront.createDistribution(params, (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
}
/**
* list Cloud Distributions
* @listDistributions
* @param {object} params
*/
listDistributions(params) {
checkParams(params);
return new Promise((resolve, reject) => {
this._cloudFront.listDistributions(params, (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
}
/**
* delete Cloud Distribution
* @deleteDistribution
* @param {object} params
*/
deleteDistribution(params) {
checkParams(params);
return new Promise((resolve, reject) => {
this._cloudFront.deleteDistribution(params, (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
}
/**
* update Cloud Distribution
* @updateDistribution
* @param {object} params
*/
updateDistribution(params) {
checkParams(params);
return new Promise((resolve, reject) => {
this._cloudFront.updateDistribution(params, (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
}
/**
* create Cloud Invalidation
* @createInvalidation
* @param {object} params
*/
createInvalidation(params) {
checkParams(params);
return new Promise((resolve, reject) => {
this._cloudFront.createInvalidation(params, (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
}
/**
* list Cloud Invalidation
* @listInvalidations
* @param {object} params
*/
listInvalidations(params) {
checkParams(params);
return new Promise((resolve, reject) => {
this._cloudFront.listInvalidations(params, (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
}
}

module.exports = CloudFront;
14 changes: 14 additions & 0 deletions lib/core/aws/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const DirectConnect = require('../../network/aws-directconnect');
const RDS = require('../../database/aws-rds');
const DynamoDB = require('../../database/aws-dynamodb');
const IAM = require('../../security/aws-iam');
const CloudFront = require('../../cdn/aws-cloud-fornt');

class AWS {
/**
Expand Down Expand Up @@ -42,6 +43,7 @@ class AWS {
rdbms: this.RDS,
nosql: this.DynamoDB,
iam: this.IAM,
cdn: this.CloudFront,
};
}
/**
Expand Down Expand Up @@ -158,6 +160,18 @@ class AWS {
}
return new IAM(this.getSDK());
}
/**
* CloudFront wrapper
* @CloudFront
* @param {object} options - { apiVersion }
*/
CloudFront(options) {
if (options.apiVersion) {
this._apiVersion = options.apiVersion;
return new CloudFront(this.getSDK(), options);
}
return new CloudFront(this.getSDK());
}
}

module.exports = AWS;