Skip to content

Commit

Permalink
fix: download conftest binary for correct arch (#4089) (#4161)
Browse files Browse the repository at this point in the history
* download conftest binary for correct arch



* remove default constant



---------

Signed-off-by: Prajith P <[email protected]>
Co-authored-by: Prajith <[email protected]>
  • Loading branch information
gcp-cherry-pick-bot[bot] and Prajithp authored Jan 21, 2024
1 parent 9235e13 commit da67e7d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
27 changes: 23 additions & 4 deletions server/core/runtime/policy/conftest_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@ import (
"github.com/runatlantis/atlantis/server/events/command"
"github.com/runatlantis/atlantis/server/events/models"
"github.com/runatlantis/atlantis/server/logging"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)

const (
DefaultConftestVersionEnvKey = "DEFAULT_CONFTEST_VERSION"
conftestBinaryName = "conftest"
conftestDownloadURLPrefix = "https://github.com/open-policy-agent/conftest/releases/download/v"
conftestArch = "x86_64"
)

type Arg struct {
Expand Down Expand Up @@ -113,8 +110,13 @@ type ConfTestVersionDownloader struct {
func (c ConfTestVersionDownloader) downloadConfTestVersion(v *version.Version, destPath string) (runtime_models.FilePath, error) {
versionURLPrefix := fmt.Sprintf("%s%s", conftestDownloadURLPrefix, v.Original())

conftestPlatform := getPlatform()
if conftestPlatform == "" {
return runtime_models.LocalFilePath(""), fmt.Errorf("don't know where to find conftest for %s on %s", runtime.GOOS, runtime.GOARCH)
}

// download binary in addition to checksum file
binURL := fmt.Sprintf("%s/conftest_%s_%s_%s.tar.gz", versionURLPrefix, v.Original(), cases.Title(language.English).String(runtime.GOOS), conftestArch)
binURL := fmt.Sprintf("%s/conftest_%s_%s.tar.gz", versionURLPrefix, v.Original(), conftestPlatform)
checksumURL := fmt.Sprintf("%s/checksums.txt", versionURLPrefix)

// underlying implementation uses go-getter so the URL is formatted as such.
Expand Down Expand Up @@ -313,3 +315,20 @@ func hasFailures(output string) bool {
}
return false
}

func getPlatform() string {
platform := runtime.GOOS + "_" + runtime.GOARCH

switch platform {
case "linux_amd64":
return "Linux_x86_64"
case "linux_arm64":
return "Linux_arm64"
case "darwin_amd64":
return "Darwin_x86_64"
case "darwin_arm64":
return "Darwin_arm64"
default:
return ""
}
}
8 changes: 2 additions & 6 deletions server/core/runtime/policy/conftest_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"path/filepath"
"runtime"
"testing"

"github.com/hashicorp/go-version"
Expand All @@ -17,17 +16,14 @@ import (
"github.com/runatlantis/atlantis/server/events/command"
"github.com/runatlantis/atlantis/server/logging"
. "github.com/runatlantis/atlantis/testing"

"golang.org/x/text/cases"
"golang.org/x/text/language"
)

func TestConfTestVersionDownloader(t *testing.T) {

version, _ := version.NewVersion("0.25.0")
destPath := "some/path"

fullURL := fmt.Sprintf("https://github.com/open-policy-agent/conftest/releases/download/v0.25.0/conftest_0.25.0_%s_x86_64.tar.gz?checksum=file:https://github.com/open-policy-agent/conftest/releases/download/v0.25.0/checksums.txt", cases.Title(language.English).String(runtime.GOOS))
platform := getPlatform()
fullURL := fmt.Sprintf("https://github.com/open-policy-agent/conftest/releases/download/v0.25.0/conftest_0.25.0_%s.tar.gz?checksum=file:https://github.com/open-policy-agent/conftest/releases/download/v0.25.0/checksums.txt", platform)

RegisterMockTestingT(t)

Expand Down

0 comments on commit da67e7d

Please sign in to comment.