Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: update docs with new authUrl setting #169

Merged
merged 1 commit into from
Sep 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;