Merge pull request #10642 from hashicorp/wilken_init_no_magic_host
github/getter: Adds a hostname check to Get function
This commit is contained in:
commit
2065de0b4f
|
@ -291,6 +291,32 @@ func TestInitCommand_Run(t *testing.T) {
|
|||
testBuild{want: 1}.fn,
|
||||
},
|
||||
},
|
||||
{
|
||||
"unsupported-non-github-source-address",
|
||||
[]func(t *testing.T, tc testCaseInit){
|
||||
skipInitTestUnlessEnVar(acctest.TestEnvVar).fn,
|
||||
},
|
||||
testMetaFile(t),
|
||||
nil,
|
||||
"h1:47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=",
|
||||
map[string]string{
|
||||
`cfg.pkr.hcl`: `
|
||||
packer {
|
||||
required_plugins {
|
||||
comment = {
|
||||
source = "example.com/sylviamoss/comment"
|
||||
version = "v0.2.19"
|
||||
}
|
||||
}
|
||||
}`,
|
||||
},
|
||||
cfg.dir("6_pkr_config"),
|
||||
cfg.dir("6_pkr_user_folder"),
|
||||
1,
|
||||
nil,
|
||||
"h1:47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=",
|
||||
nil,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
const (
|
||||
ghTokenAccessor = "PACKER_GITHUB_API_TOKEN"
|
||||
defaultUserAgent = "packer-plugin-getter"
|
||||
defaultHostname = "github.com"
|
||||
)
|
||||
|
||||
type Getter struct {
|
||||
|
@ -154,6 +155,11 @@ func (t *HostSpecificTokenAuthTransport) base() http.RoundTripper {
|
|||
}
|
||||
|
||||
func (g *Getter) Get(what string, opts plugingetter.GetOptions) (io.ReadCloser, error) {
|
||||
if opts.PluginRequirement.Identifier.Hostname != defaultHostname {
|
||||
s := opts.PluginRequirement.Identifier.String() + " doesn't appear to be a valid " + defaultHostname + " source address; check source and try again."
|
||||
return nil, errors.New(s)
|
||||
}
|
||||
|
||||
ctx := context.TODO()
|
||||
if g.Client == nil {
|
||||
var tc *http.Client
|
||||
|
|
|
@ -345,7 +345,7 @@ func (pr *Requirement) InstallLatest(opts InstallOptions) (*Installation, error)
|
|||
getters := opts.Getters
|
||||
fail := fmt.Errorf("could not find a local nor a remote checksum for plugin %q %q", pr.Identifier, pr.VersionConstraints)
|
||||
|
||||
log.Printf("[TRACE] getting available versions for the the %s plugin", pr.Identifier)
|
||||
log.Printf("[TRACE] getting available versions for the %s plugin", pr.Identifier)
|
||||
versions := version.Collection{}
|
||||
for _, getter := range getters {
|
||||
|
||||
|
|
Loading…
Reference in New Issue