openshift-rest-client
Advanced tools
Comparing version 2.3.0 to 3.0.0
@@ -5,2 +5,15 @@ # Changelog | ||
## [3.0.0](https://github.com/nodeshift/openshift-rest-client/compare/v2.3.0...v3.0.0) (2019-10-30) | ||
### ⚠ BREAKING CHANGES | ||
* Some API has changed | ||
* This commit updates the client to remove deprecation warnings caused by the kubernetes-clients. There are some changes to getting external configs. | ||
### Bug Fixes | ||
* remove warnings about deprecations ([#171](https://github.com/nodeshift/openshift-rest-client/issues/171)) ([9f7b379](https://github.com/nodeshift/openshift-rest-client/commit/9f7b379)) | ||
## [2.3.0](https://github.com/nodeshift/openshift-rest-client/compare/v2.2.2...v2.3.0) (2019-09-30) | ||
@@ -7,0 +20,0 @@ |
@@ -23,3 +23,3 @@ 'use strict'; | ||
OpenshiftClient: require('./lib/openshift-rest-client.js'), | ||
config: require('kubernetes-client').config | ||
config: new (require('kubernetes-client').KubeConfig)() | ||
}; |
@@ -25,4 +25,5 @@ 'use strict'; | ||
const { Client, config, alias } = require('kubernetes-client'); | ||
const { Client, alias, KubeConfig } = require('kubernetes-client'); | ||
const { getTokenFromBasicAuth } = require('./basic-auth-request'); | ||
const Request = require('kubernetes-client/backends/request'); | ||
@@ -73,27 +74,64 @@ const serviceCatalogCRD = require('./specs/service-catalog-crd.json'); | ||
async function openshiftClient (settings = {}) { | ||
let kubeconfig = settings.config; | ||
let config = settings.config; | ||
const clientConfig = { backend: null, spec, getNames }; | ||
if (kubeconfig) { | ||
if (config) { | ||
// A config is being passed in. Check if it is an object | ||
if (typeof kubeconfig === 'object' && kubeconfig.auth) { | ||
if (typeof config === 'object' && config.auth) { | ||
// Check for the auth username password | ||
if ('user' in kubeconfig.auth || 'username' in kubeconfig.auth) { | ||
if ('user' in config.auth || 'username' in config.auth) { | ||
// They are trying the basic auth. | ||
// Get the access token using the username and password | ||
// Check to see if we are passing in a username/password | ||
const accessToken = await getTokenFromBasicAuth({ insecureSkipTlsVerify: kubeconfig.insecureSkipTlsVerify, url: kubeconfig.url, user: kubeconfig.auth.username || kubeconfig.auth.user, password: kubeconfig.auth.password || kubeconfig.auth.pass, authUrl: kubeconfig.authUrl }); | ||
const { insecureSkipTlsVerify, url, authUrl } = config; | ||
const user = config.auth.username || config.auth.user; | ||
const password = config.auth.password || config.auth.pass; | ||
kubeconfig = { | ||
url: kubeconfig.url, | ||
auth: { | ||
bearer: accessToken | ||
}, | ||
insecureSkipTlsVerify: 'insecureSkipTlsVerify' in kubeconfig ? Boolean(kubeconfig.insecureSkipTlsVerify) : false | ||
const accessToken = await getTokenFromBasicAuth({ insecureSkipTlsVerify, url, user, password, authUrl }); | ||
const clusterUrl = authUrl || url; | ||
// Create clusterName from clusterUrl by removing 'https://' | ||
const clusterName = clusterUrl.replace(/(^\w+:|^)\/\//, ''); | ||
config = { | ||
apiVersion: 'v1', | ||
clusters: [ | ||
{ | ||
cluster: { | ||
server: clusterUrl, | ||
'insecure-skip-tls-verify': insecureSkipTlsVerify | ||
}, | ||
name: clusterName | ||
} | ||
], | ||
contexts: [ | ||
{ | ||
context: { | ||
cluster: clusterName, | ||
user: `${user}/${clusterName}` | ||
}, | ||
name: `default/${clusterName}/${user}` | ||
} | ||
], | ||
'current-context': `default/${clusterName}/${user}`, | ||
kind: 'Config', | ||
preferences: {}, | ||
users: [ | ||
{ | ||
name: `${user}/${clusterName}`, | ||
user: { | ||
token: accessToken | ||
} | ||
} | ||
] | ||
}; | ||
const kubeconfig = new KubeConfig(); | ||
kubeconfig.loadFromString(JSON.stringify(config)); | ||
clientConfig.backend = new Request({ kubeconfig }); | ||
} | ||
} else if (config.clusters) { | ||
clientConfig.backend = new Request({ kubeconfig: config }); | ||
} | ||
} | ||
const client = new Client(clientConfig); | ||
const client = new Client({ config: kubeconfig || config.fromKubeconfig(), spec, getNames: getNames }); | ||
// CRD with the service instance stuff, but only to this client, not the cluster | ||
@@ -100,0 +138,0 @@ client.addCustomResourceDefinition(serviceCatalogCRD); |
{ | ||
"name": "openshift-rest-client", | ||
"version": "2.3.0", | ||
"version": "3.0.0", | ||
"description": "Node.js client for developing with OpenShift", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -74,3 +74,3 @@ [![Build Status](https://travis-ci.org/nodeshift/openshift-rest-client.svg?branch=master)](https://travis-ci.org/nodeshift/openshift-rest-client) [![Coverage Status](https://coveralls.io/repos/github/nodeshift/openshift-rest-client/badge.svg?branch=master)](https://coveralls.io/github/nodeshift/openshift-rest-client?branch=master) | ||
const path '~/some/path/config'; | ||
const customConfig = config.fromKubeconfig(path); | ||
const customConfig = config.loadFromFile(path); | ||
@@ -77,0 +77,0 @@ openshiftRestClient({config: customConfig}).then((client) => { |
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
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
260475
202