Compare commits
26 Commits
Author | SHA1 | Date | |
---|---|---|---|
1ecf660368 | |||
a04ce339f2 | |||
feed201dc1 | |||
cb73164c8f | |||
4758f31132 | |||
5a0ab5080d | |||
26bb194814 | |||
4a656cf7f1 | |||
9a35e69ab6 | |||
757a9acd09 | |||
9cb3c1508e | |||
d25033b84b | |||
941611b7fb | |||
441d66d6f6 | |||
ba2d6f4237 | |||
ff71de8f6c | |||
e99d597c12 | |||
f44698078e | |||
0ed9c7f4f4 | |||
f4d4bc238b | |||
f4c2bb6e5b | |||
b2182ec63d | |||
6cc91c0a5e | |||
69ef50f69c | |||
71dcdd0d66 | |||
229b652c69 |
6
.gitignore
vendored
6
.gitignore
vendored
@ -1,7 +1,7 @@
|
|||||||
coverage/
|
coverage/
|
||||||
docs/
|
docs/
|
||||||
ts/typings/
|
ts/typings/
|
||||||
ts/**/*.js
|
|
||||||
ts/**/*.js.map
|
|
||||||
.idea/
|
|
||||||
node_modules/
|
node_modules/
|
||||||
|
|
||||||
|
.nogit/
|
||||||
|
nogit/
|
||||||
|
43
.gitlab-ci.yml
Normal file
43
.gitlab-ci.yml
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
image: hosttoday/ht-docker-node:npmts
|
||||||
|
|
||||||
|
stages:
|
||||||
|
- test1
|
||||||
|
- test2
|
||||||
|
- test3
|
||||||
|
- release
|
||||||
|
|
||||||
|
testLEGACY:
|
||||||
|
stage: test1
|
||||||
|
script:
|
||||||
|
- npmci test legacy
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
testLTS:
|
||||||
|
stage: test2
|
||||||
|
script:
|
||||||
|
- npmci test lts
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
testSTABLE:
|
||||||
|
stage: test3
|
||||||
|
script:
|
||||||
|
- npmci test stable
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
release:
|
||||||
|
stage: release
|
||||||
|
script:
|
||||||
|
- npmci publish
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
tags:
|
||||||
|
- docker
|
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2016 Push.Rocks
|
Copyright (c) 2016 Lossless GmbH
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
20
README.md
20
README.md
@ -1,10 +1,11 @@
|
|||||||
# cflare
|
# cflare
|
||||||
allows you to manage cloudflare from CoreOS
|
allows you to manage multiple cloudflare accounts.
|
||||||
|
|
||||||
> Note: this package is still in alpha, so some things do not yet work.
|
> Note: this package is still in alpha, so some things do not yet work.
|
||||||
I (Phil from Lossless) expect this package to be ready 1. of June 2016.
|
I (Phil from Lossless) expect this package to be ready 1. of June 2016.
|
||||||
|
|
||||||
## Status
|
## Status
|
||||||
|
[](https://travis-ci.org/pushrocks/cflare)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@ -17,9 +18,14 @@ cflareInstance.auth({
|
|||||||
key:""
|
key:""
|
||||||
});
|
});
|
||||||
|
|
||||||
cflareInstance.createRecord();
|
cflareInstance.createRecord(); // returns promise with resolve function getting the response;
|
||||||
cflareInstance.removeRecord();
|
cflareInstance.removeRecord(); // returns promise with resolve function getting the response;
|
||||||
cflareInstance.copyRecord();
|
cflareInstance.copyRecord(); // returns promise with resolve function getting the response;
|
||||||
cflareInstance.listRecords();
|
cflareInstance.listRecords(); // returns promise with resolve function getting the response;
|
||||||
cflareInstance.listDomains();
|
cflareInstance.listDomains(); // returns promise with resolve function getting the response;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### About the authors:
|
||||||
|
[](https://lossless.com/)
|
||||||
|
|
||||||
|
[](https://paypal.me/lossless)
|
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;
|
||||||
|
}
|
151
dist/cflare.classes.cflareaccount.js
vendored
Normal file
151
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";
|
"use strict";
|
||||||
|
require("typings-global");
|
||||||
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsImZpbGUiOiJjZmxhcmUuY2xhc3Nlcy5oZWxwZXJzLmpzIiwic291cmNlc0NvbnRlbnQiOltdLCJzb3VyY2VSb290IjoiL3NvdXJjZS8ifQ==
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNmbGFyZS5jbGFzc2VzLmhlbHBlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQSIsImZpbGUiOiJjZmxhcmUuY2xhc3Nlcy5oZWxwZXJzLmpzIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IFwidHlwaW5ncy1nbG9iYWxcIjtcbmltcG9ydCBwbHVnaW5zID0gcmVxdWlyZShcIi4vY2ZsYXJlLnBsdWdpbnNcIik7Il19
|
||||||
|
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";
|
"use strict";
|
||||||
/// <reference path="./typings/main.d.ts" />
|
require("typings-global");
|
||||||
exports.beautylog = require("beautylog");
|
exports.beautylog = require("beautylog");
|
||||||
|
exports.q = require("q");
|
||||||
exports.request = require("request");
|
exports.request = require("request");
|
||||||
|
exports.smartstring = require("smartstring");
|
||||||
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNmbGFyZS5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSw0Q0FBNEM7QUFDakMsaUJBQVMsR0FBRyxPQUFPLENBQUMsV0FBVyxDQUFDLENBQUM7QUFDakMsZUFBTyxHQUFHLE9BQU8sQ0FBQyxTQUFTLENBQUMsQ0FBQyIsImZpbGUiOiJjZmxhcmUucGx1Z2lucy5qcyIsInNvdXJjZXNDb250ZW50IjpbIi8vLyA8cmVmZXJlbmNlIHBhdGg9XCIuL3R5cGluZ3MvbWFpbi5kLnRzXCIgLz5cbmV4cG9ydCBsZXQgYmVhdXR5bG9nID0gcmVxdWlyZShcImJlYXV0eWxvZ1wiKTtcbmV4cG9ydCBsZXQgcmVxdWVzdCA9IHJlcXVpcmUoXCJyZXF1ZXN0XCIpOyJdLCJzb3VyY2VSb290IjoiL3NvdXJjZS8ifQ==
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNmbGFyZS5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDYixpQkFBUyxHQUFHLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FBQztBQUNqQyxTQUFDLEdBQUcsT0FBTyxDQUFDLEdBQUcsQ0FBQyxDQUFDO0FBQ2pCLGVBQU8sR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDLENBQUM7QUFDMUIsbUJBQVcsV0FBVyxhQUFhLENBQUMsQ0FBQyIsImZpbGUiOiJjZmxhcmUucGx1Z2lucy5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBcInR5cGluZ3MtZ2xvYmFsXCI7XG5leHBvcnQgbGV0IGJlYXV0eWxvZyA9IHJlcXVpcmUoXCJiZWF1dHlsb2dcIik7XG5leHBvcnQgbGV0IHEgPSByZXF1aXJlKFwicVwiKTtcbmV4cG9ydCBsZXQgcmVxdWVzdCA9IHJlcXVpcmUoXCJyZXF1ZXN0XCIpO1xuZXhwb3J0IGltcG9ydCBzbWFydHN0cmluZyA9IHJlcXVpcmUoXCJzbWFydHN0cmluZ1wiKTsiXX0=
|
||||||
|
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";
|
"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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDeEIsNkNBQTRCLGdDQUFnQyxDQUFDO0FBQXJELHFFQUFxRCIsImZpbGUiOiJpbmRleC5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBcInR5cGluZ3MtZ2xvYmFsXCI7XG5leHBvcnQge0NmbGFyZUFjY291bnR9IGZyb20gXCIuL2NmbGFyZS5jbGFzc2VzLmNmbGFyZWFjY291bnRcIjsiXX0=
|
||||||
|
15
package.json
15
package.json
@ -1,8 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name": "cflare",
|
"name": "cflare",
|
||||||
"version": "0.0.1",
|
"version": "0.0.9",
|
||||||
"description": "cloudflare management for CoreOS",
|
"description": "cloudflare management for CoreOS",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
"typings": "dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(npmts)"
|
"test": "(npmts)"
|
||||||
},
|
},
|
||||||
@ -21,10 +22,16 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/pushrocks/cflare#readme",
|
"homepage": "https://github.com/pushrocks/cflare#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"beautylog": "^4.1.2",
|
"beautylog": "^5.0.12",
|
||||||
"request": "^2.72.0"
|
"q": "^1.4.1",
|
||||||
|
"request": "^2.72.0",
|
||||||
|
"smartstring": "^2.0.10",
|
||||||
|
"typings-global": "^1.0.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"npmts": "^5.0.4"
|
"npmts-g": "^5.2.6",
|
||||||
|
"qenv": "^1.0.8",
|
||||||
|
"should": "^9.0.2",
|
||||||
|
"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";
|
91
test/test.js
Normal file
91
test/test.js
Normal file
File diff suppressed because one or more lines are too long
89
test/test.ts
Normal file
89
test/test.ts
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
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();
|
||||||
|
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);
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})
|
||||||
|
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){
|
||||||
|
this.timeout(5000);
|
||||||
|
testCflareAccount.removeRecord("subdomain.bleu.de","A")
|
||||||
|
.then(function(responseArg){
|
||||||
|
console.log(responseArg);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})
|
||||||
|
});
|
135
ts/cflare.classes.cflareaccount.ts
Normal file
135
ts/cflare.classes.cflareaccount.ts
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
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);
|
||||||
|
})
|
||||||
|
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);
|
||||||
|
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.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;
|
||||||
|
};
|
||||||
|
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
|
||||||
|
};
|
||||||
|
//console.log(options);
|
||||||
|
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");
|
import plugins = require("./cflare.plugins");
|
@ -1,12 +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;
|
|
||||||
constructor(){
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
|
@ -1,3 +1,5 @@
|
|||||||
/// <reference path="./typings/main.d.ts" />
|
import "typings-global";
|
||||||
export let beautylog = require("beautylog");
|
export let beautylog = require("beautylog");
|
||||||
export let request = require("request");
|
export let q = require("q");
|
||||||
|
export let request = require("request");
|
||||||
|
export import smartstring = require("smartstring");
|
@ -1,2 +1,2 @@
|
|||||||
/// <reference path="./typings/main.d.ts" />
|
import "typings-global";
|
||||||
import plugins = require("./cflare.plugins");
|
export {CflareAccount} from "./cflare.classes.cflareaccount";
|
@ -3,6 +3,7 @@
|
|||||||
"dependencies": {},
|
"dependencies": {},
|
||||||
"ambientDependencies": {
|
"ambientDependencies": {
|
||||||
"colors": "registry:dt/colors#0.6.0-1+20160425153322",
|
"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"
|
"node": "registry:dt/node#4.0.0+20160423143914"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user