now works for most things

This commit is contained in:
Philipp Kunz 2016-06-21 19:04:43 +02:00
parent 9cb3c1508e
commit 757a9acd09
5 changed files with 77 additions and 21 deletions

File diff suppressed because one or more lines are too long

View File

@ -25,12 +25,12 @@
"beautylog": "^5.0.12", "beautylog": "^5.0.12",
"q": "^1.4.1", "q": "^1.4.1",
"request": "^2.72.0", "request": "^2.72.0",
"smartstring": "^2.0.6", "smartstring": "^2.0.9",
"typings-global": "^1.0.3" "typings-global": "^1.0.3"
}, },
"devDependencies": { "devDependencies": {
"npmts-g": "^5.2.6", "npmts-g": "^5.2.6",
"qenv": "^1.0.6", "qenv": "^1.0.8",
"should": "^9.0.2", "should": "^9.0.2",
"typings-test": "^1.0.1" "typings-test": "^1.0.1"
} }

File diff suppressed because one or more lines are too long

View File

@ -3,7 +3,7 @@ import cflare = require("../dist/index");
let should = require("should"); let should = require("should");
import {Qenv} from "qenv"; import {Qenv} from "qenv";
let testQenv = new Qenv(process.cwd(),process.cwd() + "/.nogit"); let testQenv = new Qenv(process.cwd(),process.cwd() + "/.nogit");
console.log(testQenv.missingEnvVars);
let testCflareAccount = new cflare.CflareAccount(); let testCflareAccount = new cflare.CflareAccount();
testCflareAccount.auth({ testCflareAccount.auth({
email: process.env.CF_EMAIL, email: process.env.CF_EMAIL,
@ -13,7 +13,7 @@ testCflareAccount.auth({
describe("cflare",function(){ describe("cflare",function(){
describe(".CflareAccount",function(){ describe(".CflareAccount",function(){
describe(".listZones()",function(){ describe(".listZones()",function(){
it("should display an account",function(done){ it("should display an entire account",function(done){
this.timeout(10000); this.timeout(10000);
testCflareAccount.listZones() testCflareAccount.listZones()
.then((responseArg)=>{ .then((responseArg)=>{
@ -59,14 +59,30 @@ describe("cflare",function(){
}); });
}); });
}); });
describe(".removeRecord",function(){ describe(".getRecord",function(){
/*it("should remove a record from Cloudflare",function(done){ it("should get a record from Cloudflare",function(done){
testCflareAccount.removeRecord() testCflareAccount.getRecord("bleu.de","A")
.then(function(responseArg){ .then(function(responseArg){
console.log(responseArg); console.log(responseArg);
done(); 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();
});
});
}); });
}) })
}); });

View File

@ -39,6 +39,7 @@ export class CflareAccount {
let filteredResponse = responseArg.result.filter((recordArg) => { let filteredResponse = responseArg.result.filter((recordArg) => {
return (recordArg.type == typeArg && recordArg.name == domainNameArg); return (recordArg.type == typeArg && recordArg.name == domainNameArg);
}) })
done.resolve(filteredResponse[0]);
}) })
return done.promise; return done.promise;
}; };
@ -62,9 +63,17 @@ export class CflareAccount {
removeRecord(domainNameArg:string,typeArg:string){ removeRecord(domainNameArg:string,typeArg:string){
let done = plugins.q.defer(); let done = plugins.q.defer();
let domain = new plugins.smartstring.Domain(domainNameArg); let domain = new plugins.smartstring.Domain(domainNameArg);
this.getRecord(domain.zoneName,typeArg) this.getRecord(domain.fullName,typeArg)
.then((responseArg) => { .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; return done.promise;
}; };
@ -110,6 +119,7 @@ export class CflareAccount {
}, },
body:jsonArg body:jsonArg
}; };
//console.log(options);
plugins.request(options,function(err, res, body){ plugins.request(options,function(err, res, body){
if (!err && res.statusCode == 200) { if (!err && res.statusCode == 200) {
var responseObj = JSON.parse(body); var responseObj = JSON.parse(body);