Friday, 7 January 2022

TIL: Logging into RedHat OpenShift Container Platform using an API key

So I've been logging into various OpenShift Container Platform (OCP) clusters for the longest time now, mostly using an API key.

To facilitate this, I have an alias in my current shell ( I'm using macOS 12.1 and mainly live in Terminal ) that parses a JSON document containing said API key and pulls it out: -

alias apikey='export APIKEY=$(cat ~/key_file_production.json | jq -r .apikey) && echo $APIKEY'

Now this handily dumps the result of the operation out to the screen - which can be problematic.

Therefore, wouldn't it be nice if I could use that alias inside another command when I login to my cluster ?

Well, I can: -

oc login -u apikey -p $(apikey)

Login successful.

You have access to 68 projects, the list has been suppressed. You can list all projects with 'oc projects'

Using project "default".

Now I could've combined the two things together: -

oc login -u apikey -p $(cat ~/key_file_production.json | jq -r .apikey)

Login successful.

You have access to 68 projects, the list has been suppressed. You can list all projects with 'oc projects'

Using project "default".

which is way more typing ...

Unless I create another alias ...

code ~/.bash_profile 

...
alias oclogin='oc login -u apikey -p $(cat ~/key_file_production.json | jq -r .apikey)'
...

source ~/.bash_profile

and now I have this: -

oclogin 

Login successful.

You have access to 68 projects, the list has been suppressed. You can list all projects with 'oc projects'

Using project "default".

I love my shell!!!

No comments:

Reminder - installing podman and skopeo on Ubuntu 22.04

This follows on from: - Lest I forget - how to install pip on Ubuntu I had reason to install podman  and skopeo  on an Ubuntu box: - lsb_rel...