Files
olg-scratchpad/ucentral-client/rootfs/usr/share/ucentral/vyos/https_server_api.uc
NavneetBarwal-RA 0282b2b6ca Modified the earlier logic of applying uCentral Config to VYOS ie.(load(config.boot file) + merge)
To new logic ( retrieve(necessary configs) + load(necessary configs + Received Config from Ucentral)
Due to this logic the data path will not get affected for configuration changes.

Also Added the vyos_version.uc to prevent migration scripts from running.
2025-12-21 20:15:45 +05:30

85 lines
2.0 KiB
Ucode
Executable File

// This provides support to call VyOS Https Server API's as per operation mode
let fs = require("fs");
function quoteForShell(s) {
if (s == null)
return "''";
let parts = split(s, "'");
return "'" + join("'\"'\"'", parts) + "'";
}
return{
vyos_api_call: function(op_arg, op, host, key) {
// Basic argument validation
if (!key) {
fprintf(stderr, "Missing API key\n");
return null;
}
if (!host) {
fprintf(stderr, "Missing host\n");
return null;
}
if (!op) {
fprintf(stderr, "Missing op\n");
return null;
}
// Determine endpoint and payload based on op
let endpoint;
let payloadObj = { op: op };
if (op == "load" || op == "merge") {
endpoint = "/config-file";
if (op_arg && op_arg.file) {
payloadObj.file = op_arg.file;
} else if (op_arg && op_arg.string) {
payloadObj.string = op_arg.string;
} else {
fprintf(stderr, "Unsupported op_arg for op %s\n", op);
return null;
}
} else if (op == "showConfig") {
endpoint = "/retrieve";
if (op_arg && op_arg.path) {
payloadObj.path = op_arg.path;
} else {
// default: whole config
payloadObj.path = [];
}
} else {
fprintf(stderr, "Unsupported op: %s\n", op);
return null;
}
// Convert payload to JSON string
let payloadStr = sprintf("%J", payloadObj);
let url = host + endpoint;
// Build the curl command
let cmd = sprintf(
"curl -skL --connect-timeout 3 -m 5 -X POST %s " +
"--form-string data=%s --form key=%s",
quoteForShell(url),
quoteForShell(payloadStr),
quoteForShell(key)
);
// Run curl and capture output
let proc = fs.popen(cmd, "r");
if (!proc) {
fprintf(stderr, "Failed to start curl\n");
return null;
}
let out = proc.read("all");
proc.close();
return out;
}
};