Skip to content

Commit

Permalink
add support to override request settings for each client
Browse files Browse the repository at this point in the history
  • Loading branch information
Wilson, Dan committed Jun 14, 2016
1 parent 31e4532 commit d022127
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
.npmignore
node_modules/
test/results/
test/config.json
.DS_Store
5 changes: 5 additions & 0 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = function (info) {
, version = info.version
, token = info.token
, timeout = info.timeout
, reqOptions = info.reqOptions
, namespace = info.namespace;

var getUrl = function (object) {
Expand Down Expand Up @@ -111,6 +112,10 @@ module.exports = function (info) {
if (token) {
object.auth = {bearer: token};
}
// ovverride options for this request if reqOptions exists
if (reqOptions) {
Object.assign(object, reqOptions);
}
// Fix Content-Type header for PATCH methods.
if (object.method === 'PATCH') {
if (!object.headers) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"form-data": "~0.1.0",
"glob": "*",
"json-gate": "~0.8.21",
"request": "~2.26.0",
"request": "~2.72.0",
"sugar": "~1.3.9"
},
"devDependencies": {
Expand Down
3 changes: 3 additions & 0 deletions test/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"host": "<ip>:<port>",
"version": "v1beta1",
"token": "<token>"
//, "namespace": "default",
//, "timeout": 20000
//, "reqOptions": {"proxy": "http://x.x.x.x:xxxx/"}
},
"pattern" : "test-*.js",
"skip" : []
Expand Down
7 changes: 4 additions & 3 deletions test/test-pods.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
var should = require('should');
var assert = require('assert');
var fs = require('fs');
var Client = require('../../../kubernetes/api');
var Client = require('../');
var config = require('./config.json');

describe('Test k8s pods API', function() {
this.timeout(20000);
var client;
var pods, podId;
beforeEach(function() {
client = new Client(require('./config.json').k8s);
client = new Client(config.k8s);
});

it('should return the pods list', function(done) {
client.pods.getBy({"namespace": "default"}, function (err, podsArr) {
client.pods.getBy({"namespace": config.namespace}, function (err, podsArr) {
if (!err) {
console.log('pods: ' + JSON.stringify(podsArr));
pods = podsArr.items;
Expand Down

0 comments on commit d022127

Please sign in to comment.