You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cloudstack.apache.org by "vishesh92 (via GitHub)" <gi...@apache.org> on 2026/09/01 08:00:37 UTC

[PR] Add support to pass env vars to in addition to args to configure cmk [cloudstack-cloudmonkey]

vishesh92 opened a new pull request, #220:
URL: https://github.com/apache/cloudstack-cloudmonkey/pull/220

   (no comment)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add support to pass env vars to in addition to args to configure cmk [cloudstack-cloudmonkey]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #220:
URL: https://github.com/apache/cloudstack-cloudmonkey/pull/220#issuecomment-5490852503

   <!-- cmk-build-artifact-comment -->
   ✅ Build complete for PR #220.
   
   📦 Binary artifacts are available in the [workflow run](https://github.com/apache/cloudstack-cloudmonkey/actions/runs/33484881263) (expires on September 11, 2026).
   
   > **Note:** Download artifacts by clicking on the workflow run link above, then scroll to the "Artifacts" section.
   > _Artifacts from PR builds are for testing only and may contain unreviewed, malicious code._


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add support to pass env vars to in addition to args to configure cmk [cloudstack-cloudmonkey]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #220:
URL: https://github.com/apache/cloudstack-cloudmonkey/pull/220#discussion_r3924130522


##########
cmk.go:
##########
@@ -48,11 +49,36 @@ func main() {
 	profile := flag.String("p", "", "server profile")
 	configFilePath := flag.String("c", "", "config file path")
 	acsURL := flag.String("u", config.DefaultACSAPIEndpoint, "cloudStack's API endpoint URL")
-	apiKey := flag.String("k", "", "cloudStack user's API Key")
-	secretKey := flag.String("s", "", "cloudStack user's secret Key")
+	apiKey := flag.String("k", "", "cloudStack user's API key")
+	secretKey := flag.String("s", "", "cloudStack user's secret key")
 	flag.Parse()
 	args := flag.Args()
 
+	// Fall back to environment variables for flags not passed on the
+	// command line; CLI flags take precedence over environment variables.
+	passedFlags := make(map[string]bool)
+	flag.Visit(func(f *flag.Flag) {
+		passedFlags[f.Name] = true
+	})
+	fallbackToEnvVar := func(flagName string, flagValue *string, envVar string) {
+		if !passedFlags[flagName] {
+			if value := os.Getenv(envVar); value != "" {
+				*flagValue = value
+			}
+		}
+	}
+	fallbackToEnvVar("c", configFilePath, config.ConfigFileEnvVar)
+	fallbackToEnvVar("p", profile, config.ProfileEnvVar)
+	fallbackToEnvVar("u", acsURL, config.URLEnvVar)
+	fallbackToEnvVar("k", apiKey, config.APIKeyEnvVar)
+	fallbackToEnvVar("s", secretKey, config.SecretKeyEnvVar)
+	fallbackToEnvVar("o", outputFormat, config.OutputEnvVar)
+	if !passedFlags["d"] {
+		if value, err := strconv.ParseBool(strings.TrimSpace(os.Getenv(config.DebugEnvVar))); err == nil {
+			*debug = value
+		}
+	}
+
 	cfg := config.NewConfig(configFilePath)
 

Review Comment:
   `-u`/`CMK_URL` won't override the config file when the explicit value equals `config.DefaultACSAPIEndpoint` because the update is currently gated by `*acsURL != config.DefaultACSAPIEndpoint`. This means an explicitly provided URL (flag or env) can be silently ignored whenever it matches the default endpoint, which breaks the documented precedence over the config file.



##########
cmd/command.go:
##########
@@ -65,13 +65,15 @@ CloudMonkey (cmk) 🐵 is a command line interface for Apache CloudStack.
 Allowed flags:
   -h        Show this help message or API doc when specified after an API
   -v        Print version
-  -o        API response output format: json, text, table, column, csv
-  -p        Server profile
-  -d        Enable debug mode
-  -c        Different config file path
-  -u	    CloudStack's API endpoint URL
-  -s	    CloudStack user's secret Key
-  -k	    CloudStack user's API Key
+  -o        API response output format: json, text, table, column, csv (env: CMK_OUTPUT)

Review Comment:
   The help text for `-o` omits the `default` output format, but `config.GetOutputFormats()` (used for validation) includes it. This makes `cmk -h` misleading.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add support to pass env vars to in addition to args to configure cmk [cloudstack-cloudmonkey]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #220:
URL: https://github.com/apache/cloudstack-cloudmonkey/pull/220#discussion_r3902138746


##########
cmk.go:
##########
@@ -53,6 +53,34 @@ func main() {
 	flag.Parse()
 	args := flag.Args()
 
+	// Fall back to environment variables for flags not passed on the
+	// command line; CLI flags take precedence over environment variables.
+	if *configFilePath == "" {
+		*configFilePath = os.Getenv(config.ConfigFileEnvVar)
+	}
+	if *profile == "" {
+		*profile = os.Getenv(config.ProfileEnvVar)
+	}
+	if *acsURL == config.DefaultACSAPIEndpoint {
+		if value := os.Getenv(config.URLEnvVar); value != "" {
+			*acsURL = value
+		}
+	}
+	if *apiKey == "" {
+		*apiKey = os.Getenv(config.APIKeyEnvVar)
+	}
+	if *secretKey == "" {
+		*secretKey = os.Getenv(config.SecretKeyEnvVar)
+	}
+	if *outputFormat == "" {
+		*outputFormat = os.Getenv(config.OutputEnvVar)
+	}

Review Comment:
   This env-var fallback only applies when `*outputFormat` is empty. If the `-o` flag is defined with a non-empty default (common for output formats), `CMK_OUTPUT` will never take effect even when the user does not pass `-o`. Prefer tracking whether `-o` was explicitly set (e.g., via `flag.CommandLine.Visit(...)`) and only skipping the env fallback when the flag was actually provided.



##########
README.md:
##########
@@ -79,6 +79,27 @@ If cloudmonkey is being upgraded from a version lower than v6.0.0, it must be no
 that the cloudmonkey configuration path is changed from `~/.cloudmonkey/config` to 
 `~/.cmk/config` and a default `localcloud` profile is created. One must first set up basic configurations such as apikey/secretkey/username/password/url for the required profile(s) as required
 
+### Environment Variables
+
+`cmk` supports environment variables that mirror its CLI flags. CLI flags take
+precedence over environment variables, which take precedence over values in the
+config file.
+
+| Environment variable | Flag | Description |
+|----------------------|------|-------------|
+| `CMK_CONFIG` | `-c` | Config file path |
+| `CMK_PROFILE` | `-p` | Server profile |
+| `CMK_URL` | `-u` | CloudStack's API endpoint URL |
+| `CMK_API_KEY` | `-k` | CloudStack user's API key |
+| `CMK_SECRET_KEY` | `-s` | CloudStack user's secret key |
+| `CMK_OUTPUT` | `-o` | API response output format |
+| `CMK_DEBUG` | `-d` | Enable debug mode when set to `true` or `1` |

Review Comment:
   The markdown table is incorrectly formatted with double leading pipes (`||`), which will render poorly/incorrectly in many markdown renderers. Use single leading pipes (`|`) for the header, separator, and rows.



##########
cmk.go:
##########
@@ -53,6 +53,34 @@ func main() {
 	flag.Parse()
 	args := flag.Args()
 
+	// Fall back to environment variables for flags not passed on the
+	// command line; CLI flags take precedence over environment variables.
+	if *configFilePath == "" {
+		*configFilePath = os.Getenv(config.ConfigFileEnvVar)
+	}
+	if *profile == "" {
+		*profile = os.Getenv(config.ProfileEnvVar)
+	}
+	if *acsURL == config.DefaultACSAPIEndpoint {
+		if value := os.Getenv(config.URLEnvVar); value != "" {
+			*acsURL = value
+		}
+	}
+	if *apiKey == "" {
+		*apiKey = os.Getenv(config.APIKeyEnvVar)
+	}
+	if *secretKey == "" {
+		*secretKey = os.Getenv(config.SecretKeyEnvVar)
+	}
+	if *outputFormat == "" {
+		*outputFormat = os.Getenv(config.OutputEnvVar)
+	}
+	if !*debug {
+		if value := os.Getenv(config.DebugEnvVar); value == "true" || value == "1" {
+			*debug = true
+		}
+	}

Review Comment:
   Parsing `CMK_DEBUG` via exact string checks is brittle (e.g., `TRUE`, `True`, or surrounding whitespace won’t work). Consider using `strconv.ParseBool(strings.TrimSpace(value))` and treating a successful parse of `true` as enabling debug, while still keeping CLI flags as the priority.



##########
cmd/command.go:
##########
@@ -65,13 +65,15 @@ CloudMonkey (cmk) 🐵 is a command line interface for Apache CloudStack.
 Allowed flags:
   -h        Show this help message or API doc when specified after an API
   -v        Print version
-  -o        API response output format: json, text, table, column, csv
-  -p        Server profile
-  -d        Enable debug mode
-  -c        Different config file path
-  -u	    CloudStack's API endpoint URL
-  -s	    CloudStack user's secret Key
-  -k	    CloudStack user's API Key
+  -o        API response output format: json, text, table, column, csv (env: CMK_OUTPUT)
+  -p        Server profile (env: CMK_PROFILE)
+  -d        Enable debug mode (env: CMK_DEBUG)
+  -c        Different config file path (env: CMK_CONFIG)
+  -u	    CloudStack's API endpoint URL (env: CMK_URL)
+  -s	    CloudStack user's secret Key (env: CMK_SECRET_KEY)
+  -k	    CloudStack user's API Key (env: CMK_API_KEY)

Review Comment:
   These help-text lines contain tab characters between the flag and description, which can render inconsistently across terminals and fonts. Prefer spaces to keep alignment consistent with the surrounding help text.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add support to pass env vars to in addition to args to configure cmk [cloudstack-cloudmonkey]

Posted by "borisstoyanov (via GitHub)" <gi...@apache.org>.
borisstoyanov merged PR #220:
URL: https://github.com/apache/cloudstack-cloudmonkey/pull/220


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add support to pass env vars to in addition to args to configure cmk [cloudstack-cloudmonkey]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #220:
URL: https://github.com/apache/cloudstack-cloudmonkey/pull/220#discussion_r3902865221


##########
README.md:
##########
@@ -79,6 +79,27 @@ If cloudmonkey is being upgraded from a version lower than v6.0.0, it must be no
 that the cloudmonkey configuration path is changed from `~/.cloudmonkey/config` to 
 `~/.cmk/config` and a default `localcloud` profile is created. One must first set up basic configurations such as apikey/secretkey/username/password/url for the required profile(s) as required
 
+### Environment Variables
+
+`cmk` supports environment variables that mirror its CLI flags. CLI flags take
+precedence over environment variables, which take precedence over values in the
+config file.
+
+| Environment variable | Flag | Description |
+|----------------------|------|-------------|
+| `CMK_CONFIG` | `-c` | Config file path |
+| `CMK_PROFILE` | `-p` | Server profile |
+| `CMK_URL` | `-u` | CloudStack's API endpoint URL |
+| `CMK_API_KEY` | `-k` | CloudStack user's API key |
+| `CMK_SECRET_KEY` | `-s` | CloudStack user's secret key |
+| `CMK_OUTPUT` | `-o` | API response output format |
+| `CMK_DEBUG` | `-d` | Enable debug mode when set to a boolean true value (e.g. `true` or `1`) |

Review Comment:
   The markdown table syntax is incorrect: each row starts with `||` instead of `|`, which will render poorly in most Markdown renderers. Change the header/separator/rows to use single leading/trailing pipes (e.g., `| Environment variable | Flag | Description |`).



##########
cmk.go:
##########
@@ -53,6 +54,34 @@ func main() {
 	flag.Parse()
 	args := flag.Args()
 
+	// Fall back to environment variables for flags not passed on the
+	// command line; CLI flags take precedence over environment variables.
+	if *configFilePath == "" {
+		*configFilePath = os.Getenv(config.ConfigFileEnvVar)
+	}
+	if *profile == "" {
+		*profile = os.Getenv(config.ProfileEnvVar)
+	}
+	if *acsURL == config.DefaultACSAPIEndpoint {
+		if value := os.Getenv(config.URLEnvVar); value != "" {
+			*acsURL = value
+		}
+	}
+	if *apiKey == "" {
+		*apiKey = os.Getenv(config.APIKeyEnvVar)
+	}
+	if *secretKey == "" {
+		*secretKey = os.Getenv(config.SecretKeyEnvVar)
+	}
+	if *outputFormat == "" {
+		*outputFormat = os.Getenv(config.OutputEnvVar)
+	}
+	if !*debug {
+		if value, err := strconv.ParseBool(strings.TrimSpace(os.Getenv(config.DebugEnvVar))); err == nil && value {
+			*debug = true
+		}
+	}

Review Comment:
   This precedence logic can incorrectly let env vars override an explicitly-provided flag when the flag value equals the default. For example, `-u http://localhost:8080/client/api` (explicit) still satisfies `*acsURL == DefaultACSAPIEndpoint`, so `CMK_URL` would override it. Similarly, `-d=false` is explicitly set but `CMK_DEBUG=true` would flip it back on. To preserve “flags take precedence”, track whether each flag was explicitly set (e.g., via a custom `flag.Value` that records `Set` calls, or by scanning `os.Args` for the relevant flag tokens) and only apply env fallbacks when the flag was not set.



##########
cmk.go:
##########
@@ -53,6 +54,34 @@ func main() {
 	flag.Parse()
 	args := flag.Args()
 
+	// Fall back to environment variables for flags not passed on the
+	// command line; CLI flags take precedence over environment variables.
+	if *configFilePath == "" {
+		*configFilePath = os.Getenv(config.ConfigFileEnvVar)
+	}
+	if *profile == "" {
+		*profile = os.Getenv(config.ProfileEnvVar)
+	}
+	if *acsURL == config.DefaultACSAPIEndpoint {
+		if value := os.Getenv(config.URLEnvVar); value != "" {
+			*acsURL = value
+		}
+	}
+	if *apiKey == "" {
+		*apiKey = os.Getenv(config.APIKeyEnvVar)
+	}
+	if *secretKey == "" {
+		*secretKey = os.Getenv(config.SecretKeyEnvVar)
+	}
+	if *outputFormat == "" {
+		*outputFormat = os.Getenv(config.OutputEnvVar)
+	}
+	if !*debug {

Review Comment:
   This precedence logic can incorrectly let env vars override an explicitly-provided flag when the flag value equals the default. For example, `-u http://localhost:8080/client/api` (explicit) still satisfies `*acsURL == DefaultACSAPIEndpoint`, so `CMK_URL` would override it. Similarly, `-d=false` is explicitly set but `CMK_DEBUG=true` would flip it back on. To preserve “flags take precedence”, track whether each flag was explicitly set (e.g., via a custom `flag.Value` that records `Set` calls, or by scanning `os.Args` for the relevant flag tokens) and only apply env fallbacks when the flag was not set.



##########
cmd/command.go:
##########
@@ -65,13 +65,15 @@ CloudMonkey (cmk) 🐵 is a command line interface for Apache CloudStack.
 Allowed flags:
   -h        Show this help message or API doc when specified after an API
   -v        Print version
-  -o        API response output format: json, text, table, column, csv
-  -p        Server profile
-  -d        Enable debug mode
-  -c        Different config file path
-  -u	    CloudStack's API endpoint URL
-  -s	    CloudStack user's secret Key
-  -k	    CloudStack user's API Key
+  -o        API response output format: json, text, table, column, csv (env: CMK_OUTPUT)
+  -p        Server profile (env: CMK_PROFILE)
+  -d        Enable debug mode (env: CMK_DEBUG)
+  -c        Different config file path (env: CMK_CONFIG)
+  -u        CloudStack's API endpoint URL (env: CMK_URL)
+  -s        CloudStack user's secret Key (env: CMK_SECRET_KEY)
+  -k        CloudStack user's API Key (env: CMK_API_KEY)

Review Comment:
   Use consistent capitalization: change “secret Key” → “secret key” and “API Key” → “API key” to match typical wording and the README.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org