cahnges for getting release from release official site

anshul/plugin_binary_from_official_site
anshul sharma 10 months ago
parent fb87672ec2
commit bdb93b458d

@ -7,13 +7,10 @@ import (
"bufio"
"bytes"
"context"
"crypto/tls"
"crypto/x509"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
@ -331,25 +328,7 @@ func (g *Getter) GetOfficialRelease(what string, opts plugingetter.GetOptions) (
}
if g.HttpClient == nil {
caCert, err := ioutil.ReadFile("/Users/anshulsharma/Documents/test_official/cert.pem")
if err != nil {
panic(err)
}
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)
// Create custom TLS config
tlsConfig := &tls.Config{
InsecureSkipVerify: true,
}
g.HttpClient = &http.Client{
Transport: &http.Transport{
TLSClientConfig: tlsConfig,
},
}
//g.HttpClient = &http.Client{}
g.HttpClient = &http.Client{}
}
var req *http.Request
@ -363,10 +342,9 @@ func (g *Getter) GetOfficialRelease(what string, opts plugingetter.GetOptions) (
req, err = http.NewRequest("GET", url, nil)
transform = transformReleasesVersionStream
case "sha256":
// something like https://github.com/sylviamoss/packer-plugin-comment/releases/download/v0.2.11/packer-plugin-comment_v0.2.11_x5_SHA256SUMS
// https://github.com/sylviamoss/packer-plugin-comment/releases/download/v0.2.11/packer-plugin-comment_v0.2.11_x5_SHA256SUMS
url := filepath.ToSlash("https://releases.hashicorp.com/" + ghURI.PluginType() + "/" + opts.VersionString() + "/" + ghURI.PluginType() + "_" + opts.VersionString() + "_SHA256SUMS")
transform = transformChecksumStream()
log.Printf("[DEBUG] github-getter: getting %q", url)
req, err = http.NewRequest("GET", url, nil)
case "zip":
// https://releases.hashicorp.com/terraform-provider-akamai/8.0.0/terraform-provider-akamai_8.0.0_darwin_arm64.zip

@ -702,7 +702,7 @@ func (pr *Requirement) InstallLatest(opts InstallOptions) (*Installation, error)
newInstall, err := pr.InstallOfficial(opts)
if err != nil {
if errors.Is(err, HTTPFailure) {
log.Printf("[TRACE] Failure from release site, trying to install from gitHub.com %s", pr.Identifier)
log.Printf("[TRACE] Failure from release official site, falling-back to gitHub.com for %s", pr.Identifier)
newInstall, err = pr.InstallFromGitHub(opts)
if err != nil {
return nil, err
@ -1159,7 +1159,6 @@ func (pr *Requirement) InstallOfficial(opts InstallOptions) (*Installation, erro
}
if err := entry.validateRelease(version.String(), opts.BinaryInstallationOptions); err != nil {
log.Printf("#### Got error %v", err)
continue
}
@ -1179,12 +1178,18 @@ func (pr *Requirement) InstallOfficial(opts InstallOptions) (*Installation, erro
Checksummer: checksummer,
}
log.Printf("#### getChecksum filename: %s", checksum.Filename)
expectedZipFilename := checksum.Filename
expectedBinaryFilename := strings.TrimSuffix(expectedZipFilename, filepath.Ext(expectedZipFilename)) + opts.BinaryInstallationOptions.Ext
outputFileName := filepath.Join(outputFolder, expectedBinaryFilename)
pluginSourceParts := strings.Split(pr.Identifier.Source, "/")
log.Printf("#### output filename: %s", outputFileName)
expectedBinFilename := strings.Join([]string{fmt.Sprintf("packer-plugin-%s", pluginSourceParts[2]),
"v" + version.String(),
"x" + pluginsdk.APIVersionMajor + "." + pluginsdk.APIVersionMinor,
entry.os,
entry.arch + ".zip",
}, "_")
expectedBinaryFilename := strings.TrimSuffix(expectedBinFilename, filepath.Ext(expectedBinFilename)) + opts.BinaryInstallationOptions.Ext
outputFileName := filepath.Join(outputFolder, expectedBinaryFilename)
for _, potentialChecksumer := range opts.Checksummers {
// First check if a local checksum file is already here in the expected
@ -1236,6 +1241,7 @@ func (pr *Requirement) InstallOfficial(opts InstallOptions) (*Installation, erro
tmpFile.Close()
os.Remove(tmpFilePath)
}()
// write binary to tmp file
_, err = io.Copy(tmpFile, remoteZipFile)
_ = remoteZipFile.Close()
@ -1249,6 +1255,7 @@ func (pr *Requirement) InstallOfficial(opts InstallOptions) (*Installation, erro
errs = multierror.Append(errs, err)
continue
}
// verify that the checksum for the zip is what we expect.
if err := checksum.Checksummer.Checksum(checksum.Expected, tmpFile); err != nil {
err := fmt.Errorf("%w. Is the checksum file correct ? Is the binary file correct ?", err)
@ -1263,7 +1270,7 @@ func (pr *Requirement) InstallOfficial(opts InstallOptions) (*Installation, erro
var copyFrom io.ReadCloser
for _, f := range zr.File {
if f.Name != "terraform-provider-akamai_v8.0.0" {
if f.Name != expectedBinaryFilename {
continue
}
copyFrom, err = f.Open()
@ -1364,13 +1371,11 @@ func (pr *Requirement) InstallOfficial(opts InstallOptions) (*Installation, erro
errs = multierror.Append(errs, fmt.Errorf("could not install any compatible version of plugin %q", pr.Identifier))
return nil, errs
return nil, errs
}
func GetPluginDescription(pluginPath string) (pluginsdk.SetDescription, error) {
out, err := exec.Command(pluginPath, "describe").Output()
if err != nil {
log.Printf("#### could not get plugin description for %q %q", pluginPath, err)
return pluginsdk.SetDescription{}, err
}

Loading…
Cancel
Save