Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
4faefb0bd7 | |||
162fff134e | |||
426237b2a7 | |||
b2d48d793a | |||
54282bdc14 | |||
208fba0887 | |||
2f065b57fc | |||
3503fbc7b3 |
@ -1,4 +1,10 @@
|
||||
image: hosttoday/ht-docker-node:npmts
|
||||
# gitzone standard
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .yarn/
|
||||
key: "$CI_BUILD_STAGE"
|
||||
|
||||
stages:
|
||||
- test
|
||||
@ -10,6 +16,7 @@ testLEGACY:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test legacy
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
@ -18,6 +25,7 @@ testLTS:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test lts
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
@ -25,6 +33,7 @@ testSTABLE:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test stable
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
@ -47,10 +56,13 @@ trigger:
|
||||
- docker
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmpage
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
stage: pages
|
||||
script:
|
||||
- npmci command npmpage --publish gitlab
|
||||
- npmci command yarn global add npmpage
|
||||
- npmci command npmpage
|
||||
tags:
|
||||
- docker
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
|
7
dist/cflare.classes.cflareaccount.d.ts
vendored
7
dist/cflare.classes.cflareaccount.d.ts
vendored
@ -9,9 +9,9 @@ export declare class CflareAccount {
|
||||
key: string;
|
||||
}): void;
|
||||
getZoneId(domainName: string): Promise<string>;
|
||||
getRecord(domainNameArg: string, typeArg: string): Promise<interfaces.ICflareRecord>;
|
||||
createRecord(domainNameArg: string, typeArg: string, contentArg: string): Promise<{}>;
|
||||
removeRecord(domainNameArg: string, typeArg: string): Promise<{}>;
|
||||
getRecord(domainNameArg: string, typeArg: interfaces.TRecord): Promise<interfaces.ICflareRecord>;
|
||||
createRecord(domainNameArg: string, typeArg: interfaces.TRecord, contentArg: string): Promise<{}>;
|
||||
removeRecord(domainNameArg: string, typeArg: interfaces.TRecord): Promise<{}>;
|
||||
updateRecord(domainNameArg: string, typeArg: string, valueArg: any): Promise<{}>;
|
||||
/**
|
||||
* list all records of a specified domain name
|
||||
@ -23,6 +23,7 @@ export declare class CflareAccount {
|
||||
* @param domainName
|
||||
*/
|
||||
listZones(domainName?: string): Promise<interfaces.ICflareZone[]>;
|
||||
purgeZone(domainName: string): Promise<void>;
|
||||
request(methodArg: string, routeArg: string, dataArg?: {}): Promise<{}>;
|
||||
private authCheck();
|
||||
}
|
||||
|
30
dist/cflare.classes.cflareaccount.js
vendored
30
dist/cflare.classes.cflareaccount.js
vendored
File diff suppressed because one or more lines are too long
2
dist/cflare.interfaces.d.ts
vendored
2
dist/cflare.interfaces.d.ts
vendored
@ -1,4 +1,4 @@
|
||||
export declare type TRecord = '';
|
||||
export declare type TRecord = 'A' | 'AAAA' | 'CNAME' | 'TXT' | 'SRV' | 'LOC' | 'MX' | 'NS' | 'SPF';
|
||||
export interface ICflareZone {
|
||||
'id': string;
|
||||
'name': string;
|
||||
|
2
dist/index.d.ts
vendored
2
dist/index.d.ts
vendored
@ -1,2 +1,2 @@
|
||||
import "typings-global";
|
||||
import 'typings-global';
|
||||
export { CflareAccount } from "./cflare.classes.cflareaccount";
|
||||
|
2
dist/index.js
vendored
2
dist/index.js
vendored
@ -3,4 +3,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
require("typings-global");
|
||||
var cflare_classes_cflareaccount_1 = require("./cflare.classes.cflareaccount");
|
||||
exports.CflareAccount = cflare_classes_cflareaccount_1.CflareAccount;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF3QjtBQUN4QiwrRUFBNkQ7QUFBckQsdURBQUEsYUFBYSxDQUFBIn0=
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2QiwrRUFBNkQ7QUFBckQsdURBQUEsYUFBYSxDQUFBIn0=
|
7
npmextra.json
Normal file
7
npmextra.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"npmci": {
|
||||
"globalNpmTools": [
|
||||
"npmts"
|
||||
]
|
||||
}
|
||||
}
|
16
package.json
16
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cflare",
|
||||
"version": "0.0.20",
|
||||
"version": "1.0.3",
|
||||
"description": "easy cloudflare management",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
@ -22,15 +22,15 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/cflare#readme",
|
||||
"dependencies": {
|
||||
"beautylog": "^6.1.1",
|
||||
"smartdelay": "^1.0.1",
|
||||
"smartq": "^1.1.0",
|
||||
"beautylog": "^6.1.10",
|
||||
"smartdelay": "^1.0.3",
|
||||
"smartq": "^1.1.1",
|
||||
"smartrequest": "^1.0.4",
|
||||
"smartstring": "^2.0.22",
|
||||
"typings-global": "^1.0.14"
|
||||
"smartstring": "^2.0.24",
|
||||
"typings-global": "^1.0.16"
|
||||
},
|
||||
"devDependencies": {
|
||||
"qenv": "^1.1.3",
|
||||
"tapbundle": "^1.0.13"
|
||||
"qenv": "^1.1.7",
|
||||
"tapbundle": "^1.0.14"
|
||||
}
|
||||
}
|
||||
|
18
test/test.ts
18
test/test.ts
@ -2,7 +2,7 @@ import { expect, tap } from 'tapbundle'
|
||||
import cflare = require('../dist/index')
|
||||
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,
|
||||
@ -12,18 +12,18 @@ testCflareAccount.auth({
|
||||
let randomPrefix = Math.floor(Math.random() * 2000)
|
||||
|
||||
tap.test('.listZones() -> should display an entire account', async (tools) => {
|
||||
// tools.timeout(600000)
|
||||
tools.timeout(600000)
|
||||
let result = await testCflareAccount.listZones()
|
||||
console.log(result)
|
||||
})
|
||||
|
||||
tap.test('.getZoneId(domainName) -> should get an Cloudflare Id for a domain string', async (tools) => {
|
||||
// tools.timeout(600000)
|
||||
tools.timeout(600000)
|
||||
await testCflareAccount.getZoneId('bleu.de')
|
||||
})
|
||||
|
||||
tap.test('.listRecords(domainName) -> should list all records for a specific Domain Name', async (tools) => {
|
||||
// tools.timeout(600000)
|
||||
tools.timeout(600000)
|
||||
await testCflareAccount.listRecords('bleu.de')
|
||||
.then(async (responseArg) => {
|
||||
console.log(responseArg)
|
||||
@ -31,12 +31,12 @@ tap.test('.listRecords(domainName) -> should list all records for a specific Dom
|
||||
})
|
||||
|
||||
tap.test('should create a valid record for a subdomain', async (tools) => {
|
||||
// tools.timeout(600000)
|
||||
tools.timeout(600000)
|
||||
await testCflareAccount.createRecord(`${randomPrefix}subdomain.bleu.de`, 'A', '127.0.0.1')
|
||||
})
|
||||
|
||||
tap.test('should get a record from Cloudflare', async (tools) => {
|
||||
// tools.timeout(600000)
|
||||
tools.timeout(600000)
|
||||
await testCflareAccount.getRecord('bleu.de', 'A')
|
||||
.then(function (responseArg) {
|
||||
console.log(responseArg)
|
||||
@ -44,11 +44,15 @@ tap.test('should get a record from Cloudflare', async (tools) => {
|
||||
})
|
||||
|
||||
tap.test('should remove a subdomain record from Cloudflare', async (tools) => {
|
||||
// tools.timeout(600000)
|
||||
tools.timeout(600000)
|
||||
await testCflareAccount.removeRecord(`${randomPrefix}subdomain.bleu.de`, 'A')
|
||||
.then(async (responseArg) => {
|
||||
console.log(responseArg)
|
||||
})
|
||||
})
|
||||
|
||||
tap.test('.purge(some.domain) -> should purge everything', async () => {
|
||||
await testCflareAccount.purgeZone('bleu.de')
|
||||
})
|
||||
|
||||
tap.start()
|
||||
|
@ -15,7 +15,8 @@ export class CflareAccount {
|
||||
}
|
||||
|
||||
async getZoneId (domainName: string) {
|
||||
let zoneArray = await this.listZones(domainName)
|
||||
let domain = new plugins.smartstring.Domain(domainName)
|
||||
let zoneArray = await this.listZones(domain.zoneName)
|
||||
let filteredResponse = zoneArray.filter((zoneArg) => {
|
||||
return zoneArg.name === domainName
|
||||
})
|
||||
@ -27,7 +28,7 @@ export class CflareAccount {
|
||||
}
|
||||
|
||||
}
|
||||
getRecord (domainNameArg: string, typeArg: string): Promise<interfaces.ICflareRecord> {
|
||||
getRecord (domainNameArg: string, typeArg: interfaces.TRecord): Promise<interfaces.ICflareRecord> {
|
||||
let done = plugins.q.defer()
|
||||
let result: interfaces.ICflareRecord
|
||||
|
||||
@ -42,7 +43,7 @@ export class CflareAccount {
|
||||
return done.promise
|
||||
}
|
||||
|
||||
async createRecord (domainNameArg: string, typeArg: string, contentArg: string) {
|
||||
async createRecord (domainNameArg: string, typeArg: interfaces.TRecord, contentArg: string) {
|
||||
let done = plugins.q.defer()
|
||||
let domain = new plugins.smartstring.Domain(domainNameArg)
|
||||
let domainIdArg = await this.getZoneId(domain.zoneName)
|
||||
@ -58,7 +59,7 @@ export class CflareAccount {
|
||||
return done.promise
|
||||
}
|
||||
|
||||
removeRecord (domainNameArg: string, typeArg: string) {
|
||||
removeRecord (domainNameArg: string, typeArg: interfaces.TRecord) {
|
||||
let done = plugins.q.defer()
|
||||
let domain = new plugins.smartstring.Domain(domainNameArg)
|
||||
this.getRecord(domain.fullName, typeArg)
|
||||
@ -99,11 +100,11 @@ export class CflareAccount {
|
||||
* @param domainName
|
||||
*/
|
||||
async listZones (domainName?: string): Promise<interfaces.ICflareZone[]> { // TODO: handle pagination
|
||||
let requestRoute = '/zones?per_page=50'
|
||||
let requestRoute = `/zones?per_page=50`
|
||||
|
||||
// may be optionally filtered by domain name
|
||||
if (domainName) {
|
||||
requestRoute = requestRoute + '&name=' + domainName
|
||||
requestRoute = `${requestRoute}&name=${domainName}`
|
||||
}
|
||||
|
||||
let response: any = await this.request('GET', requestRoute)
|
||||
@ -111,17 +112,28 @@ export class CflareAccount {
|
||||
return result
|
||||
}
|
||||
|
||||
async purgeZone (domainName: string) {
|
||||
let domain = new plugins.smartstring.Domain(domainName)
|
||||
let domainId = await this.getZoneId(domain.zoneName)
|
||||
let requestUrl = `/zones/${domainId}/purge_cache`
|
||||
let payload = {
|
||||
purge_everything: true
|
||||
}
|
||||
let respone = await this.request('DELETE', requestUrl, payload)
|
||||
}
|
||||
|
||||
request (methodArg: string, routeArg: string, dataArg = {}) {
|
||||
let done = plugins.q.defer()
|
||||
let jsonArg: string = JSON.stringify(dataArg)
|
||||
let jsonStringArg: 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
|
||||
'X-Auth-Key': this.authKey,
|
||||
'Content-Length': Buffer.byteLength(jsonStringArg)
|
||||
},
|
||||
requestBody: jsonArg
|
||||
requestBody: jsonStringArg
|
||||
}
|
||||
// console.log(options);
|
||||
let retryCount = 0
|
||||
@ -137,7 +149,8 @@ export class CflareAccount {
|
||||
console.log('rate limited! Waiting for retry!')
|
||||
retryRequest()
|
||||
} else if (response.statusCode === 400) {
|
||||
console.log('bad request! Going to retry!')
|
||||
console.log(`bad request for route ${routeArg}! Going to retry!`)
|
||||
retryRequest()
|
||||
} else {
|
||||
console.log(response.statusCode)
|
||||
done.reject(new Error('request failed'))
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as plugins from './cflare.plugins'
|
||||
|
||||
export type TRecord = ''
|
||||
export type TRecord = 'A' | 'AAAA' | 'CNAME' | 'TXT' | 'SRV' | 'LOC' | 'MX' | 'NS' | 'SPF'
|
||||
|
||||
export interface ICflareZone {
|
||||
'id': string
|
||||
|
@ -1,2 +1,2 @@
|
||||
import "typings-global";
|
||||
import 'typings-global'
|
||||
export {CflareAccount} from "./cflare.classes.cflareaccount";
|
36
yarn.lock
36
yarn.lock
@ -76,7 +76,7 @@ beautycolor@^1.0.7:
|
||||
ansi-256-colors "^1.1.0"
|
||||
typings-global "^1.0.14"
|
||||
|
||||
beautylog@^6.1.1:
|
||||
beautylog@^6.1.10:
|
||||
version "6.1.10"
|
||||
resolved "https://registry.yarnpkg.com/beautylog/-/beautylog-6.1.10.tgz#9c27e566937684cb689f9372d98cfa5415d50b72"
|
||||
dependencies:
|
||||
@ -184,6 +184,10 @@ early@^2.1.1:
|
||||
smartq "^1.1.1"
|
||||
typings-global "^1.0.16"
|
||||
|
||||
es6-error@^4.0.2:
|
||||
version "4.0.2"
|
||||
resolved "https://registry.yarnpkg.com/es6-error/-/es6-error-4.0.2.tgz#eec5c726eacef51b7f6b73c20db6e1b13b069c98"
|
||||
|
||||
escape-string-regexp@^1.0.2:
|
||||
version "1.0.5"
|
||||
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
|
||||
@ -285,10 +289,11 @@ jsonfile@^3.0.0:
|
||||
optionalDependencies:
|
||||
graceful-fs "^4.1.6"
|
||||
|
||||
leakage@^0.2.0:
|
||||
version "0.2.0"
|
||||
resolved "https://registry.yarnpkg.com/leakage/-/leakage-0.2.0.tgz#9e7a8cc1d241d8c8427e348769e192e172fd8733"
|
||||
leakage@^0.3.0:
|
||||
version "0.3.0"
|
||||
resolved "https://registry.yarnpkg.com/leakage/-/leakage-0.3.0.tgz#15d698abdc76bbc6439601f4f3020e77e2d50c39"
|
||||
dependencies:
|
||||
es6-error "^4.0.2"
|
||||
left-pad "^1.1.3"
|
||||
memwatch-next "^0.3.0"
|
||||
minimist "^1.2.0"
|
||||
@ -378,7 +383,7 @@ process-nextick-args@^1.0.6, process-nextick-args@~1.0.6:
|
||||
version "1.0.7"
|
||||
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-1.0.7.tgz#150e20b756590ad3f91093f25a4f2ad8bff30ba3"
|
||||
|
||||
qenv@^1.1.3:
|
||||
qenv@^1.1.7:
|
||||
version "1.1.7"
|
||||
resolved "https://registry.yarnpkg.com/qenv/-/qenv-1.1.7.tgz#d03f8bf8fe37494cf08d0919fe765dca84d9afae"
|
||||
dependencies:
|
||||
@ -460,11 +465,12 @@ smartchai@^1.0.3:
|
||||
chai-as-promised "^6.0.0"
|
||||
chai-string "^1.3.0"
|
||||
|
||||
smartdelay@^1.0.1:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/smartdelay/-/smartdelay-1.0.1.tgz#687f8bcc09d7c62c9c5a8a1771c1aba3aff54156"
|
||||
smartdelay@^1.0.3:
|
||||
version "1.0.3"
|
||||
resolved "https://registry.yarnpkg.com/smartdelay/-/smartdelay-1.0.3.tgz#5fd44dad77262d110702f0293efa80c072cfb579"
|
||||
dependencies:
|
||||
typings-global "^1.0.14"
|
||||
smartq "^1.1.1"
|
||||
typings-global "^1.0.16"
|
||||
|
||||
smartenv@^2.0.0:
|
||||
version "2.0.6"
|
||||
@ -512,7 +518,7 @@ smartrequest@^1.0.4:
|
||||
smartq "^1.1.0"
|
||||
typings-global "^1.0.14"
|
||||
|
||||
smartstring@^2.0.22:
|
||||
smartstring@^2.0.24:
|
||||
version "2.0.24"
|
||||
resolved "https://registry.yarnpkg.com/smartstring/-/smartstring-2.0.24.tgz#dc1c5efb738c10a2d7daeea3d800ad2ecc65a26c"
|
||||
dependencies:
|
||||
@ -558,14 +564,14 @@ supports-color@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"
|
||||
|
||||
tapbundle@^1.0.13:
|
||||
version "1.0.13"
|
||||
resolved "https://registry.yarnpkg.com/tapbundle/-/tapbundle-1.0.13.tgz#0b274aed6a386c0c01d8d517709381ce96e3971e"
|
||||
tapbundle@^1.0.14:
|
||||
version "1.0.14"
|
||||
resolved "https://registry.yarnpkg.com/tapbundle/-/tapbundle-1.0.14.tgz#75827e335fcb02216f0267a26a26d702ddc02e3c"
|
||||
dependencies:
|
||||
early "^2.1.1"
|
||||
leakage "^0.2.0"
|
||||
leakage "^0.3.0"
|
||||
smartchai "^1.0.3"
|
||||
smartdelay "^1.0.1"
|
||||
smartdelay "^1.0.3"
|
||||
smartq "^1.1.1"
|
||||
typings-global "^1.0.16"
|
||||
|
||||
|
Reference in New Issue
Block a user