Unverified Commit ac16d739 authored by @mjones's avatar @mjones Committed by GitHub
Browse files

ovftool: fix fetching (#500608)

parents 611fb32a 39e45782
Loading
Loading
Loading
Loading
+38 −16
Original line number Diff line number Diff line
{
  autoPatchelfHook,
  c-ares,
  cacert,
  curl,
  darwin,
  expat,
@@ -17,6 +18,7 @@
  openssl,
  stdenv,
  unzip,
  writeShellScript,
  xercesc,
  zlib,
  acceptBroadcomEula ? false,
@@ -48,27 +50,47 @@ let
          ;
      };
    in
    fetchurl {
    stdenv.mkDerivation {
      name = fileName;
      url =
        (mkBaseUrl toolId)
        + "?p_p_id=SDK_AND_TOOL_DETAILS_INSTANCE_iwlk&p_p_lifecycle=2&p_p_resource_id=documentDownloadArtifact";
      curlOptsList = [
        "--json"
        requestJson
      ];
      downloadToTemp = true;
      nativeBuildInputs = [ jq ];
      postFetch = ''
        # Try again with the new URL
        urls="$(jq -r 'if (.success == true) then .data.downloadUrl else error(. | tostring) end' < "$downloadedFile" || exit $?)" \
          downloadToTemp="" \
          curlOptsList="" \
          curlOpts="" \
          postFetch="" \
          exec "$SHELL" "''${BASH_ARGV[@]}"
      builder = writeShellScript "builder.sh" ''
        curlVersion=$(${curl}/bin/curl -V | head -1 | cut -d' ' -f2)

        curl=(
          ${lib.getExe curl}
          --location
          --retry 3
          --user-agent "curl/$curlVersion Nixpkgs/${lib.trivial.release}"
          --cacert ${cacert}/etc/ssl/certs/ca-bundle.crt
          $NIX_CURL_FLAGS
        )

        "''${curl[@]}" --json ${lib.escapeShellArg requestJson} --output details.json "$url"

        echo "Details: $(<details.json)" >&2
        url="$(jq -r 'if (.success == true) then .data.downloadUrl else error(. | tostring) end' < details.json || exit 1)"

        echo "Redirect URL: $url" >&2
        if [ -n "$url" ]; then
          "''${curl[@]}" --output "$out" "$url"
        else
          echo "Couldn't get redirect URL, exiting." >&2
          exit 1
        fi
      '';
      inherit hash;
      nativeBuildInputs = [
        curl
        jq
      ];
      outputHashAlgo = "sha256";
      outputHash = hash;

      impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ [
        # This variable allows the user to pass additional options to curl
        "NIX_CURL_FLAGS"
      ];
    };

  ovftoolSystems = {