-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgo-pro
executable file
·195 lines (172 loc) · 13.5 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/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 │
├───────────────────────────────┼──────────────────────────────────────────────────────────┤
│ 🔐 Create PSD2 Provider! │ ${ANSI_FORMAT_VERBOSE}dotnet Tinker/TinkerSrc.dll CreatePsd2Configuration${ANSI_FORMAT_CLEAR} │
│ │ │
│ │ ${ANSI_FORMAT_DIM}Required parameters:${ANSI_FORMAT_CLEAR} │
│ │ ${ANSI_FORMAT_DIM}--env [SANDBOX/PRODUCTION]${ANSI_FORMAT_CLEAR} │
│ │ ${ANSI_FORMAT_DIM}--certificate [path]${ANSI_FORMAT_CLEAR} │
│ │ ${ANSI_FORMAT_DIM}--chain [path]${ANSI_FORMAT_CLEAR} │
│ │ ${ANSI_FORMAT_DIM}--key [path]${ANSI_FORMAT_CLEAR} │
├───────────────────────────────┼──────────────────────────────────────────────────────────┤
│ 🔒 Create PSD2 OAuth Client │ ${ANSI_FORMAT_VERBOSE}dotnet Tinker/TinkerSrc.dll CreateOauthClient${ANSI_FORMAT_CLEAR} │
│ │ │
│ │ ${ANSI_FORMAT_DIM}Required parameters:${ANSI_FORMAT_CLEAR} │
│ │ ${ANSI_FORMAT_DIM}--context [path]${ANSI_FORMAT_CLEAR} │
│ │ ${ANSI_FORMAT_DIM}--redirect [uri]${ANSI_FORMAT_CLEAR} │
├───────────────────────────────┼──────────────────────────────────────────────────────────┤
│ 🔓 Test PSD2 OAuth │ ${ANSI_FORMAT_VERBOSE}dotnet Tinker/TinkerSrc.dll TestOauth${ANSI_FORMAT_CLEAR} │
│ │ │
│ │ ${ANSI_FORMAT_DIM}Required parameters:${ANSI_FORMAT_CLEAR} │
│ │ ${ANSI_FORMAT_DIM}--env [SANDBOX/PRODUCTION]${ANSI_FORMAT_CLEAR} │
│ │ ${ANSI_FORMAT_DIM}--code [authcode]${ANSI_FORMAT_CLEAR} │
│ │ ${ANSI_FORMAT_DIM}--configuration [path]${ANSI_FORMAT_CLEAR} │
│ │ ${ANSI_FORMAT_DIM}--redirect [uri]${ANSI_FORMAT_CLEAR} │
|───────────────────────────────┼──────────────────────────────────────────────────────────┤
│ ✅ Show Overview │ ${ANSI_FORMAT_VERBOSE}dotnet Tinker/TinkerSrc.dll UserOverview --production${ANSI_FORMAT_CLEAR} │
├───────────────────────────────┼──────────────────────────────────────────────────────────┤
│ 🔼 Make a payment │ ${ANSI_FORMAT_VERBOSE}dotnet Tinker/TinkerSrc.dll MakePayment --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}dotnet Tinker/TinkerSrc.dll MakeRequest --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}dotnet Tinker/TinkerSrc.dll LinkCard --production${ANSI_FORMAT_CLEAR} │
│ │ │
│ │ ${ANSI_FORMAT_DIM}Additional parameters:${ANSI_FORMAT_CLEAR} │
│ │ ${ANSI_FORMAT_DIM}--card [id]${ANSI_FORMAT_CLEAR} │
│ │ ${ANSI_FORMAT_DIM}--account [id]${ANSI_FORMAT_CLEAR} │
├───────────────────────────────┼──────────────────────────────────────────────────────────┤
│ ✏️ Update Account │ ${ANSI_FORMAT_VERBOSE}dotnet Tinker/TinkerSrc.dll UpdateAccount --production${ANSI_FORMAT_CLEAR} │
│ │ │
│ │ ${ANSI_FORMAT_DIM}Additional parameters:${ANSI_FORMAT_CLEAR} │
│ │ ${ANSI_FORMAT_DIM}--account [id]${ANSI_FORMAT_CLEAR} │
│ │ ${ANSI_FORMAT_DIM}--name [string]${ANSI_FORMAT_CLEAR} │
├───────────────────────────────┼──────────────────────────────────────────────────────────┤
│ 📫️ Add Callback Url │ ${ANSI_FORMAT_VERBOSE}dotnet Tinker/TinkerSrc.dll AddCallbackUrl --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}")"
dotnet Tinker/TinkerSrc.dll CreateProductionConfiguration --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}"