(maint) Merge up 3.11.x to 3.13.x
* upstream/3.11.x:
(packaging) Updating the FACTER.pot file
travis
(FACT-2054) Facter::Core::Execution.execute expands shell builtins
(maint) Bump leatherman to 1.4.9 in appveyor
(maint) bump leatherman to 1.4.9 in travis
Conflicts:
.travis.yml
appveyor.yml
Gabriel Nagy
4 years ago
137 | 137 |
|
138 | 138 |
// Helper functions
|
139 | 139 |
static module* from_self(leatherman::ruby::VALUE self);
|
140 | |
static leatherman::ruby::VALUE execute_command(std::string const& command, leatherman::ruby::VALUE failure_default, bool raise, uint32_t timeout = 0);
|
|
140 |
static leatherman::ruby::VALUE execute_command(std::string const& command, leatherman::ruby::VALUE failure_default, bool raise, uint32_t timeout = 0, bool expand = true);
|
141 | 141 |
|
142 | 142 |
void initialize_search_paths(std::vector<std::string> const& paths);
|
143 | 143 |
leatherman::ruby::VALUE load_fact(leatherman::ruby::VALUE value);
|
17 | 17 |
*/
|
18 | 18 |
inline std::string which(const std::string& exe) {
|
19 | 19 |
#ifdef FACTER_PATH
|
20 | |
std::string fixed = leatherman::execution::which(exe, {FACTER_PATH});
|
|
20 |
std::string fixed = leatherman::execution::which(exe, {FACTER_PATH}, true);
|
|
21 |
if (!fixed.empty()) {
|
|
22 |
return fixed;
|
|
23 |
}
|
|
24 |
LOG_WARNING("{1} not found at configured location {2}, using PATH instead", exe, FACTER_PATH);
|
|
25 |
#endif
|
|
26 |
return exe;
|
|
27 |
}
|
|
28 |
|
|
29 |
inline std::string which(const std::string& exe, bool expand) {
|
|
30 |
#ifdef FACTER_PATH
|
|
31 |
std::string fixed = leatherman::execution::which(exe, {FACTER_PATH}, expand);
|
21 | 32 |
if (!fixed.empty()) {
|
22 | 33 |
return fixed;
|
23 | 34 |
}
|
24 | |
LOG_WARNING("{1} not found at configured location {2}, using PATH instead", exe, FACTER_PATH);
|
|
35 |
LOG_WARNING("{1} not found at configured location {2}, using PATH instead, parameter expand is {3}", exe, FACTER_PATH, expand);
|
25 | 36 |
#endif
|
26 | 37 |
return exe;
|
27 | 38 |
}
|
882 | 882 |
raise = true;
|
883 | 883 |
fail_option = ruby.nil_value();
|
884 | 884 |
}
|
885 | |
return execute_command(ruby.to_string(argv[0]), fail_option, raise, timeout);
|
|
885 |
|
|
886 |
bool expand = true;
|
|
887 |
volatile VALUE expand_option = ruby.rb_hash_lookup2(argv[1], ruby.to_symbol("expand"), ruby.true_value());
|
|
888 |
if (ruby.is_false(expand_option)) {
|
|
889 |
expand = false;
|
|
890 |
}
|
|
891 |
|
|
892 |
return execute_command(ruby.to_string(argv[0]), fail_option, raise, timeout, expand);
|
886 | 893 |
});
|
887 | 894 |
}
|
888 | 895 |
|
|
907 | 914 |
return it->second;
|
908 | 915 |
}
|
909 | 916 |
|
910 | |
VALUE module::execute_command(std::string const& command, VALUE failure_default, bool raise, uint32_t timeout)
|
911 | |
{
|
912 | |
auto const& ruby = api::instance();
|
913 | |
|
914 | |
// Expand the command
|
915 | |
auto expanded = expand_command(command);
|
|
917 |
VALUE module::execute_command(std::string const& command, VALUE failure_default, bool raise, uint32_t timeout, bool expand)
|
|
918 |
{
|
|
919 |
auto const& ruby = api::instance();
|
|
920 |
|
|
921 |
// Expand the command only if expand is true,
|
|
922 |
auto expanded = expand_command(command, leatherman::util::environment::search_paths(), expand);
|
916 | 923 |
|
917 | 924 |
if (!expanded.empty()) {
|
918 | 925 |
try {
|
|
0 |
Facter.add(:foo) do
|
|
1 |
setcode do
|
|
2 |
Facter::Core::Execution.execute("cd /opt/puppetlabs && ls", {:expand => false})
|
|
3 |
end
|
|
4 |
end
|
|
0 |
Facter.add(:zoo) do
|
|
1 |
setcode do
|
|
2 |
Facter::Core::Execution.execute("cd /opt/puppetlabs && ls", {:expand => true})
|
|
3 |
end
|
|
4 |
end
|
496 | 496 |
REQUIRE(re_search(output, boost::regex("ERROR puppetlabs\\.facter - .* command timed out after 1 seconds")));
|
497 | 497 |
}
|
498 | 498 |
}
|
|
499 |
GIVEN("a fact resolution that uses Facter::Core::Execution#execute with expand value set to true") {
|
|
500 |
log_capture capture(level::debug);
|
|
501 |
REQUIRE(load_custom_fact("execute_expand_true.rb", facts));
|
|
502 |
THEN("first command should be expanded to absolute path") {
|
|
503 |
auto output = capture.result();
|
|
504 |
CAPTURE(output);
|
|
505 |
REQUIRE(re_search(output, boost::regex("cd /opt/puppetlabs && ls")));
|
|
506 |
}
|
|
507 |
}
|
|
508 |
GIVEN("a fact resolution that uses Facter::Core::Execution#execute with expand value set to false") {
|
|
509 |
log_capture capture(level::debug);
|
|
510 |
REQUIRE(load_custom_fact("execute_expand_false.rb", facts));
|
|
511 |
THEN("first command should not be expanded to absolute path") {
|
|
512 |
auto output = capture.result();
|
|
513 |
CAPTURE(output);
|
|
514 |
REQUIRE(ruby_value_to_string(facts.get<ruby_value>("foo")) != "\"\"");
|
|
515 |
REQUIRE(re_search(output, boost::regex("bin/sh -c cd /opt/puppetlabs && ls")));
|
|
516 |
}
|
|
517 |
}
|
499 | 518 |
GIVEN("a fact that uses timeout") {
|
500 | 519 |
log_capture capture(level::warning);
|
501 | 520 |
REQUIRE(load_custom_fact("timeout.rb", facts));
|
233 | 233 |
msgid "{1} not found at configured location {2}, using PATH instead"
|
234 | 234 |
msgstr ""
|
235 | 235 |
|
|
236 |
#. warning
|
|
237 |
#: lib/inc/internal/util/agent.hpp
|
|
238 |
msgid ""
|
|
239 |
"{1} not found at configured location {2}, using PATH instead, parameter "
|
|
240 |
"expand is {3}"
|
|
241 |
msgstr ""
|
|
242 |
|
236 | 243 |
#: lib/inc/internal/util/aix/odm.hpp
|
237 | 244 |
msgid "failed to retrieve ODM error message"
|
238 | 245 |
msgstr ""
|