Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #13745: change the detection of curl path in ncf to use rudder_curl if available #862

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tree/20_cfe_basics/ncf_lib.cf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,27 @@ bundle common ncf_const {
"s" string => " ";
}


# Use rudder_curl variable if available, rather than the path[curl]
bundle common ncf_paths {
vars:
"path[curl]" string => "${g.rudder_curl}",
if => isvariable("g.rudder_curl");

"path[curl]" string => "${paths.path[curl]}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great!

unless => isvariable("g.rudder_curl");


"all_paths" slist => getindices("path");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

"$(all_paths)" string => "$(path[$(all_paths)])";

classes:
"_ncf_path_exists_$(all_paths)"
expression => fileexists("$(path[$(all_paths)])"),
comment => "It's useful to know if $(all_paths) exists on the filesystem as defined";

}

body package_method yum_rpm_no_version
{
package_changes => "bulk";
Expand Down
12 changes: 6 additions & 6 deletions tree/30_generic_methods/file_from_http_server.cf
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ bundle agent file_from_http_server(source, destination)
vars:


_stdlib_path_exists_curl::
"action_command" string => "${paths.path[curl]} -s -L -o ${destination} ${source}";
_ncf_path_exists_curl::
"action_command" string => "${ncf_paths.path[curl]} -s -L -o ${destination} ${source}";


!_stdlib_path_exists_curl._stdlib_path_exists_wget::
!_ncf_path_exists_curl._stdlib_path_exists_wget::
"action_command" string => "${paths.path[wget]} -O ${destination} ${source}";


Expand All @@ -65,14 +65,14 @@ bundle agent file_from_http_server(source, destination)
usebundle => disable_reporting;


(_stdlib_path_exists_curl|_stdlib_path_exists_wget).!file_exists::
(_ncf_path_exists_curl|_stdlib_path_exists_wget).!file_exists::
"action" usebundle => command_execution("${action_command}");

any::
"reenable_reporting_${class_prefix}"
usebundle => enable_reporting,
ifvarclass => "should_report";
(_stdlib_path_exists_curl|_stdlib_path_exists_wget).!file_exists::
(_ncf_path_exists_curl|_stdlib_path_exists_wget).!file_exists::
"class copy" usebundle => _classes_copy("command_execution_${canonified_action_command}", "${old_class_prefix}");

"new result classes"
Expand All @@ -82,7 +82,7 @@ bundle agent file_from_http_server(source, destination)
ifvarclass => "${class_prefix}_reached";


!_stdlib_path_exists_curl.!_stdlib_path_exists_wget.!file_exists::
!_ncf_path_exists_curl.!_stdlib_path_exists_wget.!file_exists::
"force_failure_class" usebundle => _classes_failure("${old_class_prefix}");
"new result classes" usebundle => _classes_failure("${class_prefix}");
"report" usebundle => _log_v3("Unable to download ${source}: neither wget or curl are installed", "${destination}", "${old_class_prefix}", "${class_prefix}", @{args});
Expand Down
4 changes: 2 additions & 2 deletions tree/30_generic_methods/http_request_check_status_headers.cf
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ bundle agent http_request_check_status_headers(method, url, expected_status, hea
pass2::
"report" usebundle => _log_v3("Performing a HTTP ${method} request on ${url}, expecting status ${expected_status}", "${url}", "${old_class_prefix}", "${class_prefix}", @{args});

!_stdlib_path_exists_curl::
!_ncf_path_exists_curl::
"force_failure_class_old" usebundle => _classes_failure("${old_class_prefix}");
"force_failure_class" usebundle => _classes_failure("${class_prefix}");
"report" usebundle => _log_v3("Unable to perform a HTTP ${method} on ${url}: curl is not installed", "${url}", "${old_class_prefix}", "${class_prefix}", @{args});

commands:
"${paths.path[curl]}"
"${ncf_paths.path[curl]}"
args => "-I -L -s -o /dev/null -w \"%{http_code}\" ${url} -X ${method} -H '${headers}' | /bin/grep -q ${expected_status}",
contain => in_shell,
# We don't define repaired class, as we only query and expect, so using 999 to avoid using this feature
Expand Down
4 changes: 2 additions & 2 deletions tree/30_generic_methods/http_request_content_headers.cf
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ bundle agent http_request_content_headers(method, url, content, headers)
pass2::
"report" usebundle => _log_v3("Performing a HTTP ${method} request on ${url} with specific content", "${url}", "${old_class_prefix}", "${class_prefix}", @{args});

!_stdlib_path_exists_curl::
!_ncf_path_exists_curl::
"force_failure_class old" usebundle => _classes_failure("${old_class_prefix}");
"force_failure_class" usebundle => _classes_failure("${class_prefix}");
"report" usebundle => _log_v3("Unable to perform a HTTP ${method} on ${url}: curl is not installed", "${url}", "${old_class_prefix}", "${class_prefix}", @{args});

commands:
"/bin/echo \"${content}\" | ${paths.path[curl]}"
"/bin/echo \"${content}\" | ${ncf_paths.path[curl]}"
args => "${url} -L -X ${method} -H '${headers}' -o /dev/null -s -f -d @-",
contain => in_shell,
classes => classes_generic_two("${old_class_prefix}", "${class_prefix}");
Expand Down
14 changes: 7 additions & 7 deletions tree/30_generic_methods/sharedfile_to_node.cf
Original file line number Diff line number Diff line change
Expand Up @@ -136,36 +136,36 @@ bundle agent sharedfile_to_node(target_uuid, file_id, file_path, ttl)
"check_failed" expression => "${old_class_prefix}_exist_error|${class_prefix}_exist_error";

methods:
!_stdlib_path_exists_curl|check_failed|!file_exists::
!_ncf_path_exists_curl|check_failed|!file_exists::
"force_failure_class old" usebundle => _classes_failure("${old_class_prefix}");
"force_failure_class" usebundle => _classes_failure("${class_prefix}");
!_stdlib_path_exists_curl::
!_ncf_path_exists_curl::
"report" usebundle => _log_v3("Unable to perform a HTTP queries on ${url}: curl is not installed", "${file_id}", "${old_class_prefix}", "${class_prefix}", @{args});
check_failed::
"report" usebundle => _log_v3("Unable to contact HTTP server on ${url} from sharedfile_to_node", "${file_id}", "${old_class_prefix}", "${class_prefix}", @{args});
!file_exists::
"report" usebundle => _log_v3("File ${file_path} does not exist", "${file_id}", "${old_class_prefix}", "${class_prefix}", @{args});

_stdlib_path_exists_curl.file_exists.!check_failed.pass3::
_ncf_path_exists_curl.file_exists.!check_failed.pass3::
"result" usebundle => _classes_combine_ifthenelse("${old_class_prefix}_exist", "success", "${old_class_prefix}_uploaded", "${old_class_prefix}");
"result" usebundle => _classes_combine_ifthenelse("${class_prefix}_exist", "success", "${class_prefix}_uploaded", "${class_prefix}");

"report" usebundle => _log_v3("Sharing ${file_path} with ${target_uuid} under the name ${file_id} for ${ttl}", "${file_id}", "${old_class_prefix}", "${class_prefix}", @{args});

commands:
_stdlib_path_exists_curl::
_ncf_path_exists_curl::
"/opt/rudder/bin/rudder-sign"
args => "${file_path} 1.1",
classes => if_ok("${canonified_path}_signed"),
ifvarclass => "!${canonified_path}_signed";

_stdlib_path_exists_curl.pass2::
"code=`${paths.path[curl]} ${url}?hash=${hash} --insecure --tlsv1 --location --head --output /dev/null --silent --fail --write-out %{http_code}` || [ $code -eq 404 ] && exit 22 || exit 254"
_ncf_path_exists_curl.pass2::
"code=`${ncf_paths.path[curl]} ${url}?hash=${hash} --insecure --tlsv1 --location --head --output /dev/null --silent --fail --write-out %{http_code}` || [ $code -eq 404 ] && exit 22 || exit 254"
contain => in_shell,
classes => classes_generic_return_single_code_two("${old_class_prefix}_exist", "${class_prefix}_exist", "0", "22", "254"), # 254 = http 400 or above, 22 = http 404
ifvarclass => "${canonified_path}_signed";

"echo | cat ${file_path}.sign - ${file_path} | ${paths.path[curl]}"
"echo | cat ${file_path}.sign - ${file_path} | ${ncf_paths.path[curl]}"
args => "${url}?ttl=${url_ttl} --insecure --tlsv1 --location --request PUT --output /dev/null --silent --fail --header 'Content-Type: application/octet-stream' --data-binary @-",
contain => in_shell,
classes => classes_generic_return_single_code_two("${old_class_prefix}_uploaded", "${class_prefix}_uploaded", "0", "999", "22"), # 22 = http 400 or above
Expand Down