Skip to content

Instantly share code, notes, and snippets.

@craicoverflow
Last active August 19, 2021 11:51
Show Gist options
  • Save craicoverflow/edcf601c7d6fdf53fb31f3159197971f to your computer and use it in GitHub Desktop.
Save craicoverflow/edcf601c7d6fdf53fb31f3159197971f to your computer and use it in GitHub Desktop.
Switching environment using rhoas CLI

Add the following to your .bashrc|.bash_profile|.zshrc|.fishrc (or whatever you use).

function set_rhoas_env {
    local env=$1

    case $env in
        "stage")
            RHOASCONFIG="$HOME/.config/rhoas/config.stage.json"
            ;;
        *)
            RHOASCONFIG="$HOME/.config/rhoas/config.json"
            env="prod"
    esac
    
    echo "export RHOASCONFIG=$RHOASCONFIG\nexport RHOAS_ENV=$env" > ~/.rhoasrc
    source ~/.rhoasrc
}

function rhoas_env {
    echo $RHOAS_ENV
}

Set environments and log in to both:

set_rhoas_env "stage"
rhoas login --api-gateway $(rhoas_env) --mas-auth-url $(rhoas_env)

```shell
set_rhoas_env "prod"
rhoas login --api-gateway $(rhoas_env) --mas-auth-url $(rhoas_env)

Interact with both environments:

$ rhoas kafka list                                                                                                     
  ID                            NAME        OWNER                   STATUS   CLOUD PROVIDER   REGION     
 ----------------------------- ----------- ----------------------- -------- ---------------- ----------- 
  1wuTelf5BPvSLfNGVXpuVR1VbVH   pete        pemuir_kafka_devexp     ready    aws              us-east-1  
  1wrIj78izxmbxwZVDPsCAW4Tli9   rama-test   rpattnai_kafka_devexp   ready    aws              us-east-1

```shell
$ set_rhoas_env "stage"
rhoas kafka list                                                                                                      12:50:13
  ID (4)                        NAME          OWNER                   STATUS   CLOUD PROVIDER   REGION     
 ----------------------------- ------------- ----------------------- -------- ---------------- ----------- 
  c4edo8htgfcsk9c2mfmg          ajay-test     apratap_kafka_devexp    ready    aws              us-east-1  
  1ws2Lo7pGJsbva1t28WIaXegRc1   jenntest      jgiardin_kafka_devexp   ready    aws              us-east-1  
  c4ehev0jc9gqpk105a5g          juntao-test   juntwang_kafka_devexp   ready    aws              us-east-1  
  c4edue1mu7h80om47slg          rama-test     rpattnai_kafka_devexp   ready    aws              us-east-1 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment