hashicorp / hc-install

Go module for downloading or locating HashiCorp binaries, verifying signatures and checksums, and asserting version constraints.

Home Page:https://pkg.go.dev/github.com/hashicorp/hc-install

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Install failure with content-type mismatch

ryanwholey opened this issue · comments

We are receiving unexpected Content-Type: "application/vnd+hashicorp.releases-api.v0+json when trying to download Terraform.

Here is a small reproduction example:

go 1.18

require (
	github.com/hashicorp/go-version v1.3.0
	github.com/hashicorp/hc-install v0.3.1
)
// main.go
package main

import (
	"context"
	"log"

	"github.com/hashicorp/go-version"
	install "github.com/hashicorp/hc-install"
	"github.com/hashicorp/hc-install/product"
	"github.com/hashicorp/hc-install/releases"
	"github.com/hashicorp/hc-install/src"
)

func main() {
	v, err := version.NewVersion("1.1.9")
	if err != nil {
		log.Fatal(err)
	}

	installer := install.NewInstaller()

	_, err = installer.Ensure(context.Background(), []src.Source{
		&releases.ExactVersion{
			Product: product.Terraform,
			Version: v,
		},
	})
	if err != nil {
		log.Fatal(err)
	}
}
go run .
2022/05/09 15:10:43 unexpected Content-Type: "application/vnd+hashicorp.releases-api.v0+json"

This can be traced back to

contentType := resp.Header.Get("content-type")
if contentType != "application/json" {
return nil, fmt.Errorf("unexpected Content-Type: %q", contentType)
}

Perhaps the registry API now returns application/vnd+hashicorp.releases-api.v0+json instead of application/json? As a fix, would you be open to getting rid of checking the response header all together? Alternatively we could check both, but since we are handling JSON marshalling errors below, seems like maybe we can just dump this check all together.

Hi @ryanwholey
Thanks for the report. This is indeed related to some recent changes made to the Release API. We're looking into patching the library and cutting a release 🔜

@radeksimko thank you, much appreciated!

#57 merged and released as part of v0.3.2.

I have also notified the team maintaining https://github.com/hashicorp/terraform-plugin-sdk internally - which is used by most of hc-install downstream consumers, so that Terraform providers can also resume testing 🔜