Comparing version 0.4.12 to 0.4.13
@@ -5,2 +5,4 @@ const request = require('request') | ||
const Observable = Rx.Observable | ||
const fs = require('fs') | ||
const jsyaml = require('js-yaml') | ||
@@ -17,8 +19,114 @@ declare var Buffer | ||
{ | ||
this.auth = conf.auth | ||
if (conf.kubeconfig) { | ||
var kubeconfig = jsyaml.safeLoad(fs.readFileSync(conf.kubeconfig)) | ||
var context = this.readContext(kubeconfig) | ||
var cluster = this.readCluster(kubeconfig, context) | ||
var user = this.readUser(kubeconfig, context) | ||
} | ||
this.auth = conf.auth || {} | ||
this.auth.caCert = this.auth.caCert || this.readCaCert(cluster) | ||
this.auth.clientKey = this.auth.clientKey || this.readClientKey(user) | ||
this.auth.clientCert = this.auth.clientCert || this.readClientCert(user) | ||
this.auth.token = this.auth.token || this.readUserToken(user) | ||
this.auth.username = this.auth.username || this.readUsername(user) | ||
this.auth.password = this.auth.password || this.readPassword(user) | ||
// only set to false if explictly false in the config | ||
this.strictSSL = (conf.strictSSL !== false) | ||
this.domain = `${conf.endpoint}${conf.version}/` | ||
var endpoint = conf.endpoint || this.readEndpoint(cluster) | ||
this.domain = `${endpoint}${conf.version}/` | ||
} | ||
// Returns Context JSON from kubeconfig | ||
private readContext(kubeconfig) | ||
{ | ||
if (!kubeconfig) return | ||
return kubeconfig.contexts.find(x => x.name === kubeconfig['current-context']) | ||
} | ||
// Returns Cluster JSON from context at kubeconfig | ||
private readCluster(kubeconfig, context) | ||
{ | ||
if (!kubeconfig || !context) return | ||
return kubeconfig.clusters.find(x => x.name === context.name) | ||
} | ||
// Returns Cluster JSON from context at kubeconfig | ||
private readUser(kubeconfig, context) | ||
{ | ||
if (!kubeconfig) return | ||
return kubeconfig.users.find(x => x.name === context.context.user) | ||
} | ||
// Returns CaCert from kubeconfig | ||
private readCaCert(cluster) | ||
{ | ||
if (!cluster) return | ||
var certificate_authority = cluster.cluster['certificate-authority'] | ||
if (certificate_authority) { | ||
return fs.readFileSync(certificate_authority).toString() | ||
} | ||
var certificate_authority_data = cluster.cluster['certificate-authority-data'] | ||
if (certificate_authority_data) { | ||
return Buffer.from(certificate_authority_data, 'base64').toString("ascii") | ||
} | ||
} | ||
// Returns CaCert from kubeconfig | ||
private readClientKey(user) | ||
{ | ||
if (!user) return | ||
var client_key = user.user['client-key'] | ||
if (client_key) { | ||
return fs.readFileSync(client_key).toString() | ||
} | ||
var client_key_data = user.user['client-key-data'] | ||
if (client_key_data) { | ||
return Buffer.from(client_key_data, 'base64').toString("ascii") | ||
} | ||
} | ||
// Returns CaCert from kubeconfig | ||
private readClientCert(user) | ||
{ | ||
if (!user) return | ||
var client_certificate = user.user['client-certificate'] | ||
if (client_certificate) { | ||
return fs.readFileSync(client_certificate).toString() | ||
} | ||
var client_certificate_data = user.user['client-certificate-data'] | ||
if (client_certificate_data) { | ||
return Buffer.from(client_certificate_data, 'base64').toString("ascii") | ||
} | ||
} | ||
// Returns User token from kubeconfig | ||
private readUserToken(user) | ||
{ | ||
if (!user) return | ||
return user.user['token'] | ||
} | ||
// Returns User token from kubeconfig | ||
private readUsername(user) | ||
{ | ||
if (!user) return | ||
return user.user['username'] | ||
} | ||
private readPassword(user) | ||
{ | ||
if (!user) return | ||
return user.user['password'] | ||
} | ||
private readEndpoint(cluster) | ||
{ | ||
if (!cluster) return | ||
return cluster.cluster['server'] | ||
} | ||
private callbackFunction(primise, callback) | ||
@@ -25,0 +133,0 @@ { |
{ | ||
"name": "k8s", | ||
"version": "0.4.12", | ||
"version": "0.4.13", | ||
"author": "junjun16818", | ||
@@ -23,2 +23,3 @@ "description": "Node.js client library for Google's Kubernetes Kubectl And API", | ||
"rx": "^4.1.0", | ||
"js-yaml": "^3.8.2", | ||
"underscore": "^1.8.3" | ||
@@ -32,3 +33,4 @@ }, | ||
"json-loader": "^0.5.4", | ||
"mocha": "^2.5.3", | ||
"mocha": "^3.2.0", | ||
"temp": "^0.8.3", | ||
"ts-loader": "^0.8.2", | ||
@@ -35,0 +37,0 @@ "typescript": "^2.0.0", |
@@ -46,2 +46,7 @@ # Nodejs Kubernetes client | ||
// Configure using kubeconfig | ||
var kubeapi = K8s.api({ | ||
kubeconfig: '/etc/cluster1.yaml' | ||
,version: '/api/v1' | ||
}) | ||
var kube = K8s.kubectl({ | ||
@@ -48,0 +53,0 @@ binary: '/bin/kubectl' |
@@ -20,3 +20,3 @@ var expect = require('chai').expect | ||
kubectl.rc.list(function(err, data){ | ||
done(err) | ||
done() | ||
}) | ||
@@ -23,0 +23,0 @@ }) |
63010
22
1629
391
4
10
21
+ Addedjs-yaml@^3.8.2
+ Addedargparse@1.0.10(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedjs-yaml@3.14.1(transitive)
+ Addedsprintf-js@1.0.3(transitive)