Compare commits
32 Commits
Author | SHA1 | Date | |
---|---|---|---|
bf15b8aec7 | |||
55b305ca1c | |||
9699e4bf76 | |||
0692d16dd7 | |||
c76643d700 | |||
de088ba550 | |||
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 |
7
.gitignore
vendored
7
.gitignore
vendored
@ -1,7 +1,6 @@
|
|||||||
coverage/
|
coverage/
|
||||||
docs/
|
docs/
|
||||||
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
|
||||||
|
18
README.md
18
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)
|
20
dist/cflare.classes.cflareaccount.d.ts
vendored
Normal file
20
dist/cflare.classes.cflareaccount.d.ts
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import 'typings-global';
|
||||||
|
import * as interfaces from './cflare.interfaces';
|
||||||
|
export declare class CflareAccount {
|
||||||
|
private authEmail;
|
||||||
|
private authKey;
|
||||||
|
constructor();
|
||||||
|
auth(optionsArg: {
|
||||||
|
email: string;
|
||||||
|
key: string;
|
||||||
|
}): void;
|
||||||
|
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();
|
||||||
|
}
|
167
dist/cflare.classes.cflareaccount.js
vendored
Normal file
167
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";
|
4
dist/cflare.classes.helpers.js
vendored
4
dist/cflare.classes.helpers.js
vendored
@ -1,3 +1,3 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
require("typings-global");
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsImZpbGUiOiJjZmxhcmUuY2xhc3Nlcy5oZWxwZXJzLmpzIiwic291cmNlc0NvbnRlbnQiOltdLCJzb3VyY2VSb290IjoiL3NvdXJjZS8ifQ==
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2ZsYXJlLmNsYXNzZXMuaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2NmbGFyZS5jbGFzc2VzLmhlbHBlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF3QiJ9
|
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=
|
|
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=
|
6
dist/cflare.plugins.d.ts
vendored
Normal file
6
dist/cflare.plugins.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import "typings-global";
|
||||||
|
export declare let beautylog: any;
|
||||||
|
export import q = require("smartq");
|
||||||
|
export import smartrequest = require("smartrequest");
|
||||||
|
export import smartstring = require("smartstring");
|
||||||
|
export import smartdelay = require('smartdelay');
|
10
dist/cflare.plugins.js
vendored
10
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.request = require("request");
|
exports.q = require("smartq");
|
||||||
|
exports.smartrequest = require("smartrequest");
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNmbGFyZS5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSw0Q0FBNEM7QUFDakMsaUJBQVMsR0FBRyxPQUFPLENBQUMsV0FBVyxDQUFDLENBQUM7QUFDakMsZUFBTyxHQUFHLE9BQU8sQ0FBQyxTQUFTLENBQUMsQ0FBQyIsImZpbGUiOiJjZmxhcmUucGx1Z2lucy5qcyIsInNvdXJjZXNDb250ZW50IjpbIi8vLyA8cmVmZXJlbmNlIHBhdGg9XCIuL3R5cGluZ3MvbWFpbi5kLnRzXCIgLz5cbmV4cG9ydCBsZXQgYmVhdXR5bG9nID0gcmVxdWlyZShcImJlYXV0eWxvZ1wiKTtcbmV4cG9ydCBsZXQgcmVxdWVzdCA9IHJlcXVpcmUoXCJyZXF1ZXN0XCIpOyJdLCJzb3VyY2VSb290IjoiL3NvdXJjZS8ifQ==
|
exports.smartstring = require("smartstring");
|
||||||
|
exports.smartdelay = require("smartdelay");
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2ZsYXJlLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9jZmxhcmUucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXdCO0FBQ2IsUUFBQSxTQUFTLEdBQUcsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFDO0FBQzVDLDhCQUFvQztBQUNwQywrQ0FBcUQ7QUFDckQsNkNBQW1EO0FBQ25ELDJDQUFpRCJ9
|
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";
|
6
dist/index.js
vendored
6
dist/index.js
vendored
@ -1,3 +1,5 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
require("typings-global");
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsImZpbGUiOiJpbmRleC5qcyIsInNvdXJjZXNDb250ZW50IjpbXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=
|
var cflare_classes_cflareaccount_1 = require("./cflare.classes.cflareaccount");
|
||||||
|
exports.CflareAccount = cflare_classes_cflareaccount_1.CflareAccount;
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXdCO0FBQ3hCLCtFQUE2RDtBQUFyRCx1REFBQSxhQUFhLENBQUEifQ==
|
16
package.json
16
package.json
@ -1,8 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name": "cflare",
|
"name": "cflare",
|
||||||
"version": "0.0.1",
|
"version": "0.0.12",
|
||||||
"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,17 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/pushrocks/cflare#readme",
|
"homepage": "https://github.com/pushrocks/cflare#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"beautylog": "^4.1.2",
|
"beautylog": "^6.1.1",
|
||||||
"request": "^2.72.0"
|
"smartdelay": "^1.0.1",
|
||||||
|
"smartq": "^1.1.0",
|
||||||
|
"smartrequest": "^1.0.4",
|
||||||
|
"smartstring": "^2.0.22",
|
||||||
|
"typings-global": "^1.0.14"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"npmts": "^5.0.4"
|
"npmts-g": "^6.0.0",
|
||||||
|
"qenv": "^1.1.3",
|
||||||
|
"smartchai": "^1.0.1",
|
||||||
|
"typings-test": "^1.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1
test/test.d.ts
vendored
Normal file
1
test/test.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
import 'typings-test';
|
88
test/test.js
Normal file
88
test/test.js
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
"use strict";
|
||||||
|
require("typings-test");
|
||||||
|
const cflare = require("../dist/index");
|
||||||
|
const qenv_1 = require("qenv");
|
||||||
|
let testQenv = new qenv_1.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(30000);
|
||||||
|
testCflareAccount.listZones()
|
||||||
|
.then((responseArg) => {
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQix3Q0FBd0M7QUFFeEMsK0JBQTJCO0FBQzNCLElBQUksUUFBUSxHQUFHLElBQUksV0FBSSxDQUFDLE9BQU8sQ0FBQyxHQUFHLEVBQUUsRUFBRSxPQUFPLENBQUMsR0FBRyxFQUFFLEdBQUcsU0FBUyxDQUFDLENBQUE7QUF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QVc7b0JBQ3ZCLE9BQU8sQ0FBQyxHQUFHLENBQUMsV0FBVyxDQUFDLENBQUE7b0JBQ3hCLElBQUksRUFBRSxDQUFBO2dCQUNWLENBQUMsQ0FBQyxDQUFBO1lBQ1YsQ0FBQyxDQUFDLENBQUE7UUFDTixDQUFDLENBQUMsQ0FBQTtJQUNOLENBQUMsQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFDLENBQUEifQ==
|
88
test/test.ts
Normal file
88
test/test.ts
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
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(30000)
|
||||||
|
testCflareAccount.listZones()
|
||||||
|
.then((responseArg) => {
|
||||||
|
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()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
161
ts/cflare.classes.cflareaccount.ts
Normal file
161
ts/cflare.classes.cflareaccount.ts
Normal file
@ -0,0 +1,161 @@
|
|||||||
|
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
|
||||||
|
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(zoneArrayArg => {
|
||||||
|
let filteredResponse = zoneArrayArg.filter((zoneArg) => {
|
||||||
|
return zoneArg.name === domainName
|
||||||
|
})
|
||||||
|
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
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
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): 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: any) {
|
||||||
|
result = responseArg.result
|
||||||
|
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: plugins.smartrequest.ISmartRequestOptions = {
|
||||||
|
method: methodArg,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'X-Auth-Email': this.authEmail,
|
||||||
|
'X-Auth-Key': this.authKey
|
||||||
|
},
|
||||||
|
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(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
|
||||||
|
}
|
||||||
|
}
|
@ -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(){
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
|
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,3 +1,6 @@
|
|||||||
/// <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 import q = require("smartq");
|
||||||
|
export import smartrequest = require("smartrequest");
|
||||||
|
export import smartstring = require("smartstring");
|
||||||
|
export import smartdelay = require('smartdelay');
|
@ -1,2 +1,2 @@
|
|||||||
/// <reference path="./typings/main.d.ts" />
|
import "typings-global";
|
||||||
import plugins = require("./cflare.plugins");
|
export {CflareAccount} from "./cflare.classes.cflareaccount";
|
@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"version": false,
|
|
||||||
"dependencies": {},
|
|
||||||
"ambientDependencies": {
|
|
||||||
"colors": "registry:dt/colors#0.6.0-1+20160425153322",
|
|
||||||
"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