diff --git a/examples/cdn/aws-cloud-front.js b/examples/cdn/aws-cloud-front.js new file mode 100644 index 0000000..40e01f0 --- /dev/null +++ b/examples/cdn/aws-cloud-front.js @@ -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); +}); \ No newline at end of file diff --git a/lib/cdn/aws-cloud-fornt.js b/lib/cdn/aws-cloud-fornt.js new file mode 100644 index 0000000..22e3760 --- /dev/null +++ b/lib/cdn/aws-cloud-fornt.js @@ -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; diff --git a/lib/core/aws/provider.js b/lib/core/aws/provider.js index 66a8e56..29c3f37 100644 --- a/lib/core/aws/provider.js +++ b/lib/core/aws/provider.js @@ -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 { /** @@ -42,6 +43,7 @@ class AWS { rdbms: this.RDS, nosql: this.DynamoDB, iam: this.IAM, + cdn: this.CloudFront, }; } /** @@ -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;