multicloud_rule_manager 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/commands/retrieve.js +41 -15
- package/package.json +1 -1
package/commands/retrieve.js
CHANGED
|
@@ -10,34 +10,60 @@ export default {
|
|
|
10
10
|
},
|
|
11
11
|
handler: async (argv) => {
|
|
12
12
|
try {
|
|
13
|
+
console.log("🔹 Recupero credenziali per alias:", argv.alias);
|
|
13
14
|
const cred = getAlias(argv.alias);
|
|
14
15
|
|
|
15
|
-
//
|
|
16
|
+
// --- PRIMA CHIAMATA: token ---
|
|
17
|
+
console.log("🔹 Inizio richiesta token...");
|
|
16
18
|
const loginResp = await fetch(`https://login-eon-no-prod.bit2win.cloud/auth/realms/${cred.realm}/protocol/openid-connect/token`, {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
|
|
19
|
+
method: "POST",
|
|
20
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
21
|
+
body: new URLSearchParams({
|
|
22
|
+
client_id: cred.clientId,
|
|
23
|
+
client_secret: cred.clientSecret,
|
|
24
|
+
username: cred.username,
|
|
25
|
+
password: cred.password,
|
|
26
|
+
grant_type: "password"
|
|
27
|
+
})
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
console.log("🔹 Token status:", loginResp.status);
|
|
31
|
+
const loginText = await loginResp.text();
|
|
32
|
+
console.log("🔹 Token response raw:", loginText);
|
|
33
|
+
|
|
34
|
+
let loginData;
|
|
35
|
+
try {
|
|
36
|
+
loginData = JSON.parse(loginText);
|
|
37
|
+
console.log("🔹 Token JSON parsed:", loginData);
|
|
38
|
+
} catch (err) {
|
|
39
|
+
throw new Error(`Token JSON parsing failed: ${err.message}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
29
42
|
const { access_token } = loginData;
|
|
30
43
|
if (!access_token) throw new Error("Token non ricevuto");
|
|
31
44
|
|
|
32
|
-
//
|
|
45
|
+
// --- SECONDA CHIAMATA: retrieve ---
|
|
46
|
+
console.log("🔹 Inizio richiesta dati API...");
|
|
33
47
|
const apiResp = await fetch(`https://${cred.realm}.bit2win.cloud/api/data/v1/rules/`, {
|
|
34
48
|
method: "GET",
|
|
35
49
|
headers: { Authorization: `Bearer ${access_token}` }
|
|
36
50
|
});
|
|
37
51
|
|
|
38
|
-
|
|
52
|
+
console.log("🔹 API status:", apiResp.status);
|
|
53
|
+
const apiText = await apiResp.text();
|
|
54
|
+
console.log("🔹 API response raw:", apiText);
|
|
55
|
+
|
|
56
|
+
let data;
|
|
57
|
+
try {
|
|
58
|
+
data = JSON.parse(apiText);
|
|
59
|
+
console.log("🔹 API JSON parsed:", data);
|
|
60
|
+
} catch (err) {
|
|
61
|
+
throw new Error(`API JSON parsing failed: ${err.message}`);
|
|
62
|
+
}
|
|
63
|
+
|
|
39
64
|
fs.writeFileSync(argv.output, JSON.stringify(data, null, 2));
|
|
40
65
|
console.log(`🚀 Dati salvati in ${argv.output}`);
|
|
66
|
+
|
|
41
67
|
} catch (err) {
|
|
42
68
|
console.error("❌ Errore:", err.message);
|
|
43
69
|
}
|