Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
ba2d6f4237 | |||
ff71de8f6c | |||
e99d597c12 | |||
f44698078e | |||
0ed9c7f4f4 | |||
f4d4bc238b | |||
f4c2bb6e5b | |||
b2182ec63d | |||
6cc91c0a5e |
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@ ts/**/*.js
|
||||
ts/**/*.js.map
|
||||
.idea/
|
||||
node_modules/
|
||||
nogit/
|
||||
|
19
dist/cflare.classes.cflareaccount.d.ts
vendored
Normal file
19
dist/cflare.classes.cflareaccount.d.ts
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
import "typings-global";
|
||||
export declare class CflareAccount {
|
||||
private authEmail;
|
||||
private authKey;
|
||||
private authCheck();
|
||||
constructor();
|
||||
auth(optionsArg: {
|
||||
email: string;
|
||||
key: string;
|
||||
}): void;
|
||||
getZoneId(domainName: string): any;
|
||||
getRecord(domainNameArg: string, typeArg: string): any;
|
||||
createRecord(domainNameArg: string, typeArg: string, contentArg: string): any;
|
||||
removeRecord(domainNameArg: string, typeArg: string): any;
|
||||
updateRecord(domainNameArg: string, typeArg: string, valueArg: any): any;
|
||||
listRecords(domainNameArg: string): any;
|
||||
listZones(domainName?: string): any;
|
||||
request(methodArg: string, routeArg: string, dataArg?: {}): any;
|
||||
}
|
139
dist/cflare.classes.cflareaccount.js
vendored
Normal file
139
dist/cflare.classes.cflareaccount.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
dist/cflare.classes.helpers.d.ts
vendored
Normal file
1
dist/cflare.classes.helpers.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
import "typings-global";
|
3
dist/cflare.classes.helpers.js
vendored
3
dist/cflare.classes.helpers.js
vendored
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsImZpbGUiOiJjZmxhcmUuY2xhc3Nlcy5oZWxwZXJzLmpzIiwic291cmNlc0NvbnRlbnQiOltdLCJzb3VyY2VSb290IjoiL3NvdXJjZS8ifQ==
|
||||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNmbGFyZS5jbGFzc2VzLmhlbHBlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQSIsImZpbGUiOiJjZmxhcmUuY2xhc3Nlcy5oZWxwZXJzLmpzIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IFwidHlwaW5ncy1nbG9iYWxcIjtcclxuaW1wb3J0IHBsdWdpbnMgPSByZXF1aXJlKFwiLi9jZmxhcmUucGx1Z2luc1wiKTsiXX0=
|
||||
|
10
dist/cflare.classes.js
vendored
10
dist/cflare.classes.js
vendored
@ -1,10 +0,0 @@
|
||||
"use strict";
|
||||
var cflare = (function () {
|
||||
function cflare() {
|
||||
}
|
||||
;
|
||||
return cflare;
|
||||
}());
|
||||
;
|
||||
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNmbGFyZS5jbGFzc2VzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFJQTtJQUdJO0lBRUEsQ0FBQzs7SUFFTCxhQUFDO0FBQUQsQ0FQQSxBQU9DLElBQUE7QUFBQSxDQUFDIiwiZmlsZSI6ImNmbGFyZS5jbGFzc2VzLmpzIiwic291cmNlc0NvbnRlbnQiOlsiLy8vIDxyZWZlcmVuY2UgcGF0aD1cIi4vdHlwaW5ncy9tYWluLmQudHNcIiAvPlxuaW1wb3J0IHBsdWdpbnMgPSByZXF1aXJlKFwiLi9jZmxhcmUucGx1Z2luc1wiKTtcbmltcG9ydCBoZWxwZXJzID0gcmVxdWlyZShcIi4vY2ZsYXJlLmNsYXNzZXMuaGVscGVyc1wiKTtcblxuY2xhc3MgY2ZsYXJlIHtcbiAgICBwcml2YXRlIGF1dGhFbWFpbDpzdHJpbmc7XG4gICAgcHJpdmF0ZSBhdXRoS2V5OnN0cmluZztcbiAgICBjb25zdHJ1Y3Rvcigpe1xuICAgICAgICBcbiAgICB9O1xuICAgIFxufTsiXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=
|
5
dist/cflare.plugins.d.ts
vendored
Normal file
5
dist/cflare.plugins.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
import "typings-global";
|
||||
export declare let beautylog: any;
|
||||
export declare let q: any;
|
||||
export declare let request: any;
|
||||
export import smartstring = require("smartstring");
|
6
dist/cflare.plugins.js
vendored
6
dist/cflare.plugins.js
vendored
@ -1,6 +1,8 @@
|
||||
"use strict";
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
require("typings-global");
|
||||
exports.beautylog = require("beautylog");
|
||||
exports.q = require("q");
|
||||
exports.request = require("request");
|
||||
exports.smartstring = require("smartstring");
|
||||
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNmbGFyZS5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSw0Q0FBNEM7QUFDakMsaUJBQVMsR0FBRyxPQUFPLENBQUMsV0FBVyxDQUFDLENBQUM7QUFDakMsZUFBTyxHQUFHLE9BQU8sQ0FBQyxTQUFTLENBQUMsQ0FBQyIsImZpbGUiOiJjZmxhcmUucGx1Z2lucy5qcyIsInNvdXJjZXNDb250ZW50IjpbIi8vLyA8cmVmZXJlbmNlIHBhdGg9XCIuL3R5cGluZ3MvbWFpbi5kLnRzXCIgLz5cbmV4cG9ydCBsZXQgYmVhdXR5bG9nID0gcmVxdWlyZShcImJlYXV0eWxvZ1wiKTtcbmV4cG9ydCBsZXQgcmVxdWVzdCA9IHJlcXVpcmUoXCJyZXF1ZXN0XCIpOyJdLCJzb3VyY2VSb290IjoiL3NvdXJjZS8ifQ==
|
||||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNmbGFyZS5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDYixpQkFBUyxHQUFHLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FBQztBQUNqQyxTQUFDLEdBQUcsT0FBTyxDQUFDLEdBQUcsQ0FBQyxDQUFDO0FBQ2pCLGVBQU8sR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDLENBQUM7QUFDMUIsbUJBQVcsV0FBVyxhQUFhLENBQUMsQ0FBQyIsImZpbGUiOiJjZmxhcmUucGx1Z2lucy5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBcInR5cGluZ3MtZ2xvYmFsXCI7XHJcbmV4cG9ydCBsZXQgYmVhdXR5bG9nID0gcmVxdWlyZShcImJlYXV0eWxvZ1wiKTtcclxuZXhwb3J0IGxldCBxID0gcmVxdWlyZShcInFcIik7XHJcbmV4cG9ydCBsZXQgcmVxdWVzdCA9IHJlcXVpcmUoXCJyZXF1ZXN0XCIpO1xyXG5leHBvcnQgaW1wb3J0IHNtYXJ0c3RyaW5nID0gcmVxdWlyZShcInNtYXJ0c3RyaW5nXCIpOyJdfQ==
|
||||
|
2
dist/index.d.ts
vendored
Normal file
2
dist/index.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import "typings-global";
|
||||
export { CflareAccount } from "./cflare.classes.cflareaccount";
|
5
dist/index.js
vendored
5
dist/index.js
vendored
@ -1,3 +1,6 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
var cflare_classes_cflareaccount_1 = require("./cflare.classes.cflareaccount");
|
||||
exports.CflareAccount = cflare_classes_cflareaccount_1.CflareAccount;
|
||||
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsImZpbGUiOiJpbmRleC5qcyIsInNvdXJjZXNDb250ZW50IjpbXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=
|
||||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDeEIsNkNBQTRCLGdDQUFnQyxDQUFDO0FBQXJELHFFQUFxRCIsImZpbGUiOiJpbmRleC5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBcInR5cGluZ3MtZ2xvYmFsXCI7XHJcbmV4cG9ydCB7Q2ZsYXJlQWNjb3VudH0gZnJvbSBcIi4vY2ZsYXJlLmNsYXNzZXMuY2ZsYXJlYWNjb3VudFwiOyJdfQ==
|
||||
|
12
package.json
12
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cflare",
|
||||
"version": "0.0.2",
|
||||
"version": "0.0.3",
|
||||
"description": "cloudflare management for CoreOS",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
@ -21,11 +21,15 @@
|
||||
},
|
||||
"homepage": "https://github.com/pushrocks/cflare#readme",
|
||||
"dependencies": {
|
||||
"beautylog": "^4.1.2",
|
||||
"beautylog": "^5.0.6",
|
||||
"q": "^1.4.1",
|
||||
"request": "^2.72.0"
|
||||
"request": "^2.72.0",
|
||||
"smartstring": "^2.0.1",
|
||||
"typings-global": "^1.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"npmts": "^5.0.4"
|
||||
"npmts": "^5.1.14",
|
||||
"should": "^8.4.0",
|
||||
"typings-test": "^1.0.1"
|
||||
}
|
||||
}
|
||||
|
1
test/test.d.ts
vendored
Normal file
1
test/test.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
import "typings-test";
|
72
test/test.js
Normal file
72
test/test.js
Normal file
File diff suppressed because one or more lines are too long
71
test/test.ts
Normal file
71
test/test.ts
Normal file
@ -0,0 +1,71 @@
|
||||
import "typings-test";
|
||||
import cflare = require("../dist/index");
|
||||
let should = require("should");
|
||||
let nogit = require("../nogit/nogit.json");
|
||||
|
||||
let testCflareAccount = new cflare.CflareAccount();
|
||||
testCflareAccount.auth({
|
||||
email: nogit.cfemail,
|
||||
key: nogit.cfkey
|
||||
});
|
||||
|
||||
describe("cflare",function(){
|
||||
describe(".CflareAccount",function(){
|
||||
describe(".listZones()",function(){
|
||||
it("should display an account",function(done){
|
||||
this.timeout(10000);
|
||||
testCflareAccount.listZones()
|
||||
.then((responseArg)=>{
|
||||
console.log(responseArg);
|
||||
done();
|
||||
})
|
||||
});
|
||||
});
|
||||
describe(".getZoneId(domainName)",function(){
|
||||
it("should get an Cloudflare Id for a domain string",function(done){
|
||||
this.timeout(10000)
|
||||
testCflareAccount.getZoneId("push.rocks")
|
||||
.then((responseArg)=>{
|
||||
console.log(responseArg);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe(".listRecords(domainName)",function(){
|
||||
it("should list all records for a specific Domain Name",function(done){
|
||||
this.timeout(10000);
|
||||
testCflareAccount.listRecords("push.rocks")
|
||||
.then((responseArg) => {
|
||||
console.log(responseArg);
|
||||
done();
|
||||
});
|
||||
});
|
||||
})
|
||||
describe(".createRecord",function(){
|
||||
this.timeout(10000);
|
||||
it("should create a valid record for a level 2 domain",function(done){
|
||||
testCflareAccount.createRecord("bleu.de","A","127.0.0.1")
|
||||
.then(function(responseArg){
|
||||
console.log(responseArg);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("should create a valid record for a subdomain",function(done){
|
||||
testCflareAccount.createRecord("subdomain.bleu.de","A","127.0.0.1")
|
||||
.then(function(responseArg){
|
||||
console.log(responseArg);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe(".removeRecord",function(){
|
||||
/*it("should remove a record from Cloudflare",function(done){
|
||||
testCflareAccount.removeRecord()
|
||||
.then(function(responseArg){
|
||||
console.log(responseArg);
|
||||
done();
|
||||
});
|
||||
});*/
|
||||
});
|
||||
})
|
||||
});
|
125
ts/cflare.classes.cflareaccount.ts
Normal file
125
ts/cflare.classes.cflareaccount.ts
Normal file
@ -0,0 +1,125 @@
|
||||
import "typings-global";
|
||||
import plugins = require("./cflare.plugins");
|
||||
import helpers = require("./cflare.classes.helpers");
|
||||
|
||||
export class CflareAccount {
|
||||
private authEmail:string;
|
||||
private authKey:string;
|
||||
private authCheck(){
|
||||
return (this.authEmail && this.authKey); //check if auth is available
|
||||
}
|
||||
constructor(){
|
||||
|
||||
};
|
||||
auth(optionsArg:{email:string,key:string}){
|
||||
this.authEmail = optionsArg.email;
|
||||
this.authKey = optionsArg.key;
|
||||
}
|
||||
getZoneId(domainName:string){
|
||||
let done = plugins.q.defer();
|
||||
this.listZones(domainName)
|
||||
.then((responseArg) => {
|
||||
let filteredResponse = responseArg.result.filter((zoneArg)=>{
|
||||
return zoneArg.name === domainName;
|
||||
});
|
||||
if (filteredResponse.length >= 1){
|
||||
done.resolve(filteredResponse[0].id);
|
||||
} else {
|
||||
plugins.beautylog.error("the domain " + domainName.blue + " does not appear to be in this account!");
|
||||
done.reject(undefined);
|
||||
}
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
getRecord(domainNameArg:string,typeArg:string){
|
||||
let done = plugins.q.defer();
|
||||
let domain = new plugins.smartstring.Domain(domainNameArg);
|
||||
this.listRecords(domain.zoneName)
|
||||
.then((responseArg) => {
|
||||
let filteredResponse = responseArg.result.filter((recordArg) => {
|
||||
return (recordArg.type == typeArg && recordArg.name == domainNameArg);
|
||||
})
|
||||
})
|
||||
return done.promise;
|
||||
};
|
||||
createRecord(domainNameArg:string,typeArg:string,contentArg:string){
|
||||
let done = plugins.q.defer();
|
||||
let domain = new plugins.smartstring.Domain(domainNameArg);
|
||||
this.getZoneId(domain.zoneName)
|
||||
.then((domainIdArg)=>{
|
||||
let dataObject = {
|
||||
name: domain.fullName,
|
||||
type: typeArg,
|
||||
content: contentArg
|
||||
};
|
||||
this.request("POST","/zones/" + domainIdArg + "/dns_records",dataObject)
|
||||
.then(function(responseArg){
|
||||
done.resolve(responseArg);
|
||||
});
|
||||
});
|
||||
return done.promise;
|
||||
};
|
||||
removeRecord(domainNameArg:string,typeArg:string){
|
||||
let done = plugins.q.defer();
|
||||
let domain = new plugins.smartstring.Domain(domainNameArg);
|
||||
this.getRecord(domain.zoneName,typeArg)
|
||||
.then((responseArg) => {
|
||||
|
||||
});
|
||||
return done.promise;
|
||||
};
|
||||
updateRecord(domainNameArg:string,typeArg:string,valueArg){
|
||||
let done = plugins.q.defer();
|
||||
let domain = new plugins.smartstring.Domain(domainNameArg);
|
||||
return done.promise;
|
||||
};
|
||||
listRecords(domainNameArg:string){
|
||||
let done = plugins.q.defer();
|
||||
let domain = new plugins.smartstring.Domain(domainNameArg);
|
||||
this.getZoneId(domain.zoneName)
|
||||
.then((domainIdArg)=>{
|
||||
this.request("GET","/zones/" + domainIdArg + "/dns_records?per_page=100")
|
||||
.then(function(responseArg){
|
||||
done.resolve(responseArg);
|
||||
});
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
listZones(domainName?:string){ // TODO: handle pagination
|
||||
let done = plugins.q.defer();
|
||||
let requestRoute = "/zones?per_page=50"
|
||||
if(domainName) requestRoute = requestRoute + "&name=" + domainName;
|
||||
let result = {};
|
||||
this.request("GET",requestRoute)
|
||||
.then(function(responseArg){
|
||||
result = responseArg;
|
||||
done.resolve(result);
|
||||
});
|
||||
return done.promise;
|
||||
};
|
||||
request(methodArg:string,routeArg:string,dataArg = {}){
|
||||
let done = plugins.q.defer();
|
||||
let jsonArg:string = JSON.stringify(dataArg);
|
||||
let options = {
|
||||
method:methodArg,
|
||||
url:"https://api.cloudflare.com/client/v4" + routeArg,
|
||||
headers:{
|
||||
"Content-Type":"application/json",
|
||||
"X-Auth-Email":this.authEmail,
|
||||
"X-Auth-Key":this.authKey
|
||||
},
|
||||
body:jsonArg
|
||||
};
|
||||
plugins.request(options,function(err, res, body){
|
||||
if (!err && res.statusCode == 200) {
|
||||
var responseObj = JSON.parse(body);
|
||||
done.resolve(responseObj);
|
||||
} else {
|
||||
console.log(err);
|
||||
console.log(res);
|
||||
done.reject(err);
|
||||
};
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
};
|
@ -1,2 +1,2 @@
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
import "typings-global";
|
||||
import plugins = require("./cflare.plugins");
|
@ -1,38 +0,0 @@
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
import plugins = require("./cflare.plugins");
|
||||
import helpers = require("./cflare.classes.helpers");
|
||||
|
||||
class cflare {
|
||||
private authEmail:string;
|
||||
private authKey:string;
|
||||
private authCheck(){
|
||||
return (this.authEmail && this.authKey); //check if auth is available
|
||||
}
|
||||
constructor(){
|
||||
|
||||
};
|
||||
auth(optionsArg:{email:string,key:string}){
|
||||
this.authEmail = optionsArg.email;
|
||||
this.authKey = optionsArg.key;
|
||||
}
|
||||
createRecord(){
|
||||
let done = plugins.q.defer();
|
||||
return done.promise;
|
||||
};
|
||||
removeRecord(){
|
||||
let done = plugins.q.defer();
|
||||
return done.promise;
|
||||
};
|
||||
listRecords(){
|
||||
let done = plugins.q.defer();
|
||||
return done.promise;
|
||||
}
|
||||
listDomains(){
|
||||
let done = plugins.q.defer();
|
||||
return done.promise;
|
||||
};
|
||||
request(){
|
||||
let done = plugins.q.defer();
|
||||
return done.promise;
|
||||
}
|
||||
};
|
@ -1,4 +1,5 @@
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
import "typings-global";
|
||||
export let beautylog = require("beautylog");
|
||||
export let q = require("q");
|
||||
export let request = require("request");
|
||||
export let request = require("request");
|
||||
export import smartstring = require("smartstring");
|
@ -1,2 +1,2 @@
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
import plugins = require("./cflare.plugins");
|
||||
import "typings-global";
|
||||
export {CflareAccount} from "./cflare.classes.cflareaccount";
|
@ -3,6 +3,7 @@
|
||||
"dependencies": {},
|
||||
"ambientDependencies": {
|
||||
"colors": "registry:dt/colors#0.6.0-1+20160425153322",
|
||||
"mocha": "registry:dt/mocha#2.2.5+20160317120654",
|
||||
"node": "registry:dt/node#4.0.0+20160423143914"
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user