Skip to content

Commit

Permalink
1. move remote module utils to downloader pkg
Browse files Browse the repository at this point in the history
2. add wiki link for punycode
3. use filepath.Join()
  • Loading branch information
patilpankaj212 committed Feb 1, 2021
1 parent 90fe2cb commit 50d64c3
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
9 changes: 4 additions & 5 deletions pkg/downloader/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"fmt"
"path/filepath"

"github.com/accurics/terrascan/pkg/utils"
getter "github.com/hashicorp/go-getter"
"github.com/hashicorp/go-version"
"github.com/hashicorp/terraform/configs"
Expand Down Expand Up @@ -150,13 +149,13 @@ func (g *goGetter) DownloadWithType(remoteType, remoteURL, destPath string) (str
return "", ErrEmptyURLDest
}

if !utils.IsValidRemoteType(remoteType) {
if !IsValidRemoteType(remoteType) {
return "", ErrInvalidRemoteType
}

if utils.IsRemoteTypeTerraformRegistry(remoteType) {
sourceAddr, ver := utils.GetSourceAddrAndVersion(remoteURL)
if utils.IsRegistrySourceAddr(sourceAddr) {
if IsRemoteTypeTerraformRegistry(remoteType) {
sourceAddr, ver := GetSourceAddrAndVersion(remoteURL)
if IsRegistrySourceAddr(sourceAddr) {
module, _ := regsrc.ParseModuleSource(sourceAddr)
versionConstraints := configs.VersionConstraint{}
if ver != "" {
Expand Down
1 change: 1 addition & 0 deletions pkg/downloader/module-download.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func (r *remoteModuleInstaller) DownloadModule(addr, destPath string) (string, e
// this function takes similar approach taken by terraform init for downloading terraform registry modules
func (r *remoteModuleInstaller) DownloadRemoteModule(requiredVersion hclConfigs.VersionConstraint, destPath string, module *regsrc.Module) (string, error) {
// Terraform doesn't allow the hostname to contain Punycode
// for more information on Punycode refer https://en.wikipedia.org/wiki/Punycode
// module.SvcHost returns an error for such case
_, err := module.SvcHost()
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
*/

package utils
package downloader

import (
"strings"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
*/

package utils
package downloader

import (
"testing"
Expand Down
6 changes: 3 additions & 3 deletions pkg/iac-providers/terraform/commons/load-dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ func LoadIacDir(absRootDir string) (allResourcesConfig output.AllResourceConfigs

// figure out path sub module directory, if it's remote then download it locally
var pathToModule string
if utils.IsLocalSourceAddr(req.SourceAddr) {
if downloader.IsLocalSourceAddr(req.SourceAddr) {

pathToModule = processLocalSource(req, remoteModPaths, absRootDir)
zap.S().Debugf("processing local module %q", pathToModule)
} else if utils.IsRegistrySourceAddr(req.SourceAddr) {
} else if downloader.IsRegistrySourceAddr(req.SourceAddr) {
// temp dir to download the remote repo
tempDir := generateTempDir()

Expand Down Expand Up @@ -213,7 +213,7 @@ func processLocalSource(req *hclConfigs.ModuleRequest, remoteModPaths map[string
for remoteSourceAddr, downloadPath := range remoteModPaths {
if strings.Contains(pathToModule, remoteSourceAddr) {
pathToModule = strings.Replace(pathToModule, remoteSourceAddr, "", 1)
pathToModule = downloadPath + pathToModule
pathToModule = filepath.Join(downloadPath, pathToModule)
keyFound = true
break
}
Expand Down

0 comments on commit 50d64c3

Please sign in to comment.