-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path001-base-saas_stack-connect.sh
More file actions
executable file
·62 lines (46 loc) · 1.78 KB
/
001-base-saas_stack-connect.sh
File metadata and controls
executable file
·62 lines (46 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
source "$(dirname "${BASH_SOURCE[0]}")"/utils/log.sh
# export TANZU_API_TOKEN=<CSP-TOKEN>
# export ORG_NAME=tanzumissioncontroluserorgstg
# export TANZU_CLI_CEIP_OPT_IN_PROMPT_ANSWER=no
if [ -z "$TANZU_API_TOKEN" ]; then
log error "❌ TANZU_API_TOKEN environment variable is not set."
exit 1
fi
if [[ -z "$TMC_ENDPOINT" && -z "$ORG_NAME" ]]; then
log error "❌ Environment variables TMC_ENDPOINT or ORG_NAME is not set."
exit 1
fi
if [ -z "$TMC_ENV" ]; then
TMC_ENV="tmc" # "tmc-dev" for dev stack
fi
# The URL can be overridden by environment variable, e.g for dev stack
# export TMC_ENDPOINT={{ORG_NAME}}.tmc-dev.tanzu.broadcom.com
if [ -z "$TMC_ENDPOINT" ]; then
TMC_ENDPOINT="${ORG_NAME}.${TMC_ENV}.tanzu.broadcom.com"
fi
# The CSP_URL can be overridden by environment variable, e.g for stg CSP
# export CSP_URL=https://console-stg.tanzu.broadcom.com/csp/gateway/am/api/auth/api-tokens/authorize
if [ -z "$CSP_URL" ]; then
CSP_URL="https://console.tanzu.broadcom.com/csp/gateway/am/api/auth/api-tokens/authorize"
fi
## Create CLI context.
TMC_CONTEXT=migration
# Clear the context first if it exists.
tanzu context delete ${TMC_CONTEXT} -y
tanzu config eula accept
STAGING=""
if [[ $CSP_URL == *"console-stg.tanzu.broadcom.com"* ]]; then
STAGING="--staging"
fi
tanzu context create ${TMC_CONTEXT} --type tmc $STAGING --endpoint $TMC_ENDPOINT:443
## Alternative option:
## Exchange the access token.
#export TOKEN_URL=https://console.tanzu.broadcom.com/csp/gateway/am/api/auth/api-tokens/authorize
#export REFRESH_TOKEN=<CSP Token>
echo ""
log info "Fetch the access token:"
export TMC_ACCESS_TOKEN="$(curl -s -X POST $CSP_URL \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d "refresh_token=$TANZU_API_TOKEN" | jq -r .access_token)"
echo $TMC_ACCESS_TOKEN