mirror of
https://github.com/j3ssie/osmedeus.git
synced 2026-09-28 20:44:57 +02:00
feat: add cdn tree listing and webhook config setters
This commit is contained in:
@@ -1023,6 +1023,11 @@ func setNotificationValue(cfg *config.Config, parts []string, value string) erro
|
||||
return fmt.Errorf("missing telegram field")
|
||||
}
|
||||
return setTelegramValue(cfg, parts[1:], value)
|
||||
case "webhooks":
|
||||
if len(parts) < 2 {
|
||||
return fmt.Errorf("missing webhooks index and field (e.g., webhooks.0.url)")
|
||||
}
|
||||
return setWebhooksValue(cfg, parts[1:], value)
|
||||
default:
|
||||
return fmt.Errorf("unknown notification field: %s", parts[0])
|
||||
}
|
||||
@@ -1055,6 +1060,56 @@ func setTelegramValue(cfg *config.Config, parts []string, value string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// setWebhooksValue sets webhook config fields (notification.webhooks.<index>.<field>)
|
||||
func setWebhooksValue(cfg *config.Config, parts []string, value string) error {
|
||||
if len(parts) < 2 {
|
||||
return fmt.Errorf("missing webhook index and field (e.g., webhooks.0.url)")
|
||||
}
|
||||
|
||||
index, err := strconv.Atoi(parts[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("webhook index must be a number: %s", parts[0])
|
||||
}
|
||||
|
||||
// Ensure webhooks slice is large enough
|
||||
for len(cfg.Notification.Webhooks) <= index {
|
||||
cfg.Notification.Webhooks = append(cfg.Notification.Webhooks, config.WebhookConfig{})
|
||||
}
|
||||
|
||||
field := parts[1]
|
||||
switch field {
|
||||
case "url":
|
||||
cfg.Notification.Webhooks[index].URL = value
|
||||
case "enabled":
|
||||
enabled, err := strconv.ParseBool(value)
|
||||
if err != nil {
|
||||
return fmt.Errorf("enabled must be true or false")
|
||||
}
|
||||
cfg.Notification.Webhooks[index].Enabled = enabled
|
||||
case "timeout":
|
||||
timeout, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
return fmt.Errorf("timeout must be a number")
|
||||
}
|
||||
cfg.Notification.Webhooks[index].Timeout = timeout
|
||||
case "retry_count":
|
||||
retryCount, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
return fmt.Errorf("retry_count must be a number")
|
||||
}
|
||||
cfg.Notification.Webhooks[index].RetryCount = retryCount
|
||||
case "skip_tls_verify":
|
||||
skip, err := strconv.ParseBool(value)
|
||||
if err != nil {
|
||||
return fmt.Errorf("skip_tls_verify must be true or false")
|
||||
}
|
||||
cfg.Notification.Webhooks[index].SkipTLSVerify = skip
|
||||
default:
|
||||
return fmt.Errorf("unknown webhook field: %s (available: url, enabled, timeout, retry_count, skip_tls_verify)", field)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// setEnvironmentsValue sets an environments config field
|
||||
func setEnvironmentsValue(cfg *config.Config, parts []string, value string) error {
|
||||
if len(parts) == 0 {
|
||||
|
||||
+32
-2
@@ -172,8 +172,8 @@ func runFunctionEval(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
script = fmt.Sprintf("%s(%s)", args[0], strings.Join(quotedArgs, ", "))
|
||||
} else {
|
||||
// Single arg: use as-is (could be full expression or function name with no args)
|
||||
script = args[0]
|
||||
// Single arg: check if it is a bare function name and add () if needed
|
||||
script = normalizeScriptExpression(args[0])
|
||||
}
|
||||
} else if evalScript != "" {
|
||||
// Script provided via -e flag
|
||||
@@ -188,6 +188,10 @@ func runFunctionEval(cmd *cobra.Command, args []string) error {
|
||||
script = strings.TrimSpace(string(data))
|
||||
}
|
||||
|
||||
if script != "" {
|
||||
script = normalizeScriptExpression(script)
|
||||
}
|
||||
|
||||
if script == "" {
|
||||
return fmt.Errorf("no script provided: use positional argument, -e flag, --function-file, or --stdin")
|
||||
}
|
||||
@@ -443,3 +447,29 @@ func runFunctionList(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// normalizeScriptExpression checks if the input is a bare function name (without parentheses)
|
||||
// and adds () to make it a valid function call. This allows "osmedeus eval cdn_ls_tree"
|
||||
// to work the same as "osmedeus eval cdn_ls_tree()"
|
||||
func normalizeScriptExpression(expr string) string {
|
||||
expr = strings.TrimSpace(expr)
|
||||
|
||||
// If it already has parentheses, return as-is
|
||||
if strings.Contains(expr, "(") {
|
||||
return expr
|
||||
}
|
||||
|
||||
// Check if it's a known function name
|
||||
allFuncs := functions.AllFunctions()
|
||||
for _, fn := range allFuncs {
|
||||
if expr == fn {
|
||||
if fn == functions.FnCdnLsTree {
|
||||
return expr + "(\"\")"
|
||||
}
|
||||
return expr + "()"
|
||||
}
|
||||
}
|
||||
|
||||
// Not a known function, return as-is (could be a variable or expression)
|
||||
return expr
|
||||
}
|
||||
|
||||
+7
-1
@@ -420,7 +420,13 @@ func UsageConfigSet() string {
|
||||
` + terminal.Yellow("redis.port") + ` Redis port
|
||||
` + terminal.Yellow("global_vars.<name>") + ` Set a global variable
|
||||
` + terminal.Yellow("notification.enabled") + ` Enable notifications (true/false)
|
||||
` + terminal.Yellow("notification.telegram.bot_token") + ` Telegram bot token
|
||||
` + terminal.Yellow("notification.provider") + ` Notification provider (telegram, webhook)
|
||||
` + terminal.Yellow("notification.telegram.enabled") + ` Enable Telegram notifications (true/false)
|
||||
` + terminal.Yellow("notification.telegram.bot_token") + ` Telegram bot token from @BotFather
|
||||
` + terminal.Yellow("notification.telegram.chat_id") + ` Telegram chat ID to send messages to
|
||||
` + terminal.Yellow("notification.webhooks.0.url") + ` Webhook URL (use index 0, 1, 2... for multiple)
|
||||
` + terminal.Yellow("notification.webhooks.0.enabled") + ` Enable webhook (true/false)
|
||||
` + terminal.Yellow("notification.webhooks.0.timeout") + ` Webhook timeout in seconds
|
||||
` + terminal.Yellow("environments.external_binaries_path") + ` Binaries directory
|
||||
` + terminal.Yellow("storage.enabled") + ` Enable cloud storage (true/false)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user