multicloud_rule_manager 1.0.24 โ 1.0.25
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 +55 -30
- package/package.json +1 -1
package/commands/retrieve.js
CHANGED
|
@@ -27,50 +27,75 @@ export default {
|
|
|
27
27
|
})
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
const access_token = loginData.access_token;
|
|
30
|
+
const loginData = await loginResp.json(); // leggi direttamente JSON
|
|
31
|
+
const access_token = loginData.access_token;
|
|
32
32
|
|
|
33
|
-
console.log("๐น Token response raw:", access_token);
|
|
33
|
+
console.log("๐น Token response raw:", access_token);
|
|
34
34
|
|
|
35
|
-
if (!access_token) {
|
|
36
|
-
|
|
37
|
-
}
|
|
35
|
+
if (!access_token) {
|
|
36
|
+
throw new Error("Token non ricevuto nel campo 'access_token'");
|
|
37
|
+
}
|
|
38
38
|
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
// --- SECONDA CHIAMATA: retrieve ---
|
|
42
42
|
console.log("๐น Inizio richiesta dati API...");
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
);
|
|
43
|
+
const apiResp = await fetch(
|
|
44
|
+
"https://eon-dev-01.bit2win.cloud/api/data/v1/rules",
|
|
45
|
+
{
|
|
46
|
+
method: "GET",
|
|
47
|
+
headers: {
|
|
48
|
+
"Authorization": `Bearer ${access_token}`,
|
|
49
|
+
"Accept": "application/json"
|
|
50
|
+
},
|
|
51
|
+
redirect: "manual"
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
54
|
|
|
55
55
|
|
|
56
|
-
console.log("๐น API token:", "Bearer "+access_token);
|
|
57
56
|
console.log("๐น API status:", apiResp.status);
|
|
58
|
-
const apiText = await apiResp.text();
|
|
59
|
-
console.log("๐น API response raw:", apiText);
|
|
60
|
-
const apiTeapixt = await apiResp.json();
|
|
61
|
-
console.log("๐น API response rawjson:", apiTeapixt);
|
|
62
57
|
|
|
63
|
-
|
|
58
|
+
if (!apiResp.ok) {
|
|
59
|
+
const errText = await apiResp.text();
|
|
60
|
+
throw new Error(`Errore API ${apiResp.status}: ${errText}`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const data = await apiResp.json();
|
|
64
|
+
|
|
64
65
|
console.log("๐น API final URL:", apiResp.url);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
|
|
67
|
+
// Se non รจ un array โ errore
|
|
68
|
+
if (!Array.isArray(data)) {
|
|
69
|
+
throw new Error("La risposta API non รจ una lista di oggetti");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Crea cartella rules se non esiste
|
|
73
|
+
const rulesDir = "./rules";
|
|
74
|
+
if (!fs.existsSync(rulesDir)) {
|
|
75
|
+
fs.mkdirSync(rulesDir, { recursive: true });
|
|
76
|
+
console.log("๐ Cartella 'rules' creata");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Per ogni record crea/sovrascrive file
|
|
80
|
+
for (const record of data) {
|
|
81
|
+
|
|
82
|
+
if (!record.name || !record.guid) {
|
|
83
|
+
console.warn("โ ๏ธ Record saltato (name o guid mancanti):", record);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const safeName = record.name.replace(/[<>:"/\\|?*]+/g, "_");
|
|
88
|
+
const fileName = `${safeName}_${record.guid}.js`;
|
|
89
|
+
const filePath = `${rulesDir}/${fileName}`;
|
|
90
|
+
|
|
91
|
+
const content = record.dsl_internal || "";
|
|
92
|
+
|
|
93
|
+
fs.writeFileSync(filePath, content, "utf8");
|
|
94
|
+
|
|
95
|
+
console.log(`๐ File scritto: ${fileName}`);
|
|
70
96
|
}
|
|
71
97
|
|
|
72
|
-
|
|
73
|
-
console.log(`๐ Dati salvati in ${argv.output}`);
|
|
98
|
+
console.log("๐ Tutti i file sono stati generati correttamente");
|
|
74
99
|
|
|
75
100
|
} catch (err) {
|
|
76
101
|
console.error("โ Errore:", err.message);
|