This repository has been archived by the owner on Dec 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
initialise.js
143 lines (133 loc) · 5.82 KB
/
initialise.js
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
const server = require('./server/server');
async function auth(username, role, email, password) {
const user = await User.create({ username, email, password });
const user_role = await Role.create({ name: role });
await user_role.principals.create({ principalType: RoleMapping.USER, principalId: user.id });
const login = await User.login({ email, password });
return login.id;
};
const { spawnSync } = require("child_process");
const User = server.models.User;
const Role = server.models.Role;
const RoleMapping = server.models.RoleMapping;
const HOST = process.env.HOST || "localhost:3000";
const os = [], arch = [], distro = [], lts = [], node = [], validPlatforms = [];
async function main() {
const adminToken = await auth("admin", "admin", "[email protected]", "admin"); // TODO: set admin username, role, email, password
const testToken = await auth("test", "test", "[email protected]", "test"); // TODO: set test username, role, email, password
console.log(`\nADMIN_TOKEN: ${adminToken}\nTEST_TOKEN: ${testToken}\n\n`);
const TOKEN = testToken;
os.push(spawnSync("curl", ['-X', 'POST',
'--header', 'Content-Type: application/json',
'--header', 'Accept: application/json',
'--header', `Authorization: ${TOKEN}`,
'-d', JSON.stringify({ arch: "x64" }),
`http://${HOST}/api/Architectures`
]).stdout.toString().trim());
os.push(spawnSync("curl", ['-X', 'POST',
'--header', 'Content-Type: application/json',
'--header', 'Accept: application/json',
'--header', `Authorization: ${TOKEN}`,
'-d', JSON.stringify({ arch: "ppc64le" }),
`http://${HOST}/api/Architectures`
]).stdout.toString().trim());
os.push(spawnSync("curl", ['-X', 'POST',
'--header', 'Content-Type: application/json',
'--header', 'Accept: application/json',
'--header', `Authorization: ${TOKEN}`,
'-d', JSON.stringify({ arch: "s390x" }),
`http://${HOST}/api/Architectures`
]).stdout.toString().trim());
console.log(os);
arch.push(spawnSync("curl", ['-X', 'POST',
'--header', 'Content-Type: application/json',
'--header', 'Accept: application/json',
'--header', `Authorization: ${TOKEN}`,
'-d', JSON.stringify({ os: "linux" }),
`http://${HOST}/api/OperatingSystems`
]).stdout.toString().trim());
arch.push(spawnSync("curl", ['-X', 'POST',
'--header', 'Content-Type: application/json',
'--header', 'Accept: application/json',
'--header', `Authorization: ${TOKEN}`,
'-d', JSON.stringify({ os: "darwin" }),
`http://${HOST}/api/OperatingSystems`
]).stdout.toString().trim());
console.log(arch);
distro.push(spawnSync("curl", ['-X', 'POST',
'--header', 'Content-Type: application/json',
'--header', 'Accept: application/json',
'--header', `Authorization: ${TOKEN}`,
'-d', JSON.stringify({ distro: "ubuntu-16.04" }),
`http://${HOST}/api/Distributions`
]).stdout.toString().trim());
distro.push(spawnSync("curl", ['-X', 'POST',
'--header', 'Content-Type: application/json',
'--header', 'Accept: application/json',
'--header', `Authorization: ${TOKEN}`,
'-d', JSON.stringify({ distro: "macos10.13" }),
`http://${HOST}/api/Distributions`
]).stdout.toString().trim());
console.log(distro);
lts.push(spawnSync("curl", ['-X', 'POST',
'--header', 'Content-Type: application/json',
'--header', 'Accept: application/json',
'--header', `Authorization: ${TOKEN}`,
'-d', JSON.stringify({ lts_version: 6 }),
`http://${HOST}/api/LTSVersions`
]).stdout.toString().trim());
lts.push(spawnSync("curl", ['-X', 'POST',
'--header', 'Content-Type: application/json',
'--header', 'Accept: application/json',
'--header', `Authorization: ${TOKEN}`,
'-d', JSON.stringify({ lts_version: 8 }),
`http://${HOST}/api/LTSVersions`
]).stdout.toString().trim());
console.log(lts);
node.push(spawnSync("curl", ['-X', 'POST',
'--header', 'Content-Type: application/json',
'--header', 'Accept: application/json',
'--header', `Authorization: ${TOKEN}`,
'-d', JSON.stringify({ node_version: "v6.14.3", lts_version: 6}),
`http://${HOST}/api/nodeVersions`
]).stdout.toString().trim());
node.push(spawnSync("curl", ['-X', 'POST',
'--header', 'Content-Type: application/json',
'--header', 'Accept: application/json',
'--header', `Authorization: ${TOKEN}`,
'-d', JSON.stringify({ node_version: "v8.11.3", lts_version: 8}),
`http://${HOST}/api/nodeVersions`
]).stdout.toString().trim());
console.log(node);
validPlatforms.push(spawnSync("curl", ['-X', 'POST',
'--header', 'Content-Type: application/json',
'--header', 'Accept: application/json',
'--header', `Authorization: ${TOKEN}`,
'-d', JSON.stringify({ os: "linux", arch: "x64", distro: "ubuntu-16.04"}),
`http://${HOST}/api/ValidPlatforms`
]).stdout.toString().trim());
validPlatforms.push(spawnSync("curl", ['-X', 'POST',
'--header', 'Content-Type: application/json',
'--header', 'Accept: application/json',
'--header', `Authorization: ${TOKEN}`,
'-d', JSON.stringify({ os: "linux", arch: "s390x", distro: "ubuntu-16.04"}),
`http://${HOST}/api/ValidPlatforms`
]).stdout.toString().trim());
validPlatforms.push(spawnSync("curl", ['-X', 'POST',
'--header', 'Content-Type: application/json',
'--header', 'Accept: application/json',
'--header', `Authorization: ${TOKEN}`,
'-d', JSON.stringify({ os: "linux", arch: "ppc64le", distro: "ubuntu-16.04"}),
`http://${HOST}/api/ValidPlatforms`
]).stdout.toString().trim());
validPlatforms.push(spawnSync("curl", ['-X', 'POST',
'--header', 'Content-Type: application/json',
'--header', 'Accept: application/json',
'--header', `Authorization: ${TOKEN}`,
'-d', JSON.stringify({ os: "darwin", arch: "x64", distro: "macos10.13"}),
`http://${HOST}/api/ValidPlatforms`
]).stdout.toString().trim());
console.log(validPlatforms);
process.exit(0);
}
main();