kong-admin-node-client
Advanced tools
Comparing version 1.0.10 to 1.0.11
{ | ||
"name": "kong-admin-node-client", | ||
"version": "1.0.10", | ||
"version": "1.0.11", | ||
"description": "Kong admin API client in node", | ||
@@ -10,3 +10,4 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "node_modules/.bin/_mocha --recursive -- ./test/*-test.js", | ||
"test-travis": "./node_modules/.bin/istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --recursive --reporter spec --check-leaks test/" | ||
}, | ||
@@ -35,3 +36,9 @@ "repository": { | ||
"request-promise": "^4.2.2" | ||
}, | ||
"devDependencies": { | ||
"istanbul": "^1.1.0-alpha.1", | ||
"mocha": "^4.0.1", | ||
"should": "^13.1.3", | ||
"sinon": "^4.1.3" | ||
} | ||
} |
@@ -0,1 +1,7 @@ | ||
[![NPM Version][npm-image]][npm-url] | ||
[![Build Status][travis-image]][travis-url] | ||
[![Test Coverage][coveralls-image]][coveralls-url] | ||
[![NPM Downloads][downloads-image]][downloads-url] | ||
[![MIT License][license-image]][license-url] | ||
# kong admin client API | ||
@@ -61,1 +67,11 @@ Client API for configuring Kong admin. | ||
``` | ||
[npm-image]: https://img.shields.io/npm/v/express-requests-logger.svg?style=flat | ||
[npm-url]: https://www.npmjs.com/package/kong-admin-node-client | ||
[travis-image]: https://travis-ci.org/ugolas/kong-admin-node-client.svg?branch=master | ||
[travis-url]: https://travis-ci.org/ugolas/kong-admin-node-client | ||
[coveralls-image]: https://coveralls.io/repos/github/ugolas/kong-admin-node-client/badge.svg?branch=master | ||
[coveralls-url]: https://coveralls.io/github/ugolas/kong-admin-node-client?branch=master | ||
[downloads-image]: http://img.shields.io/npm/dm/kong-admin-node-client.svg?style=flat | ||
[downloads-url]: https://npmjs.org/package/kong-admin-node-client | ||
[license-image]: http://img.shields.io/badge/license-MIT-blue.svg?style=flat | ||
[license-url]: LICENSE |
@@ -7,3 +7,2 @@ let _ = require('lodash'), | ||
let options = { | ||
method: 'PUT', | ||
uri: `${url}/apis`, | ||
@@ -14,3 +13,3 @@ body: body | ||
var requestOptions = _.assign(options, basicRequest); | ||
return sendRequestAndProcessError(requestOptions, [200, 201]); | ||
return sendRequestAndProcessError(request.put, requestOptions, [200, 201]); | ||
}; | ||
@@ -20,3 +19,2 @@ | ||
let options = { | ||
method: 'DELETE', | ||
uri: `${url}/apis/${apiName}` | ||
@@ -26,3 +24,3 @@ }; | ||
var requestOptions = _.assign(options, basicRequest); | ||
return sendRequestAndProcessError(requestOptions, [204, 404]); | ||
return sendRequestAndProcessError(request.delete, requestOptions, [204, 404]); | ||
}; | ||
@@ -32,8 +30,12 @@ | ||
let options = { | ||
method: 'GET', | ||
uri: `${url}/apis/${apiName}` | ||
uri: `${url}/apis` | ||
}; | ||
if (apiName) { | ||
options.uri += `/${apiName}` | ||
} | ||
logger.info({ req: options }, 'getAPI'); | ||
var requestOptions = _.assign(options, basicRequest); | ||
return sendRequestAndProcessError(requestOptions, [200, 404]); | ||
let requestOptions = _.assign(options, basicRequest); | ||
return sendRequestAndProcessError(request.get, requestOptions, [200, 404]); | ||
}; | ||
@@ -43,3 +45,2 @@ | ||
let options = { | ||
method: 'PUT', | ||
uri: apiId ? `${url}/apis/${apiId}/plugins` : `${url}/plugins`, | ||
@@ -50,3 +51,3 @@ body: body | ||
var requestOptions = _.assign(options, basicRequest); | ||
return sendRequestAndProcessError(requestOptions, [200, 201]); | ||
return sendRequestAndProcessError(request.put, requestOptions, [200, 201]); | ||
}; | ||
@@ -56,3 +57,2 @@ | ||
let options = { | ||
method: 'GET', | ||
uri: apiId ? `${url}/apis/${apiId}/plugins/${pluginName}` : `${url}/plugins/${pluginName}` | ||
@@ -62,3 +62,3 @@ }; | ||
var requestOptions = _.assign(options, basicRequest); | ||
return sendRequestAndProcessError(requestOptions, [200]); | ||
return sendRequestAndProcessError(request.get, requestOptions, [200]); | ||
}; | ||
@@ -68,3 +68,2 @@ | ||
let options = { | ||
method: 'GET', | ||
uri: apiId ? `${url}/apis/${apiId}/plugins/` : `${url}/plugins/` | ||
@@ -74,8 +73,8 @@ }; | ||
var requestOptions = _.assign(options, basicRequest); | ||
return sendRequestAndProcessError(requestOptions, [200]); | ||
return sendRequestAndProcessError(request.get, requestOptions, [200]); | ||
}; | ||
let sendRequestAndProcessError = function (options, expectedStatuses) { | ||
return request(options) | ||
let sendRequestAndProcessError = function (requestMethod, options, expectedStatuses) { | ||
return requestMethod(options) | ||
.then((res) => { | ||
@@ -85,3 +84,3 @@ if (!expectedStatuses.includes(res.statusCode)) { | ||
logger.error(`Error body: ${JSON.stringify(res.body)}`); | ||
throw new Error(`Error in ${options.method}, ${options.uri}`); | ||
throw new Error(`Error in calling ${options.uri}`); | ||
} | ||
@@ -88,0 +87,0 @@ |
@@ -74,2 +74,43 @@ let httpHelper = require('./http-helper'), | ||
async getAPIs(apis) { | ||
let getResponse = []; | ||
apis = Array.isArray(apis) ? apis : []; | ||
if (apis.length === 0) { | ||
// Get all configured API's | ||
let response = await httpHelper.getAPI({ | ||
url: this.kongAdminUrl | ||
}); | ||
if (response.statusCode === 200) { | ||
getResponse = response.body; | ||
} | ||
return getResponse; | ||
} | ||
for(let i = 0; i < apis.length; i++) { | ||
let api = apis[i]; | ||
if (!api.name) { | ||
logger.info('skip api since no api name was found. api:' + JSON.stringify(api)); | ||
continue; | ||
} | ||
logger.info(`getting api: ${api.name}, ${apis.indexOf(api) + 1} out of ${apis.length} apis`); | ||
let response = await httpHelper.getAPI({ | ||
url: this.kongAdminUrl, | ||
apiName: api.name | ||
}); | ||
if (response.statusCode === 200) { | ||
getResponse.push(response.body); | ||
} | ||
} | ||
return getResponse; | ||
} | ||
async removeAPIs(apis) { | ||
@@ -76,0 +117,0 @@ logger.info(`Removing apis from kong, ${apis.length} in total`); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
40044
10
985
0
76
4