multicloud_rule_manager 1.0.30 → 1.0.32

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.
Files changed (2) hide show
  1. package/commands/deploy.js +64 -53
  2. package/package.json +1 -1
@@ -1,67 +1,78 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
+ import { getAlias } from "../utils/aliasManager.js";
3
4
 
5
+ export default {
6
+ command: "deploy <alias>",
7
+ describe: "Deploy dei file rules su API",
8
+ handler: async (argv) => {
9
+ try {
10
+ console.log("🔹 Recupero credenziali per alias:", argv.alias);
11
+ const cred = getAlias(argv.alias);
12
+ // --- PRIMA CHIAMATA: token ---
13
+ console.log("🔹 Inizio richiesta token...");
14
+ const loginResp = await fetch(`https://login-eon-no-prod.bit2win.cloud/auth/realms/${cred.realm}/protocol/openid-connect/token`, {
15
+ method: "POST",
4
16
 
5
- // --- token già recuperato ---
6
- console.log("🔹 Recupero credenziali per alias:", argv.alias);
7
- const cred = getAlias(argv.alias);
17
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
18
+ body: new URLSearchParams({
19
+ client_id: cred.clientId,
20
+ client_secret: cred.clientSecret,
21
+ username: cred.username,
22
+ password: cred.password,
23
+ grant_type: "password"
24
+ })
25
+ });
8
26
 
9
- // --- PRIMA CHIAMATA: token ---
10
- console.log("🔹 Inizio richiesta token...");
11
- const loginResp = await fetch(`https://login-eon-no-prod.bit2win.cloud/auth/realms/${cred.realm}/protocol/openid-connect/token`, {
12
- method: "POST",
13
- headers: { "Content-Type": "application/x-www-form-urlencoded" },
14
- body: new URLSearchParams({
15
- client_id: cred.clientId,
16
- client_secret: cred.clientSecret,
17
- username: cred.username,
18
- password: cred.password,
19
- grant_type: "password"
20
- })
21
- });
27
+ const loginData = await loginResp.json(); // leggi direttamente JSON
28
+ const accessToken = loginData.access_token;
22
29
 
23
- const loginData = await loginResp.json(); // leggi direttamente JSON
24
- const accessToken = loginData.access_token;
30
+ // cartella rules
31
+ const rulesDir = "./rules";
25
32
 
26
- // cartella rules
27
- const rulesDir = "./rules";
33
+ // leggi tutti i file js in rules/
34
+ const files = fs.readdirSync(rulesDir).filter(f => f.endsWith(".js"));
28
35
 
29
- // leggi tutti i file js in rules/
30
- const files = fs.readdirSync(rulesDir).filter(f => f.endsWith(".js"));
36
+ for (const file of files) {
37
+ const filePath = path.join(rulesDir, file);
38
+ const content = fs.readFileSync(filePath, "utf8");
31
39
 
32
- for (const file of files) {
33
- const filePath = path.join(rulesDir, file);
34
- const content = fs.readFileSync(filePath, "utf8");
40
+ // estrai guid dal nome file: name_guid.js
41
+ const match = file.match(/_(.+)\.js$/);
42
+ if (!match) {
43
+ console.warn(`⚠️ Nome file non valido, saltato: ${file}`);
44
+ continue;
45
+ }
46
+ const guid = match[1];
35
47
 
36
- // estrai guid dal nome file: name_guid.js
37
- const match = file.match(/_(.+)\.js$/);
38
- if (!match) {
39
- console.warn(`⚠️ Nome file non valido, saltato: ${file}`);
40
- continue;
41
- }
42
- const guid = match[1];
48
+ // --- POST API ---
49
+ try {
50
+ const resp = await fetch(`https://${cred.realm}.bit2win.cloud/api/data/v1/rules`, {
51
+ method: "PATCH",
52
+ headers: {
53
+ "Authorization": `Bearer ${accessToken}`,
54
+ "Content-Type": "application/json"
55
+ },
56
+ body: JSON.stringify({
57
+ guid,
58
+ dsl_internal: content
59
+ })
60
+ });
61
+
62
+ if (!resp.ok) {
63
+ const text = await resp.text();
64
+ console.error(`❌ Errore deploy ${file}: ${resp.status} ${text}`);
65
+ } else {
66
+ console.log(`✅ Deploy riuscito per ${file}`);
67
+ }
68
+ } catch (err) {
69
+ console.error(`❌ Errore rete deploy ${file}:`, err.message);
70
+ }
71
+ }
43
72
 
44
- // --- POST API ---
45
- try {
46
- const resp = await fetch(`https://${cred.realm}.bit2win.cloud/api/data/v1/rules`, {
47
- method: "PATCH",
48
- headers: {
49
- "Authorization": `Bearer ${accessToken}`,
50
- "Content-Type": "application/json"
51
- },
52
- body: JSON.stringify({
53
- guid,
54
- dsl_internal: content
55
- })
56
- });
57
73
 
58
- if (!resp.ok) {
59
- const text = await resp.text();
60
- console.error(`❌ Errore deploy ${file}: ${resp.status} ${text}`);
61
- } else {
62
- console.log(`✅ Deploy riuscito per ${file}`);
74
+ } catch (err) {
75
+ console.error("❌ Errore:", err.message);
63
76
  }
64
- } catch (err) {
65
- console.error(`❌ Errore rete deploy ${file}:`, err.message);
66
77
  }
67
- }
78
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "multicloud_rule_manager",
3
- "version": "1.0.30",
3
+ "version": "1.0.32",
4
4
  "description": "CLI interna per retrieve/upload con token",
5
5
  "main": "index.js",
6
6
  "type": "module",