Codebase list facter / 404913c
(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
7 changed file(s) with 64 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
137137
138138 // Helper functions
139139 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);
141141
142142 void initialize_search_paths(std::vector<std::string> const& paths);
143143 leatherman::ruby::VALUE load_fact(leatherman::ruby::VALUE value);
1717 */
1818 inline std::string which(const std::string& exe) {
1919 #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);
2132 if (!fixed.empty()) {
2233 return fixed;
2334 }
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);
2536 #endif
2637 return exe;
2738 }
882882 raise = true;
883883 fail_option = ruby.nil_value();
884884 }
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);
886893 });
887894 }
888895
907914 return it->second;
908915 }
909916
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);
916923
917924 if (!expanded.empty()) {
918925 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
496496 REQUIRE(re_search(output, boost::regex("ERROR puppetlabs\\.facter - .* command timed out after 1 seconds")));
497497 }
498498 }
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 }
499518 GIVEN("a fact that uses timeout") {
500519 log_capture capture(level::warning);
501520 REQUIRE(load_custom_fact("timeout.rb", facts));
233233 msgid "{1} not found at configured location {2}, using PATH instead"
234234 msgstr ""
235235
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
236243 #: lib/inc/internal/util/aix/odm.hpp
237244 msgid "failed to retrieve ODM error message"
238245 msgstr ""