-
Notifications
You must be signed in to change notification settings - Fork 6
/
pip_set_server.ado
96 lines (73 loc) · 2.25 KB
/
pip_set_server.ado
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
/*==================================================
project: Define which server to use
Author: R.Andres Castaneda
E-email: [email protected]
url:
Dependencies: The World Bank
----------------------------------------------------
Creation Date: 1 Dec 2021 - 10:59:19
Modification Date:
Do-file version: 01
References:
Output:
==================================================*/
/*==================================================
0: Program set up
==================================================*/
program define pip_set_server, rclass
syntax [, server(string) ]
version 16.1
//========================================================
// Define server
//========================================================
*##s
* local server "prod"
//------------ If shortcut used
local current_server "https://api.worldbank.org/pip/v1" // production
local server = lower("`server'")
if (inlist("`server'", "qa", "dev", "vm")) {
local url "${pip_svr_`server'}"
}
else if (lower("`server'") == "prod") {
local url "`current_server'"
local server "prod"
}
/*==================================================
2: Server not defined
==================================================*/
else if ("`server'" == "") {
local url "`current_server'"
local server "prod"
}
else {
noi disp in red "server {it:`server'} not allowed"
error
}
//========================================================
// Test API Health
//========================================================
cap scalar tpage = fileread(`"`url'/health-check"')
* disp tpage
*##e
if (!regexm(tpage, "API is running") | _rc) {
noi disp in red "There is a problem with PIP API server. Try again later"
error
}
//========================================================
// Return values
//========================================================
global pip_host "`url'"
global pip_server "`server'"
return local server = "`server'"
return local url = "`url'"
return local base = "`url'/pip"
return local base_grp = "`url'/pip-grp"
end
exit
/* End of do-file */
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
Notes:
1.
2.
3.
Version Control: