-
Notifications
You must be signed in to change notification settings - Fork 7
/
go-pro
executable file
·173 lines (150 loc) · 8.81 KB
/
go-pro
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env bash
WORKING_DIR="$(cd `dirname $0`; pwd)"
SCRIPT_NAME="$(basename $0)"
source "${WORKING_DIR}/base.sh"
# Header constants.
HEADER_GO_PRO="${ANSI_FORMAT_COLOR_YELLOW}
██████╗ ██████╗ ██████╗ ██████╗ ██████╗
██╔════╝ ██╔═══██╗ ██╔══██╗██╔══██╗██╔═══██╗
██║ ███╗██║ ██║ ██████╔╝██████╔╝██║ ██║
██║ ██║██║ ██║ ██╔═══╝ ██╔══██╗██║ ██║
╚██████╔╝╚██████╔╝ ██║ ██║ ██║╚██████╔╝
╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝
${ANSI_FORMAT_CLEAR}"
FOOTER_PRODUCTION_READY="${ANSI_FORMAT_COLOR_GREEN_LIGHT}
🌈 You're ready to use the PRODUCTION environment.
${ANSI_FORMAT_CLEAR}"
# Usage constant.
USAGE="\
┌───────────────────────┬─────────────────────────────────────────┐
│ │ Run │
├───────────────────────┼─────────────────────────────────────────┤
│ ✅ Show Overview │ ${ANSI_FORMAT_VERBOSE}tinker/user_overview.py --production${ANSI_FORMAT_CLEAR} │
├───────────────────────┼─────────────────────────────────────────┤
│ 🔼 Make a payment │ ${ANSI_FORMAT_VERBOSE}tinker/make_payment.py --production${ANSI_FORMAT_CLEAR} │
│ │ │
│ │ ${ANSI_FORMAT_DIM}Additional parameters:${ANSI_FORMAT_CLEAR} │
│ │ ${ANSI_FORMAT_DIM}--amount [euro]${ANSI_FORMAT_CLEAR} │
│ │ ${ANSI_FORMAT_DIM}--recipient [email]${ANSI_FORMAT_CLEAR} │
│ │ ${ANSI_FORMAT_DIM}--description [string]${ANSI_FORMAT_CLEAR} │
├───────────────────────┼─────────────────────────────────────────┤
│ 🔽 Make a request │ ${ANSI_FORMAT_VERBOSE}tinker/make_request.py --production${ANSI_FORMAT_CLEAR} │
│ │ │
│ │ ${ANSI_FORMAT_DIM}Additional parameters:${ANSI_FORMAT_CLEAR} │
│ │ ${ANSI_FORMAT_DIM}--amount [euro]${ANSI_FORMAT_CLEAR} │
│ │ ${ANSI_FORMAT_DIM}--recipient [email]${ANSI_FORMAT_CLEAR} │
│ │ ${ANSI_FORMAT_DIM}--description [string]${ANSI_FORMAT_CLEAR} │
├───────────────────────┼─────────────────────────────────────────┤
│ 🔗 Link Card │ ${ANSI_FORMAT_VERBOSE}tinker/link_card.py --production${ANSI_FORMAT_CLEAR} │
│ │ │
│ │ ${ANSI_FORMAT_DIM}Additional parameters:${ANSI_FORMAT_CLEAR} │
│ │ ${ANSI_FORMAT_DIM}--card-id [id]${ANSI_FORMAT_CLEAR} │
│ │ ${ANSI_FORMAT_DIM}--account-id [id]${ANSI_FORMAT_CLEAR} │
├───────────────────────┼─────────────────────────────────────────┤
│ ✏️ Update Account │ ${ANSI_FORMAT_VERBOSE}tinker/update_account.py --production${ANSI_FORMAT_CLEAR} │
│ │ │
│ │ ${ANSI_FORMAT_DIM}Additional parameters:${ANSI_FORMAT_CLEAR} │
│ │ ${ANSI_FORMAT_DIM}--account-id [id]${ANSI_FORMAT_CLEAR} │
│ │ ${ANSI_FORMAT_DIM}--name [string]${ANSI_FORMAT_CLEAR} │
├───────────────────────┼─────────────────────────────────────────┤
│ 📫️ Add Callback Url │ ${ANSI_FORMAT_VERBOSE}tinker/add_callback_url.py --production${ANSI_FORMAT_CLEAR} │
│ │ │
│ │ ${ANSI_FORMAT_DIM}Additional parameters:${ANSI_FORMAT_CLEAR} │
│ │ ${ANSI_FORMAT_DIM}--url [url]${ANSI_FORMAT_CLEAR} │
└───────────────────────┴─────────────────────────────────────────┘
"
# Endpoint constants.
API_TINKER='https://api.tinker.bunq.com/v1/'
# Status constants.
STATUS_CREATED="CREATED"
STATUS_ACCEPTED="ACCEPTED"
function shouldEnrollProductionUser
{
[ ! -f "${WORKING_DIR}/bunq-production.conf" ] && return 0 || return 1
}
function enrollProductionUser
{
response="$(createUserCredentialPasswordIpRequest)"
publicUuid="$(determineUserCredentialPasswordIpRequestPublicUuidFromResponse ${response})"
token="$(determineUserCredentialPasswordIpRequestTokenQrFromResponse ${response})"
displayTokenQr "${token}"
waitForUserCredentialPasswordIpRequestAccepted "${publicUuid}"
clearTokenQr "${token}"
apiKey="$(getApiKeyFromUserCredentialPasswordIpRequestAccepted "${publicUuid}")"
tinker/create_production_configuration.py --api-key "${apiKey}"
}
function createUserCredentialPasswordIpRequest
{
echo "$(curl -k -s -X POST -H "X-Bunq-Client-Request-Id: unique" ${API_TINKER}/credential-password-ip-request)"
}
function determineUserCredentialPasswordIpRequestPublicUuidFromResponse
{
echo "$(echo ${1} | jq -r '.Response | .[0].UserCredentialPasswordIpRequest.uuid')"
}
function determineUserCredentialPasswordIpRequestTokenQrFromResponse
{
echo "$(echo ${1} | jq -r '.Response | .[0].UserCredentialPasswordIpRequest.qr_token')"
}
function determineUserCredentialPasswordIpRequestStatusFromResponse
{
echo "$(echo ${1} | jq -r '.Response | .[0].UserCredentialPasswordIpRequest.status')"
}
function determineUserCredentialPasswordIpRequestApiKeyFromResponse
{
echo "$(echo ${1} | jq -r '.Response | .[0].UserCredentialPasswordIpRequest.api_key')"
}
function displayTokenQr
{
token="${1}"
echo -e "$(qrencode --type ANSI256 --margin 1 "18:${token}")"
echo ""
echo -e " ${ANSI_FORMAT_COLOR_GREEN_LIGHT}Scan this QR with your bunq app${ANSI_FORMAT_CLEAR}"
echo ""
}
function clearTokenQr
{
token="${1}"
countAllLineToClear="$(displayTokenQr "${token}" | wc -l)"
clearLines "${countAllLineToClear}"
}
function clearLines
{
countAllLineToClear="${1}"
seq 1 "${countAllLineToClear}" | while read i; do echo -en "\033[1A\r\033[K"; done
}
function waitForUserCredentialPasswordIpRequestAccepted
{
uuid="${1}"
while ! isUserCredentialPasswordIpRequestAccepted "${uuid}" ; do
sleep 1
done
}
function isUserCredentialPasswordIpRequestAccepted
{
uuid="${1}"
response="$(curl -k -s -X GET -H "X-Bunq-Client-Request-Id: unique" ${API_TINKER}/credential-password-ip-request/${uuid})"
status="$(determineUserCredentialPasswordIpRequestStatusFromResponse "${response}")"
if [ "${status}" = "${STATUS_ACCEPTED}" ]; then
return 0
else
return 1
fi
}
function getApiKeyFromUserCredentialPasswordIpRequestAccepted
{
uuid="${1}"
response="$(curl -k -s -X GET -H "X-Bunq-Client-Request-Id: unique" ${API_TINKER}/credential-password-ip-request/${uuid})"
status="$(determineUserCredentialPasswordIpRequestStatusFromResponse "${response}")"
echo "$(determineUserCredentialPasswordIpRequestApiKeyFromResponse "${response}")"
}
echo -e "${HEADER_GO_PRO}"
if shouldEnrollProductionUser; then
enrollProductionUser
else
# Already have a production config.
:
fi
clearLines 1
echo -e "${FOOTER_PRODUCTION_READY}"
sleep 1
echo -e "${USAGE}"