Skip to content

Commit

Permalink
Fixes #13745: change the detection of curl path in ncf to use rudder_…
Browse files Browse the repository at this point in the history
…curl if available
  • Loading branch information
ncharles committed Oct 30, 2018
1 parent 2f5c57f commit 24f5891
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 17 deletions.
14 changes: 14 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,20 @@ bundle common ncf_const {
"s" string => " ";
}


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

"ncf_curl" string => "${paths.path[curl]}",
unless => isvariable("g.rudder_curl");

classes:
"_ncf_path_ncf_curl_exists" expression => fileexists("${ncf_curl}");
}

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_ncf_curl_exists::
"action_command" string => "${ncf_path.ncf_curl} -s -L -o ${destination} ${source}";


!_stdlib_path_exists_curl._stdlib_path_exists_wget::
!_ncf_path_ncf_curl_exists._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_ncf_curl_exists|_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_ncf_curl_exists|_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_ncf_curl_exists.!_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_ncf_curl_exists::
"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_path.ncf_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_ncf_curl_exists::
"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_path.ncf_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_ncf_curl_exists|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_ncf_curl_exists::
"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_ncf_curl_exists.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_ncf_curl_exists::
"/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_ncf_curl_exists.pass2::
"code=`${ncf_path.ncf_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_path.ncf_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

0 comments on commit 24f5891

Please sign in to comment.