Repository navigation
Expand file tree
/
Copy pathget_token.sh
More file actions
executable file
·114 lines (98 loc) · 3.18 KB
/
Copy pathget_token.sh
File metadata and controls
executable file
·114 lines (98 loc) · 3.18 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# Generates and returns a `refresh_token` from Aria Automation (SaaS) or Aria Automation for use by the Terraform P\provider.
#
# terraform {
# required_providers {
# vra = {
# source = "vmware/vra"
# version = ">= x.y.z"
# }
# }
# required_version = ">= 0.13"
# }
#
# provider "vra" {
# url = "https://api.mgmt.cloud.vmware.com"
# refresh_token = "mx7w9**********************zB3UC"
# insecure = false
# }
#
# Sets environment variables for `VRA_REFRESH_TOKEN` and `VRA_URL` for use by the Terraform provider.
### Check for an installtion of jq. ###
if ! [ -x "$(command -v jq)" ]
then
echo -e "\nThe jq utility is missing. See https://stedolan.github.io/jq/ for installation instructions.\n"
exit 1
fi
### Check for an existing endpoint value. ###
if [[ -v VRA_URL || -v fqdn ]]
then
echo -e "\nFQDN variable found: $fqdn. Skipping...\n"
export VRA_URL="https://$fqdn"
else
echo -e "\nEnter the FQDN for the Aria Automation services:"
read fqdn
export VRA_URL="https://$fqdn"
fi
### Check for an existing username value. ###
if [[ -v username ]]
then
echo -e "\nUsername variable found: $username. Skipping...\n"
else
echo -e "\nEnter the username to authenticate with Aria Automation:"
read username
fi
### Check for an existing password value. ###
if [[ -v password ]]
then
echo -e "\nPassword variable found. Skipping...\n"
else
echo -e "\nEnter the password to authenticate with Aria Automation:"
read -s password
fi
### Check for an a existing domain value. ###
if [[ -v domain ]]
then
echo -e "\nDomain variable found: $domain. Skipping...\n"
else
echo -e "\nEnter the domain or press enter to skip:"
read domain
fi
### Generate the refresh token. ###
echo -e "\nGenerating Refresh Token..."
if [[ $domain == "" ]]
then
export VRA_REFRESH_TOKEN=`curl -k -X POST \
"$VRA_URL/csp/gateway/am/api/login?access_token" \
-H 'Content-Type: application/json' \
-s \
-d '{
"username": "'"$username"'",
"password": "'"$password"'"
}' | jq -r .refresh_token`
else
export VRA_REFRESH_TOKEN=`curl -k -X POST \
"$VRA_URL/csp/gateway/am/api/login?access_token" \
-H 'Content-Type: application/json' \
-s \
-d '{
"username": "'"$username"'",
"password": "'"$password"'",
"domain": "'"$domain"'"
}' | jq -r .refresh_token`
fi
echo ""
echo "----------Refresh Token----------"
echo $VRA_REFRESH_TOKEN
echo "---------------------------------"
echo ""
echo "Environmental variables..."
echo ""
echo "VRA_URL = " $VRA_URL
echo "VRA_REFRESH_TOKEN = " $VRA_REFRESH_TOKEN
### Clear the password value. ###
unset password