Skip to content

Commit 02ba487

Browse files
author
Ryan Johnson
committed
Update get_token.sh
- Adds headers. - Update the messages and outputs for the script. Signed-off-by: Ryan Johnson <[email protected]>
1 parent c6ced1a commit 02ba487

File tree

1 file changed

+68
-39
lines changed

1 file changed

+68
-39
lines changed

docs/get_token.sh

100644100755
Lines changed: 68 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,86 @@
11
#!/bin/bash
2+
3+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
4+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
5+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
6+
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7+
8+
# Generates and returns a `refresh_token` from vRealize Automation Cloud or vRealize Automation for use by the Terraform P\provider.
9+
#
10+
# terraform {
11+
# required_providers {
12+
# vra = {
13+
# source = "vmware/vra"
14+
# version = ">= x.y.z"
15+
# }
16+
# }
17+
# required_version = ">= 0.13"
18+
# }
219
#
3-
# Script to generate a refresh token for vRA8 on prem or vRA Cloud.
4-
# This will prompt for the following values if they are not already set:
5-
# username
6-
# Sets environment variables for VRA_REFRESH_TOKEN and VRA_URL which can be consumed by the
7-
# TF provider more securely than leaving the token in cleartext.
8-
#
20+
# provider "vra" {
21+
# url = "https://api.mgmt.cloud.vmware.com"
22+
# refresh_token = "mx7w9**********************zB3UC"
23+
# insecure = false
24+
# }
925
#
10-
if ! [ -x "$(command -v jq)" ]
26+
# Sets environment variables for `VRA_REFRESH_TOKEN` and `VRA_URL` for use by the Terraform provider.
27+
28+
### Check for an installtion of jq. ###
29+
30+
if ! [ -x "$(command -v jq)" ]
1131
then
12-
echo -e "\nthe jq utility is missing. See https://stedolan.github.io/jq/ for instructions to get it\n"
32+
echo -e "\nThe jq utility is missing. See https://stedolan.github.io/jq/ for installation instructions.\n"
1333
exit 1
1434
fi
1535

16-
#Check for an already existing username value
17-
if [[ -v username ]]
36+
### Check for an existing endpoint value. ###
37+
38+
if [[ -v VRA_URL || -v fqdn ]]
39+
then
40+
echo -e "\nFQDN variable found: $fqdn. Skipping...\n"
41+
export VRA_URL="https://$fqdn"
42+
else
43+
echo -e "\nEnter the FQDN for the vRealize Automation services:"
44+
read fqdn
45+
export VRA_URL="https://$fqdn"
46+
fi
47+
48+
### Check for an existing username value. ###
49+
50+
if [[ -v username ]]
1851
then
19-
echo -e "\nusername variable found: $username\n"
20-
else
21-
echo -e "\nPlease enter username to connect to vra with"
52+
echo -e "\nUsername variable found: $username. Skipping...\n"
53+
else
54+
echo -e "\nEnter the username to authenticate with vRealize Automation:"
2255
read username
2356
fi
2457

25-
#Check for an already existing password value
58+
### Check for an existing password value. ###
59+
2660
if [[ -v password ]]
2761
then
28-
echo -e "\npassword variable found\n"
62+
echo -e "\nPassword variable found. Skipping...\n"
2963
else
30-
echo -e "\nPlease enter password to connect to vra with\n"
64+
echo -e "\nEnter the password to authenticate with vRealize Automation:"
3165
read -s password
3266
fi
3367

34-
#Check for an already existing LDAP/AD domain value
68+
### Check for an a existing domain value. ###
69+
3570
if [[ -v domain ]]
3671
then
37-
echo -e "\nExisting domain variable found: $domain\n"
72+
echo -e "\nDomain variable found: $domain. Skipping...\n"
3873
else
39-
echo -e "\nPlease enter domain to connect to vra with (for AD/LDAP users) or press Enter if you not want to use domain"
74+
echo -e "\nEnter the domain or press enter to skip:"
4075
read domain
4176
fi
4277

43-
if [[ -v VRA_URL || -v host ]]
44-
then
45-
echo -e "\nfound a value for the vra/cas server\n"
46-
export VRA_URL="https://$host"
47-
else
48-
echo -e "\nPlease enter the hostname/fqdn of the VRA8 server/ or cloud identity server"
49-
read host
50-
export VRA_URL="https://$host"
51-
fi
78+
### Generate the refresh token. ###
5279

53-
#use different json bodies with curl depending on whether or not a domain
54-
# was specified
55-
echo -e "\nGetting Token"
80+
echo -e "\nGenerating Refresh Token..."
5681
if [[ $domain == "" ]]
5782
then
58-
export VRA_REFRESH_TOKEN=`curl -vvvk -X POST \
83+
export VRA_REFRESH_TOKEN=`curl -k -X POST \
5984
"$VRA_URL/csp/gateway/am/api/login?access_token" \
6085
-H 'Content-Type: application/json' \
6186
-s \
@@ -75,11 +100,15 @@ else
75100
}' | jq -r .refresh_token`
76101
fi
77102

78-
79-
#clean up password
80-
unset password
81-
82-
echo -e "\nRefresh Token"
83-
echo "----------------------------"
103+
echo ""
104+
echo "----------Refresh Token----------"
84105
echo $VRA_REFRESH_TOKEN
85-
echo "----------------------------"
106+
echo "---------------------------------"
107+
echo ""
108+
echo "Environmental variables..."
109+
echo ""
110+
echo "VRA_URL = " $VRA_URL
111+
echo "VRA_REFRESH_TOKEN = " $VRA_REFRESH_TOKEN
112+
113+
### Clear the password value. ###
114+
unset password

0 commit comments

Comments
 (0)