Skip to content

Commit db8deaf

Browse files
authored
config sub-command output hides secrets (#4223)
1 parent 96fee09 commit db8deaf

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

libmamba/include/mamba/api/configuration.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#define MAMBA_API_CONFIGURATION_HPP
99

1010
#include <functional>
11+
#include <string>
12+
#include <vector>
1113

1214
#include <yaml-cpp/yaml.h>
1315

@@ -961,6 +963,13 @@ namespace mamba
961963
}
962964

963965
void use_conda_root_prefix(Configuration& config, bool force = false);
966+
967+
void print_dump(
968+
const Configuration& config,
969+
int dump_opts = MAMBA_SHOW_CONFIG_VALUES,
970+
std::vector<std::string> dump_names = {}
971+
);
972+
964973
}
965974

966975
#endif // MAMBA_CONFIG_HPP

libmamba/src/api/config.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace mamba
3131
auto specs = config.at("specs").value<std::vector<std::string>>();
3232
int dump_opts = MAMBA_SHOW_CONFIG_DESCS | show_long_desc | show_group;
3333

34-
std::cout << config.dump(dump_opts, specs) << std::endl;
34+
print_dump(config, dump_opts, specs);
3535

3636
config.operation_teardown();
3737
}
@@ -64,7 +64,7 @@ namespace mamba
6464
int dump_opts = MAMBA_SHOW_CONFIG_VALUES | show_sources | show_desc | show_long_desc
6565
| show_group | show_all_rcs | show_all;
6666

67-
std::cout << config.dump(dump_opts, specs) << std::endl;
67+
print_dump(config, dump_opts, specs);
6868

6969
config.operation_teardown();
7070
}

libmamba/src/api/configuration.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2288,7 +2288,7 @@ namespace mamba
22882288
{
22892289
int dump_opts = MAMBA_SHOW_CONFIG_VALUES | MAMBA_SHOW_CONFIG_SRCS
22902290
| MAMBA_SHOW_ALL_CONFIGS;
2291-
std::cout << this->dump(dump_opts) << std::endl;
2291+
print_dump(*this, dump_opts);
22922292
exit(0);
22932293
}
22942294

@@ -2771,4 +2771,12 @@ namespace mamba
27712771
return dump_yaml(opts, names, get_grouped_config());
27722772
}
27732773
}
2774+
2775+
void print_dump(const Configuration& config, int dump_opts, std::vector<std::string> dump_names)
2776+
{
2777+
// Note: this function is intended to get more complex with incoming changes and need to be
2778+
// isolated in preparation for these changes.
2779+
const std::string dump_text = hide_secrets(config.dump(dump_opts, std::move(dump_names)));
2780+
std::cout << dump_text << std::endl;
2781+
}
27742782
}

micromamba/tests/test_config.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -816,11 +816,8 @@ def test_envsubst_windows_problem(self, monkeypatch, rc_file):
816816
monkeypatch.setenv("CONDA_CHANNEL_UPLOAD_USER", "uuuuuuuuu", True)
817817
monkeypatch.setenv("CONDA_CHANNEL_UPLOAD_PASSWORD", "pppppppppppppppppppp", True)
818818
out = self._roundtrip(rc_file, condarc)
819+
# Note that the password is a secret and will be hidden in the output
820+
assert out["channel_alias"] == "https://xxxxxxxxxxxxxxxxxxxx.com/t/*****/get"
819821
assert (
820-
out["channel_alias"]
821-
== "https://xxxxxxxxxxxxxxxxxxxx.com/t/kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk/get"
822-
)
823-
assert (
824-
out["custom_channels"]["yyyyyyyyyyyy"]
825-
== "https://uuuuuuuuu:pppppppppppppppppppp@xxxxxxxxxxxxxxx.com"
822+
out["custom_channels"]["yyyyyyyyyyyy"] == "https://uuuuuuuuu:*****@xxxxxxxxxxxxxxx.com"
826823
)

0 commit comments

Comments
 (0)