multicloud_rule_manager 1.0.39 โ 1.0.41
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 +11 -44
- package/package.json +1 -1
package/commands/retrieve.js
CHANGED
|
@@ -41,7 +41,7 @@ export default {
|
|
|
41
41
|
// --- SECONDA CHIAMATA: retrieve ---
|
|
42
42
|
console.log("๐น Inizio richiesta dati API...");
|
|
43
43
|
const apiResp = await fetch(
|
|
44
|
-
`https://${cred.realm}.cloud/api/data/v1/rules`,
|
|
44
|
+
`https://${cred.realm}.bit2win.cloud/api/data/v1/rules`,
|
|
45
45
|
{
|
|
46
46
|
method: "GET",
|
|
47
47
|
headers: {
|
|
@@ -52,54 +52,21 @@ export default {
|
|
|
52
52
|
}
|
|
53
53
|
);
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
55
|
+
console.log("๐น Status risposta API:", apiResp.status);
|
|
56
|
+
const apiText = await apiResp.text();
|
|
57
|
+
console.log("๐น Body risposta API (raw):", apiText);
|
|
59
58
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
console.log("๐น API final URL:", data.url);
|
|
66
|
-
|
|
67
|
-
// Controlla che sia array
|
|
68
|
-
if (!Array.isArray(data)) {
|
|
69
|
-
throw new Error("La risposta API non รจ una lista di oggetti");
|
|
59
|
+
if (!apiResp.ok) {
|
|
60
|
+
throw new Error(`Errore API ${apiResp.status}: ${apiText}`);
|
|
70
61
|
}
|
|
71
62
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
63
|
+
let data;
|
|
64
|
+
try {
|
|
65
|
+
data = JSON.parse(apiText);
|
|
66
|
+
} catch (err) {
|
|
67
|
+
throw new Error(`Parsing JSON fallito: ${err.message}`);
|
|
77
68
|
}
|
|
78
69
|
|
|
79
|
-
// Per ogni record genera file SOLO se dsl_internal esiste
|
|
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
|
-
if (!record.dsl_internal || record.dsl_internal.trim() === "") {
|
|
88
|
-
console.log(`โ ๏ธ Record "${record.name}" saltato: dsl_internal vuoto`);
|
|
89
|
-
continue;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const safeName = record.name.replace(/[<>:"/\\|?*]+/g, "_");
|
|
93
|
-
const fileName = `${safeName}_${record.guid}.js`;
|
|
94
|
-
const filePath = `${rulesDir}/${fileName}`;
|
|
95
|
-
|
|
96
|
-
fs.writeFileSync(filePath, record.dsl_internal, "utf8");
|
|
97
|
-
|
|
98
|
-
console.log(`๐ File scritto: ${fileName}`);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
console.log("๐ Tutti i file con contenuto valido sono stati generati");
|
|
102
|
-
|
|
103
70
|
} catch (err) {
|
|
104
71
|
console.error("โ Errore:", err.message);
|
|
105
72
|
}
|