Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
bf15b8aec7 | |||
55b305ca1c | |||
9699e4bf76 | |||
0692d16dd7 | |||
c76643d700 | |||
de088ba550 | |||
1ecf660368 | |||
a04ce339f2 | |||
feed201dc1 | |||
cb73164c8f |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,6 +1,5 @@
|
||||
coverage/
|
||||
docs/
|
||||
ts/typings/
|
||||
node_modules/
|
||||
|
||||
.nogit/
|
||||
|
21
dist/cflare.classes.cflareaccount.d.ts
vendored
21
dist/cflare.classes.cflareaccount.d.ts
vendored
@ -1,19 +1,20 @@
|
||||
import "typings-global";
|
||||
import 'typings-global';
|
||||
import * as interfaces from './cflare.interfaces';
|
||||
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;
|
||||
getZoneId(domainName: string): Promise<{}>;
|
||||
getRecord(domainNameArg: string, typeArg: string): Promise<interfaces.ICflareRecord>;
|
||||
createRecord(domainNameArg: string, typeArg: string, contentArg: string): Promise<{}>;
|
||||
removeRecord(domainNameArg: string, typeArg: string): Promise<{}>;
|
||||
updateRecord(domainNameArg: string, typeArg: string, valueArg: any): Promise<{}>;
|
||||
listRecords(domainNameArg: string): Promise<interfaces.ICflareRecord[]>;
|
||||
listZones(domainName?: string): Promise<interfaces.ICflareZone[]>;
|
||||
request(methodArg: string, routeArg: string, dataArg?: {}): Promise<{}>;
|
||||
private authCheck();
|
||||
}
|
||||
|
186
dist/cflare.classes.cflareaccount.js
vendored
186
dist/cflare.classes.cflareaccount.js
vendored
File diff suppressed because one or more lines are too long
3
dist/cflare.classes.helpers.js
vendored
3
dist/cflare.classes.helpers.js
vendored
@ -1,4 +1,3 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
|
||||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNmbGFyZS5jbGFzc2VzLmhlbHBlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQSIsImZpbGUiOiJjZmxhcmUuY2xhc3Nlcy5oZWxwZXJzLmpzIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IFwidHlwaW5ncy1nbG9iYWxcIjtcbmltcG9ydCBwbHVnaW5zID0gcmVxdWlyZShcIi4vY2ZsYXJlLnBsdWdpbnNcIik7Il19
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2ZsYXJlLmNsYXNzZXMuaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2NmbGFyZS5jbGFzc2VzLmhlbHBlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF3QiJ9
|
56
dist/cflare.interfaces.d.ts
vendored
Normal file
56
dist/cflare.interfaces.d.ts
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
export interface ICflareZone {
|
||||
"id": string;
|
||||
"name": string;
|
||||
"development_mode": number;
|
||||
"original_name_servers": string[];
|
||||
"original_registrar": string;
|
||||
"original_dnshost": string;
|
||||
"created_on": string;
|
||||
"modified_on": string;
|
||||
"name_servers": string[];
|
||||
"owner": {
|
||||
"id": string;
|
||||
"email": string;
|
||||
"owner_type": string;
|
||||
};
|
||||
"permissions": string[];
|
||||
"plan": {
|
||||
"id": string;
|
||||
"name": string;
|
||||
"price": number;
|
||||
"currency": string;
|
||||
"frequency": string;
|
||||
"legacy_id": string;
|
||||
"is_subscribed": boolean;
|
||||
"can_subscribe": boolean;
|
||||
};
|
||||
"plan_pending": {
|
||||
"id": string;
|
||||
"name": string;
|
||||
"price": number;
|
||||
"currency": string;
|
||||
"frequency": string;
|
||||
"legacy_id": string;
|
||||
"is_subscribed": string;
|
||||
"can_subscribe": string;
|
||||
};
|
||||
"status": string;
|
||||
"paused": boolean;
|
||||
"type": string;
|
||||
"checked_on": string;
|
||||
}
|
||||
export interface ICflareRecord {
|
||||
"id": string;
|
||||
"type": string;
|
||||
"name": string;
|
||||
"content": string;
|
||||
"proxiable": boolean;
|
||||
"proxied": boolean;
|
||||
"ttl": number;
|
||||
"locked": boolean;
|
||||
"zone_id": string;
|
||||
"zone_name": string;
|
||||
"created_on": string;
|
||||
"modified_on": string;
|
||||
"data": any;
|
||||
}
|
2
dist/cflare.interfaces.js
vendored
Normal file
2
dist/cflare.interfaces.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2ZsYXJlLmludGVyZmFjZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9jZmxhcmUuaW50ZXJmYWNlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIn0=
|
5
dist/cflare.plugins.d.ts
vendored
5
dist/cflare.plugins.d.ts
vendored
@ -1,5 +1,6 @@
|
||||
import "typings-global";
|
||||
export declare let beautylog: any;
|
||||
export declare let q: any;
|
||||
export declare let request: any;
|
||||
export import q = require("smartq");
|
||||
export import smartrequest = require("smartrequest");
|
||||
export import smartstring = require("smartstring");
|
||||
export import smartdelay = require('smartdelay');
|
||||
|
8
dist/cflare.plugins.js
vendored
8
dist/cflare.plugins.js
vendored
@ -1,8 +1,8 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
exports.beautylog = require("beautylog");
|
||||
exports.q = require("q");
|
||||
exports.request = require("request");
|
||||
exports.q = require("smartq");
|
||||
exports.smartrequest = require("smartrequest");
|
||||
exports.smartstring = require("smartstring");
|
||||
|
||||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNmbGFyZS5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDYixpQkFBUyxHQUFHLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FBQztBQUNqQyxTQUFDLEdBQUcsT0FBTyxDQUFDLEdBQUcsQ0FBQyxDQUFDO0FBQ2pCLGVBQU8sR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDLENBQUM7QUFDMUIsbUJBQVcsV0FBVyxhQUFhLENBQUMsQ0FBQyIsImZpbGUiOiJjZmxhcmUucGx1Z2lucy5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBcInR5cGluZ3MtZ2xvYmFsXCI7XG5leHBvcnQgbGV0IGJlYXV0eWxvZyA9IHJlcXVpcmUoXCJiZWF1dHlsb2dcIik7XG5leHBvcnQgbGV0IHEgPSByZXF1aXJlKFwicVwiKTtcbmV4cG9ydCBsZXQgcmVxdWVzdCA9IHJlcXVpcmUoXCJyZXF1ZXN0XCIpO1xuZXhwb3J0IGltcG9ydCBzbWFydHN0cmluZyA9IHJlcXVpcmUoXCJzbWFydHN0cmluZ1wiKTsiXX0=
|
||||
exports.smartdelay = require("smartdelay");
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2ZsYXJlLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9jZmxhcmUucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXdCO0FBQ2IsUUFBQSxTQUFTLEdBQUcsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFDO0FBQzVDLDhCQUFvQztBQUNwQywrQ0FBcUQ7QUFDckQsNkNBQW1EO0FBQ25ELDJDQUFpRCJ9
|
3
dist/index.js
vendored
3
dist/index.js
vendored
@ -2,5 +2,4 @@
|
||||
require("typings-global");
|
||||
var cflare_classes_cflareaccount_1 = require("./cflare.classes.cflareaccount");
|
||||
exports.CflareAccount = cflare_classes_cflareaccount_1.CflareAccount;
|
||||
|
||||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDeEIsNkNBQTRCLGdDQUFnQyxDQUFDO0FBQXJELHFFQUFxRCIsImZpbGUiOiJpbmRleC5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBcInR5cGluZ3MtZ2xvYmFsXCI7XG5leHBvcnQge0NmbGFyZUFjY291bnR9IGZyb20gXCIuL2NmbGFyZS5jbGFzc2VzLmNmbGFyZWFjY291bnRcIjsiXX0=
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXdCO0FBQ3hCLCtFQUE2RDtBQUFyRCx1REFBQSxhQUFhLENBQUEifQ==
|
21
package.json
21
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cflare",
|
||||
"version": "0.0.6",
|
||||
"version": "0.0.12",
|
||||
"description": "cloudflare management for CoreOS",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
@ -22,16 +22,17 @@
|
||||
},
|
||||
"homepage": "https://github.com/pushrocks/cflare#readme",
|
||||
"dependencies": {
|
||||
"beautylog": "^5.0.12",
|
||||
"q": "^1.4.1",
|
||||
"request": "^2.72.0",
|
||||
"smartstring": "^2.0.9",
|
||||
"typings-global": "^1.0.3"
|
||||
"beautylog": "^6.1.1",
|
||||
"smartdelay": "^1.0.1",
|
||||
"smartq": "^1.1.0",
|
||||
"smartrequest": "^1.0.4",
|
||||
"smartstring": "^2.0.22",
|
||||
"typings-global": "^1.0.14"
|
||||
},
|
||||
"devDependencies": {
|
||||
"npmts-g": "^5.2.6",
|
||||
"qenv": "^1.0.8",
|
||||
"should": "^9.0.2",
|
||||
"typings-test": "^1.0.1"
|
||||
"npmts-g": "^6.0.0",
|
||||
"qenv": "^1.1.3",
|
||||
"smartchai": "^1.0.1",
|
||||
"typings-test": "^1.0.3"
|
||||
}
|
||||
}
|
||||
|
2
test/test.d.ts
vendored
2
test/test.d.ts
vendored
@ -1 +1 @@
|
||||
import "typings-test";
|
||||
import 'typings-test';
|
||||
|
124
test/test.js
124
test/test.js
File diff suppressed because one or more lines are too long
160
test/test.ts
160
test/test.ts
@ -1,88 +1,88 @@
|
||||
import "typings-test";
|
||||
import cflare = require("../dist/index");
|
||||
let should = require("should");
|
||||
import {Qenv} from "qenv";
|
||||
let testQenv = new Qenv(process.cwd(),process.cwd() + "/.nogit");
|
||||
console.log(testQenv.missingEnvVars);
|
||||
let testCflareAccount = new cflare.CflareAccount();
|
||||
import 'typings-test'
|
||||
import cflare = require('../dist/index')
|
||||
import { expect } from 'smartchai'
|
||||
import { Qenv } from 'qenv'
|
||||
let testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit')
|
||||
console.log(testQenv.missingEnvVars)
|
||||
let testCflareAccount = new cflare.CflareAccount()
|
||||
testCflareAccount.auth({
|
||||
email: process.env.CF_EMAIL,
|
||||
key: process.env.CF_KEY
|
||||
});
|
||||
})
|
||||
|
||||
describe("cflare",function(){
|
||||
describe(".CflareAccount",function(){
|
||||
describe(".listZones()",function(){
|
||||
it("should display an entire account",function(done){
|
||||
this.timeout(10000);
|
||||
describe('cflare', function () {
|
||||
describe('.CflareAccount', function () {
|
||||
describe('.listZones()', function () {
|
||||
it('should display an entire account', function (done) {
|
||||
this.timeout(30000)
|
||||
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("bleu.de")
|
||||
.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("bleu.de")
|
||||
.then((responseArg) => {
|
||||
console.log(responseArg);
|
||||
done();
|
||||
});
|
||||
});
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
describe('.getZoneId(domainName)', function () {
|
||||
it('should get an Cloudflare Id for a domain string', function (done) {
|
||||
this.timeout(30000)
|
||||
testCflareAccount.getZoneId('bleu.de')
|
||||
.then((responseArg) => {
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
describe('.listRecords(domainName)', function () {
|
||||
it('should list all records for a specific Domain Name', function (done) {
|
||||
this.timeout(30000)
|
||||
testCflareAccount.listRecords('bleu.de')
|
||||
.then((responseArg) => {
|
||||
console.log(responseArg)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
describe('.createRecord', function () {
|
||||
it('should create a valid record for a level 2 domain', function (done) {
|
||||
this.timeout(30000)
|
||||
testCflareAccount.createRecord('bleu.de', 'A', '127.0.0.1')
|
||||
.then(function (responseArg) {
|
||||
done()
|
||||
})
|
||||
})
|
||||
it('should create a valid record for a subdomain', function (done) {
|
||||
this.timeout(30000)
|
||||
testCflareAccount.createRecord('subdomain.bleu.de', 'A', '127.0.0.1')
|
||||
.then(function (responseArg) {
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
describe('.getRecord', function () {
|
||||
it('should get a record from Cloudflare', function (done) {
|
||||
this.timeout(30000)
|
||||
testCflareAccount.getRecord('bleu.de', 'A')
|
||||
.then(function (responseArg) {
|
||||
console.log(responseArg)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
describe('.removeRecord', function () {
|
||||
it('should remove a record from Cloudflare', function (done) {
|
||||
this.timeout(30000)
|
||||
testCflareAccount.removeRecord('bleu.de', 'A')
|
||||
.then(function (responseArg) {
|
||||
console.log(responseArg)
|
||||
done()
|
||||
})
|
||||
})
|
||||
it('should remove a subdomain record from Cloudflare', function (done) {
|
||||
this.timeout(30000)
|
||||
testCflareAccount.removeRecord('subdomain.bleu.de', 'A')
|
||||
.then(function (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(".getRecord",function(){
|
||||
it("should get a record from Cloudflare",function(done){
|
||||
testCflareAccount.getRecord("bleu.de","A")
|
||||
.then(function(responseArg){
|
||||
console.log(responseArg);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe(".removeRecord",function(){
|
||||
it("should remove a record from Cloudflare",function(done){
|
||||
testCflareAccount.removeRecord("bleu.de","A")
|
||||
.then(function(responseArg){
|
||||
console.log(responseArg);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("should remove a subdomain record from Cloudflare",function(done){
|
||||
testCflareAccount.removeRecord("subdomain.bleu.de","A")
|
||||
.then(function(responseArg){
|
||||
console.log(responseArg);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
});
|
||||
})
|
||||
|
@ -1,135 +1,161 @@
|
||||
import "typings-global";
|
||||
import plugins = require("./cflare.plugins");
|
||||
import helpers = require("./cflare.classes.helpers");
|
||||
import 'typings-global';
|
||||
import plugins = require('./cflare.plugins')
|
||||
import helpers = require('./cflare.classes.helpers')
|
||||
import * as interfaces from './cflare.interfaces'
|
||||
|
||||
export class CflareAccount {
|
||||
private authEmail:string;
|
||||
private authKey:string;
|
||||
private authCheck(){
|
||||
return (this.authEmail && this.authKey); //check if auth is available
|
||||
}
|
||||
constructor(){
|
||||
private authEmail: string
|
||||
private authKey: string
|
||||
constructor() {
|
||||
|
||||
};
|
||||
auth(optionsArg:{email:string,key:string}){
|
||||
this.authEmail = optionsArg.email;
|
||||
this.authKey = optionsArg.key;
|
||||
}
|
||||
getZoneId(domainName:string){
|
||||
let done = plugins.q.defer();
|
||||
|
||||
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);
|
||||
.then(zoneArrayArg => {
|
||||
let filteredResponse = zoneArrayArg.filter((zoneArg) => {
|
||||
return zoneArg.name === domainName
|
||||
})
|
||||
done.resolve(filteredResponse[0]);
|
||||
if (filteredResponse.length >= 1) {
|
||||
done.resolve(filteredResponse[ 0 ].id)
|
||||
} else {
|
||||
plugins.beautylog.error(`the domain ${domainName} does not appear to be in this account!`)
|
||||
done.reject(undefined)
|
||||
}
|
||||
})
|
||||
return done.promise;
|
||||
return done.promise
|
||||
}
|
||||
getRecord(domainNameArg: string, typeArg: string): Promise<interfaces.ICflareRecord> {
|
||||
let done = plugins.q.defer()
|
||||
let result: interfaces.ICflareRecord
|
||||
|
||||
let domain = new plugins.smartstring.Domain(domainNameArg)
|
||||
this.listRecords(domain.zoneName)
|
||||
.then((recordArrayArg) => {
|
||||
let filteredResponse = recordArrayArg.filter((recordArg) => {
|
||||
return (recordArg.type === typeArg && recordArg.name === domainNameArg)
|
||||
})
|
||||
done.resolve(filteredResponse[ 0 ])
|
||||
})
|
||||
return done.promise
|
||||
};
|
||||
createRecord(domainNameArg:string,typeArg:string,contentArg:string){
|
||||
let done = plugins.q.defer();
|
||||
let domain = new plugins.smartstring.Domain(domainNameArg);
|
||||
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)=>{
|
||||
.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.fullName,typeArg)
|
||||
.then((responseArg) => {
|
||||
if(responseArg){
|
||||
let requestRoute:string = "/zones/" + responseArg.zone_id + "/dns_records/" + responseArg.id;
|
||||
this.request("DELETE",requestRoute)
|
||||
.then((responseArg) => {
|
||||
done.resolve(responseArg);
|
||||
});
|
||||
} else {
|
||||
done.reject();
|
||||
}
|
||||
});
|
||||
return done.promise;
|
||||
this.request('POST', '/zones/' + domainIdArg + '/dns_records', dataObject)
|
||||
.then(function (responseArg) {
|
||||
done.resolve(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;
|
||||
removeRecord(domainNameArg: string, typeArg: string) {
|
||||
let done = plugins.q.defer()
|
||||
let domain = new plugins.smartstring.Domain(domainNameArg)
|
||||
this.getRecord(domain.fullName, typeArg)
|
||||
.then((responseArg) => {
|
||||
if (responseArg) {
|
||||
let requestRoute: string = '/zones/' + responseArg.zone_id + '/dns_records/' + responseArg.id
|
||||
this.request('DELETE', requestRoute)
|
||||
.then((responseArg) => {
|
||||
done.resolve(responseArg)
|
||||
})
|
||||
} else {
|
||||
done.reject()
|
||||
}
|
||||
})
|
||||
return done.promise
|
||||
};
|
||||
listRecords(domainNameArg:string){
|
||||
let done = plugins.q.defer();
|
||||
let domain = new plugins.smartstring.Domain(domainNameArg);
|
||||
updateRecord(domainNameArg: string, typeArg: string, valueArg) {
|
||||
let done = plugins.q.defer()
|
||||
let domain = new plugins.smartstring.Domain(domainNameArg)
|
||||
return done.promise
|
||||
};
|
||||
listRecords(domainNameArg: string): Promise<interfaces.ICflareRecord[]> {
|
||||
let done = plugins.q.defer<interfaces.ICflareRecord[]>()
|
||||
let result: interfaces.ICflareRecord[] = []
|
||||
|
||||
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;
|
||||
.then((domainIdArg) => {
|
||||
this.request('GET', '/zones/' + domainIdArg + '/dns_records?per_page=100')
|
||||
.then(function (responseArg: any) {
|
||||
result = responseArg.result
|
||||
done.resolve(result)
|
||||
})
|
||||
})
|
||||
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;
|
||||
listZones(domainName?: string): Promise<interfaces.ICflareZone[]> { // TODO: handle pagination
|
||||
let done = plugins.q.defer<interfaces.ICflareZone[]>()
|
||||
let requestRoute = '/zones?per_page=50'
|
||||
if (domainName) requestRoute = requestRoute + '&name=' + domainName
|
||||
let result = []
|
||||
this.request('GET', requestRoute)
|
||||
.then((responseArg: any) => {
|
||||
result = responseArg.result
|
||||
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
|
||||
request(methodArg: string, routeArg: string, dataArg = {}) {
|
||||
let done = plugins.q.defer()
|
||||
let jsonArg: string = JSON.stringify(dataArg)
|
||||
let options: plugins.smartrequest.ISmartRequestOptions = {
|
||||
method: methodArg,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Auth-Email': this.authEmail,
|
||||
'X-Auth-Key': this.authKey
|
||||
},
|
||||
body:jsonArg
|
||||
};
|
||||
//console.log(options);
|
||||
plugins.request(options,function(err, res, body){
|
||||
if (!err && res.statusCode == 200) {
|
||||
var responseObj = JSON.parse(body);
|
||||
done.resolve(responseObj);
|
||||
requestBody: jsonArg
|
||||
}
|
||||
// console.log(options);
|
||||
let retryCount = 0
|
||||
|
||||
let makeRequest = async () => {
|
||||
let response: any = await plugins.smartrequest.request(
|
||||
`https://api.cloudflare.com/client/v4${routeArg}`,
|
||||
options
|
||||
)
|
||||
if (response.statusCode === 200) {
|
||||
done.resolve(response.body)
|
||||
} else if (response.statusCode === 429) {
|
||||
console.log('rate limited! Waiting for retry!')
|
||||
retryRequest()
|
||||
} else {
|
||||
console.log(err);
|
||||
console.log(res);
|
||||
done.reject(err);
|
||||
};
|
||||
});
|
||||
return done.promise;
|
||||
console.log(response.status)
|
||||
console.log(response.messages)
|
||||
console.log(response.errors)
|
||||
done.reject(new Error('request failed'))
|
||||
}
|
||||
}
|
||||
let retryRequest = async (delayTimeArg = 6000) => {
|
||||
console.log(`retry started and waiting for ${delayTimeArg} ms`)
|
||||
await plugins.smartdelay.delayFor(delayTimeArg)
|
||||
if (retryCount < 10) {
|
||||
retryCount++
|
||||
return await makeRequest()
|
||||
}
|
||||
}
|
||||
makeRequest()
|
||||
return done.promise
|
||||
}
|
||||
};
|
||||
|
||||
private authCheck() {
|
||||
return (this.authEmail && this.authKey) // check if auth is available
|
||||
}
|
||||
}
|
||||
|
59
ts/cflare.interfaces.ts
Normal file
59
ts/cflare.interfaces.ts
Normal file
@ -0,0 +1,59 @@
|
||||
import * as plugins from './cflare.plugins'
|
||||
|
||||
export interface ICflareZone {
|
||||
"id": string
|
||||
"name": string
|
||||
"development_mode": number
|
||||
"original_name_servers": string[]
|
||||
"original_registrar": string
|
||||
"original_dnshost": string
|
||||
"created_on": string
|
||||
"modified_on": string
|
||||
"name_servers": string[]
|
||||
"owner": {
|
||||
"id": string
|
||||
"email": string
|
||||
"owner_type": string
|
||||
},
|
||||
"permissions": string []
|
||||
"plan": {
|
||||
"id": string
|
||||
"name": string
|
||||
"price": number
|
||||
"currency": string
|
||||
"frequency": string
|
||||
"legacy_id": string
|
||||
"is_subscribed": boolean
|
||||
"can_subscribe": boolean
|
||||
},
|
||||
"plan_pending": {
|
||||
"id": string
|
||||
"name": string
|
||||
"price": number
|
||||
"currency": string
|
||||
"frequency": string
|
||||
"legacy_id": string
|
||||
"is_subscribed": string
|
||||
"can_subscribe": string
|
||||
},
|
||||
"status": string
|
||||
"paused": boolean
|
||||
"type": string
|
||||
"checked_on": string
|
||||
}
|
||||
|
||||
export interface ICflareRecord {
|
||||
"id": string
|
||||
"type": string
|
||||
"name": string
|
||||
"content": string
|
||||
"proxiable": boolean
|
||||
"proxied": boolean
|
||||
"ttl": number
|
||||
"locked": boolean
|
||||
"zone_id": string
|
||||
"zone_name": string
|
||||
"created_on": string
|
||||
"modified_on": string
|
||||
"data": any
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
import "typings-global";
|
||||
export let beautylog = require("beautylog");
|
||||
export let q = require("q");
|
||||
export let request = require("request");
|
||||
export import q = require("smartq");
|
||||
export import smartrequest = require("smartrequest");
|
||||
export import smartstring = require("smartstring");
|
||||
export import smartdelay = require('smartdelay');
|
@ -1,9 +0,0 @@
|
||||
{
|
||||
"version": false,
|
||||
"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"
|
||||
}
|
||||
}
|
3
tslint.json
Normal file
3
tslint.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "tslint-config-standard"
|
||||
}
|
Reference in New Issue
Block a user