mirror of
https://github.com/floci-io/floci-cli.git
synced 2026-11-23 14:10:50 -05:00
fix(env): single-quote exported values in every product tree (#19)
`floci az env` printed the semicolon-separated Azure connection string unquoted, so `eval $(floci az env)` set only AZURE_STORAGE_CONNECTION_STRING=DefaultEndpointsProtocol=http and ran the remaining segments as commands — `az` then reported "Invalid connection string". `floci env` and `floci gcp env` carried a byte-identical copy of the same unquoted emitter (their values are `;`-free URLs today, so nobody hit it), and the aws.cli.endpoint / az.cli.connection-string doctor checks suggested export lines with the same flaw. Extract the correct emitter that `floci oci env` already had into io.floci.cli.output.ShellExport and use it everywhere: values are single quoted with per-shell escaping for bash, fish, and PowerShell, so `;`, `$`, backticks, and quotes can neither break nor inject through `eval`. OciEnvFormatTest becomes ShellExportTest, keeping its four assertions and adding the connection-string regression from the issue. Closes #18
This commit is contained in:
1 parent
fee32a76a1
commit
6496795708
11 files changed
+99
-91
No files matched your search
@@ -7,6 +7,7 @@ import io.floci.cli.doctor.checks.AzCliConnectionStringCheck;
|
||||
import io.floci.cli.output.Ansi;
|
||||
import io.floci.cli.output.OutputFormat;
|
||||
import io.floci.cli.output.Printer;
|
||||
import io.floci.cli.output.ShellExport;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
import java.net.URI;
|
||||
@@ -90,14 +91,14 @@ public class AzEnvCommand implements Callable<Integer> {
|
||||
|
||||
if (!sdkVarsMode) {
|
||||
String connStr = AzCliConnectionStringCheck.buildConnectionString(account, host, port);
|
||||
printer.println(formatExport("AZURE_STORAGE_CONNECTION_STRING", connStr));
|
||||
printer.println(ShellExport.formatExport(shell, "AZURE_STORAGE_CONNECTION_STRING", connStr));
|
||||
printer.println("");
|
||||
printer.println(Ansi.gray("# Run: eval $(floci az env)"));
|
||||
} else {
|
||||
printer.println(formatExport("AZURE_STORAGE_ACCOUNT", account));
|
||||
printer.println(formatExport("AZURE_STORAGE_KEY", DEV_KEY));
|
||||
printer.println(ShellExport.formatExport(shell, "AZURE_STORAGE_ACCOUNT", account));
|
||||
printer.println(ShellExport.formatExport(shell, "AZURE_STORAGE_KEY", DEV_KEY));
|
||||
for (String svc : requestedServices) {
|
||||
printer.println(formatExport(envVarName(svc), buildEndpointUrl(svc, host, port, account)));
|
||||
printer.println(ShellExport.formatExport(shell, envVarName(svc), buildEndpointUrl(svc, host, port, account)));
|
||||
}
|
||||
printer.println("");
|
||||
printer.println(Ansi.gray("# Run: eval $(floci az env --format sdk-vars)"));
|
||||
@@ -143,14 +144,6 @@ public class AzEnvCommand implements Callable<Integer> {
|
||||
};
|
||||
}
|
||||
|
||||
private String formatExport(String key, String value) {
|
||||
return switch (shell.toLowerCase()) {
|
||||
case "fish" -> "set -x " + key + " \"" + value + "\"";
|
||||
case "powershell", "ps1" -> "$env:" + key + " = \"" + value + "\"";
|
||||
default -> "export " + key + "=" + value;
|
||||
};
|
||||
}
|
||||
|
||||
private int extractPort(String endpoint) {
|
||||
try {
|
||||
int p = URI.create(endpoint).getPort();
|
||||
|
||||
Reference in new issue
Block a user