mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
check the registry detector before local files
Breaking change for 0.11. Local files were checked first to avoid the possibility of breaking a module with a local source that looked like a registry ID. Now we can enfore that any source iwth the pattern "namespace/identifier/provider" must be a registry module.
This commit is contained in:
parent
6088270c66
commit
a359c4ee2f
@ -87,8 +87,8 @@ var detectors = []getter.Detector{
|
|||||||
new(getter.GitHubDetector),
|
new(getter.GitHubDetector),
|
||||||
new(getter.BitBucketDetector),
|
new(getter.BitBucketDetector),
|
||||||
new(getter.S3Detector),
|
new(getter.S3Detector),
|
||||||
new(localDetector),
|
|
||||||
new(registryDetector),
|
new(registryDetector),
|
||||||
|
new(localDetector),
|
||||||
}
|
}
|
||||||
|
|
||||||
// these prefixes can't be registry IDs
|
// these prefixes can't be registry IDs
|
||||||
|
@ -39,6 +39,10 @@ var testMods = map[string]testMod{
|
|||||||
location: "test-fixtures/registry-tar-subdir/foo.tgz//*?archive=tar.gz",
|
location: "test-fixtures/registry-tar-subdir/foo.tgz//*?archive=tar.gz",
|
||||||
version: "0.1.2",
|
version: "0.1.2",
|
||||||
},
|
},
|
||||||
|
"exists-in-registry/identifier/provider": {
|
||||||
|
location: "file:///registry/exists",
|
||||||
|
version: "0.2.0",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func latestVersion(versions []string) string {
|
func latestVersion(versions []string) string {
|
||||||
@ -65,7 +69,7 @@ func mockRegistry() *httptest.Server {
|
|||||||
http.StripPrefix("/v1/modules/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
http.StripPrefix("/v1/modules/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
p := strings.TrimLeft(r.URL.Path, "/")
|
p := strings.TrimLeft(r.URL.Path, "/")
|
||||||
// handle download request
|
// handle download request
|
||||||
download := regexp.MustCompile(`^(\w+/\w+/\w+)/download$`)
|
download := regexp.MustCompile(`^([-a-z]+/\w+/\w+)/download$`)
|
||||||
|
|
||||||
// download lookup
|
// download lookup
|
||||||
matches := download.FindStringSubmatch(p)
|
matches := download.FindStringSubmatch(p)
|
||||||
@ -189,8 +193,8 @@ func TestDetectors(t *testing.T) {
|
|||||||
new(getter.GitHubDetector),
|
new(getter.GitHubDetector),
|
||||||
new(getter.BitBucketDetector),
|
new(getter.BitBucketDetector),
|
||||||
new(getter.S3Detector),
|
new(getter.S3Detector),
|
||||||
new(localDetector),
|
|
||||||
regDetector,
|
regDetector,
|
||||||
|
new(localDetector),
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range []struct {
|
for _, tc := range []struct {
|
||||||
@ -239,13 +243,22 @@ func TestDetectors(t *testing.T) {
|
|||||||
err: true,
|
err: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
// make sure a local module that looks like a registry id takes precedence
|
// make sure a local module that looks like a registry id can be found
|
||||||
{
|
{
|
||||||
source: "namespace/identifier/provider",
|
source: "namespace/identifier/provider",
|
||||||
fixture: "discover-subdirs",
|
fixture: "discover-subdirs",
|
||||||
// this should be found locally
|
// this should be found locally
|
||||||
location: "file://" + filepath.Join(wd, fixtureDir, "discover-subdirs/namespace/identifier/provider"),
|
location: "file://" + filepath.Join(wd, fixtureDir, "discover-subdirs/namespace/identifier/provider"),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// The registry takes precedence over local paths if they don't start
|
||||||
|
// with a relative or absolute path
|
||||||
|
{
|
||||||
|
source: "exists-in-registry/identifier/provider",
|
||||||
|
fixture: "discover-registry-local",
|
||||||
|
// registry should take precidence
|
||||||
|
location: "file:///registry/exists",
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
|
|
||||||
t.Run(tc.source, func(t *testing.T) {
|
t.Run(tc.source, func(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user