248 lines
8.3 KiB
Bash
248 lines
8.3 KiB
Bash
# ============================================================================
|
|
# OCP Smart Login/Context Switch Aliases
|
|
# ============================================================================
|
|
# These are actually functions (not aliases) for proper variable expansion.
|
|
# They intelligently switch between OCP clusters:
|
|
# - If logged in with valid token: just switch context (fast)
|
|
# - If token expired or not logged in: full login with browser (safe)
|
|
#
|
|
# Source this after .bash_aliases to override the old context-only aliases
|
|
# ============================================================================
|
|
|
|
# First, source the helper functions (suppress all console output during init)
|
|
source ~/.bash_oc_smart.sh &>/dev/null
|
|
|
|
# ============================================================================
|
|
# AWS Shared Clusters - Smart Switch Functions
|
|
# ============================================================================
|
|
|
|
# AWS-Test1 (aws01t)
|
|
ocAWS-Test1() {
|
|
oc_smart_switch \
|
|
"aws01t" \
|
|
"AWS-Test1" \
|
|
"kihub-u241100-dev/api-aws01t-sbb-aws-test-net:6443/u241100" \
|
|
"kihub-dev-u241100" \
|
|
"$OPENSHIFT_TOKEN_AWS_TEST" \
|
|
"https://api.aws01t.sbb-aws-test.net:6443" \
|
|
"https://oauth-openshift.apps.aws01t.sbb-aws-test.net/oauth/token/request"
|
|
}
|
|
|
|
# AWS-Test2 (aws02t)
|
|
ocAWS-Test2() {
|
|
oc_smart_switch \
|
|
"aws02t" \
|
|
"AWS-Test2" \
|
|
"kihub-u241100-dev/api-aws02t-sbb-aws-test-net:6443/u241100" \
|
|
"kihub-dev-u241100" \
|
|
"$OPENSHIFT_TOKEN_AWS_TEST" \
|
|
"https://api.aws02t.sbb-aws-test.net:6443" \
|
|
"https://oauth-openshift.apps.aws02t.sbb-aws-test.net/oauth/token/request"
|
|
}
|
|
|
|
# AWS-Int (Integration on Lisa)
|
|
ocAWS-Int() {
|
|
oc_smart_switch \
|
|
"lisa" \
|
|
"AWS-Int" \
|
|
"kihub-int/api-lisa-sbb-aws-net:6443/u241100" \
|
|
"kihub-int" \
|
|
"$OPENSHIFT_TOKEN_AWS_PROD" \
|
|
"https://api.lisa.sbb-aws.net:6443" \
|
|
"https://oauth-openshift.apps.lisa.sbb-aws.net/oauth/token/request"
|
|
}
|
|
|
|
# AWS-Prod (Production on Lisa)
|
|
ocAWS-Prod() {
|
|
oc_smart_switch \
|
|
"lisa" \
|
|
"AWS-Prod" \
|
|
"kihub-prod/api-lisa-sbb-aws-net:6443/u241100" \
|
|
"kihub-prod" \
|
|
"$OPENSHIFT_TOKEN_AWS_PROD" \
|
|
"https://api.lisa.sbb-aws.net:6443" \
|
|
"https://oauth-openshift.apps.lisa.sbb-aws.net/oauth/token/request"
|
|
}
|
|
|
|
# AWS-Lisa (Production cluster)
|
|
ocAWS-Lisa() {
|
|
oc_smart_switch \
|
|
"lisa" \
|
|
"AWS-Lisa" \
|
|
"kihub-prod/api-lisa-sbb-aws-net:6443/u241100" \
|
|
"kihub-prod" \
|
|
"$OPENSHIFT_TOKEN_AWS_PROD" \
|
|
"https://api.lisa.sbb-aws.net:6443" \
|
|
"https://oauth-openshift.apps.lisa.sbb-aws.net/oauth/token/request"
|
|
}
|
|
|
|
# AWS-Maggie (Production cluster)
|
|
ocAWS-Maggie() {
|
|
oc_smart_switch \
|
|
"maggie" \
|
|
"AWS-Maggie" \
|
|
"kihub-prod/api-maggie-sbb-aws-net:6443/u241100" \
|
|
"kihub-prod" \
|
|
"$OPENSHIFT_TOKEN_AWS_PROD" \
|
|
"https://api.maggie.sbb-aws.net:6443" \
|
|
"https://oauth-openshift.apps.maggie.sbb-aws.net/oauth/token/request"
|
|
}
|
|
|
|
# AWS-WZU
|
|
ocAWS-WZU() {
|
|
oc_smart_switch \
|
|
"wzu01t" \
|
|
"AWS-WZU" \
|
|
"kihub-test/api-wzu01t-ocp-test-sbb-aws-net:6443/u241100" \
|
|
"" \
|
|
"$OPENSHIFT_TOKEN_WZU" \
|
|
"https://api.wzu01t.ocp-test.sbb-aws.net:6443" \
|
|
"https://oauth-openshift.apps.wzu01t.ocp-test.sbb-aws.net/oauth/token/request"
|
|
}
|
|
|
|
# ============================================================================
|
|
# CUS Private Clusters - Smart Switch Functions
|
|
# ============================================================================
|
|
|
|
# AWS-Dev (Development on aws01t)
|
|
ocCUS-Dev() {
|
|
oc_smart_switch \
|
|
"cus01t" \
|
|
"AWS-Dev" \
|
|
"kihub-dev-u241100/api-cus01t-sbb-aws-test-net:6443/u241100" \
|
|
"kihub-dev-u241100" \
|
|
"$OPENSHIFT_TOKEN_AWS_TEST" \
|
|
"https://api.cus01t.sbb-aws-test.net:6443" \
|
|
"https://oauth-openshift.apps.cus01t.sbb-aws-test.net/oauth/token/request"
|
|
}
|
|
|
|
# AWS-RT (Runtime on aws01t)
|
|
ocCUS-RT() {
|
|
oc_smart_switch \
|
|
"cus01t" \
|
|
"AWS-RT" \
|
|
"kihub-dev-rt/api-cus01t-sbb-aws-test-net:6443/u241100" \
|
|
"kihub-dev-rt" \
|
|
"$OPENSHIFT_TOKEN_AWS_TEST" \
|
|
"https://api.cus01t.sbb-aws-test.net:6443" \
|
|
"https://oauth-openshift.apps.cus01t.sbb-aws-test.net/oauth/token/request"
|
|
}
|
|
|
|
# AWS-Test (Test on aws01t)
|
|
ocCUS-Test() {
|
|
oc_smart_switch \
|
|
"cus01t" \
|
|
"CUS-Test" \
|
|
"kihub-test/api-cus01t-sbb-aws-test-net:6443/u241100" \
|
|
"kihub-test" \
|
|
"$OPENSHIFT_TOKEN_AWS_TEST" \
|
|
"https://api.cus01t.sbb-aws-test.net:6443" \
|
|
"https://oauth-openshift.apps.cus01t.sbb-aws-test.net/oauth/token/request"
|
|
}
|
|
|
|
# AWS-Int (Test on aws01t)
|
|
ocCUS-Int() {
|
|
oc_smart_switch \
|
|
"cus01t" \
|
|
"CUS-Int" \
|
|
"kihub-int/api-cus01t-sbb-aws-test-net:6443/u241100" \
|
|
"kihub-int" \
|
|
"$OPENSHIFT_TOKEN_AWS_TEST" \
|
|
"https://api.cus01t.sbb-aws-test.net:6443" \
|
|
"https://oauth-openshift.apps.cus01t.sbb-aws-test.net/oauth/token/request"
|
|
}
|
|
|
|
# AWS-Prod (Test on aws01t)
|
|
ocCUS-Prod() {
|
|
oc_smart_switch \
|
|
"cus01p" \
|
|
"CUS-Prod" \
|
|
"kihub-prod/api-cus01p-sbb-aws-net:6443/u241100" \
|
|
"kihub-prod" \
|
|
"$OPENSHIFT_TOKEN_AWS_TEST" \
|
|
"https://api.cus01p.sbb-aws-net:6443" \
|
|
"https://oauth-openshift.apps.cus01p.sbb-aws.net/oauth/token/request"
|
|
}
|
|
|
|
# ============================================================================
|
|
# SC (OTC) Clusters - Smart Switch Functions
|
|
# IMPORTANT: These clusters require separate tokens from AWS clusters!
|
|
# Set OPENSHIFT_TOKEN_SC02 and OPENSHIFT_TOKEN_SCSputnix in ~/.profile
|
|
# ============================================================================
|
|
|
|
# SC-Test (Test on sc02t - OTC, not AWS!)
|
|
ocSC-Test() {
|
|
oc_smart_switch \
|
|
"sc02t" \
|
|
"SC-Test" \
|
|
"kihub-test/api-sc02t-otc-test-sbb-ch:6443/u241100" \
|
|
"kihub-test" \
|
|
"$OPENSHIFT_TOKEN_SC02" \
|
|
"https://api.sc02t.otc-test.sbb.ch:6443" \
|
|
"https://oauth-openshift.apps.sc02t.otc-test.sbb.ch/oauth/token/request"
|
|
}
|
|
|
|
# SC-Int (Integration on Sputnix - OTC, not AWS!)
|
|
ocSC-Int() {
|
|
oc_smart_switch \
|
|
"sputnix" \
|
|
"SC-Int" \
|
|
"kihub-int/api-sputnix-otc-sbb-ch:6443/u241100" \
|
|
"kihub-int" \
|
|
"$OPENSHIFT_TOKEN_SCSputnix" \
|
|
"https://api.sputnix.otc.sbb.ch:6443" \
|
|
"https://oauth-openshift.apps.sputnix.otc.sbb.ch/oauth/token/request"
|
|
}
|
|
|
|
# SC-Prod (Production on Sputnix - OTC, not AWS!)
|
|
ocSC-Prod() {
|
|
oc_smart_switch \
|
|
"sputnix" \
|
|
"SC-Prod" \
|
|
"kihub-prod/api-sputnix-otc-sbb-ch:6443/u241100" \
|
|
"kihub-prod" \
|
|
"$OPENSHIFT_TOKEN_SCSputnix" \
|
|
"https://api.sputnix.otc.sbb.ch:6443" \
|
|
"https://oauth-openshift.apps.sputnix.otc.sbb.ch/oauth/token/request"
|
|
}
|
|
|
|
# ============================================================================
|
|
# Convenience Aliases for Helper Functions
|
|
# ============================================================================
|
|
|
|
# These can stay as aliases since they're just shortcuts to functions
|
|
alias ocStatus='oc_status'
|
|
alias ocCtx='oc_contexts'
|
|
alias ocLogout='oc_logout'
|
|
alias ocWhoami='oc whoami'
|
|
|
|
# ============================================================================
|
|
# Notes on Usage
|
|
# ============================================================================
|
|
#
|
|
# Old way (still works):
|
|
# ocLoginAWS-Test1 → Full login every time
|
|
# ocAWS-Dev → Only context switch (fails if not logged in)
|
|
#
|
|
# New way (smart):
|
|
# ocAWS-Dev → Auto-detect & do the right thing
|
|
# - Logged in? → Switch context only (FAST)
|
|
# - Not logged in? → Full login (SAFE)
|
|
#
|
|
# Note: These are FUNCTIONS (not aliases) for proper variable expansion
|
|
# in bash and zsh.
|
|
#
|
|
# Helper commands:
|
|
# ocStatus → Show current auth status
|
|
# ocCtx → List all available contexts
|
|
# ocLogout → Logout from current cluster
|
|
# ocWhoami → Show current user
|
|
#
|
|
# Example workflow:
|
|
# 1. ocAWS-Test1 → Switch to Test1, full login if needed
|
|
# 2. ocAWS-Int → Switch to Int, just context switch (fast!)
|
|
# 3. ocAWS-Prod → Switch to Prod, just context switch (fast!)
|
|
# 4. ocSC-Int → Switch to SC Int, full login if different token
|
|
#
|
|
|