Skip to content

Commit

Permalink
docs: update docs with new authUrl setting (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
lholmquist authored Sep 30, 2019
1 parent 3e9071a commit 4d36008
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
36 changes: 36 additions & 0 deletions example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const { OpenshiftClient: openshiftRestClient, config } = require('.');

// async function genericTryCatch (fn) {
// let result;
// try {
// result = await fn;
// } catch (err) {
// if (err.code === 404) {
// return Promise.reject(err);
// }
// result = err;
// }

// return result;
// }

// console.log(config);

// OpenshiftClient().then(async (client) => {
// // Use the client object to find a list of projects, for example
// let bc = await genericTryCatch(client.apis.build.v1.ns('myproject').buildconfigs('nodejs-rest-http-s2i').delete());
// console.log(bc);
// });

// const openshiftRestClient = require('openshift-rest-client').OpenshiftClient;

const otherConfig = config.fromKubeconfig();

console.log(otherConfig);

openshiftRestClient().then((client) => {
// Use the client object to find a list of projects, for example
client.apis['project.openshift.io'].v1.project.get().then((response) => {
console.log(response.body);
});
});
1 change: 1 addition & 0 deletions lib/openshift-rest-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const spec = JSON.parse(zlib.gunzipSync(fs.readFileSync(path.join(__dirname, 'sp
*
* @param {object} [settings] - settings object for the openshiftClient function
* @param {string} [settings.url] - Openshift cluster url
* @param {string} [settings.authUrl] - Openshift Basic auth url
* @param {object} [settings.auth] -
* @param {string} [settings.auth.username] - username to authenticate to Openshift
* @param {string} [settings.auth.password] - password to authenticate to Openshift
Expand Down
26 changes: 26 additions & 0 deletions other.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
let kubeconfig = settings.config;
if (kubeconfig) {
// A config is being passed in. Check if it is an object
if (typeof kubeconfig === 'object' && kubeconfig.auth) {
// Check for the auth username password
if ('user' in kubeconfig.auth || 'username' in kubeconfig.auth) {
// They are trying the basic auth.
// Get the access token using the username and password
const accessToken = await getTokenFromBasicAuth({ insecureSkipTlsVerify: settings.insecureSkipTlsVerify, url: kubeconfig.url, user: kubeconfig.username || kubeconfig.user, password: kubeconfig.password || kubeconfig.pass });

kubeconfig = {
url: kubeconfig.url,
auth: {
bearer: accessToken
},
insecureSkipTlsVerify: 'insecureSkipTlsVerify' in settings ? Boolean(settings.insecureSkipTlsVerify) : false
};
}
}
}

console.log(kubeconfig);

// TODO: need to be able to pass in the config object here
const client = new Client({ config: kubeconfig || config.fromKubeconfig(), spec, getNames: getNames });
return client;

0 comments on commit 4d36008

Please sign in to comment.