Skip to content

Commit

Permalink
add support to download remote repo in CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
Yusuf Kanchwala committed Oct 2, 2020
1 parent d834e2e commit 160743f
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions pkg/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,24 @@ import (
func Run(iacType, iacVersion, cloudType, iacFilePath, iacDirPath, configFile,
policyPath, format, remoteType, remoteURL string, configOnly, useColors bool) {

// validate remote repository options
toDownload, err := validateRemoteOpts(remoteType, remoteURL)
if err != nil {
os.Exit(5)
}

// download remote repository
var tempDir string
if toDownload {
// temp dir to download the remote repo
tempDir = filepath.Join(os.TempDir(), utils.GenRandomString(6))
defer os.RemoveAll(tempDir)

// download remote repository
iacDirPath, err = downloadRemoteRepo(remoteType, remoteURL, tempDir)
if err != nil {
os.RemoveAll(tempDir)
os.Exit(5)
}
// temp dir to download the remote repo
tempDir = filepath.Join(os.TempDir(), utils.GenRandomString(6))
defer os.RemoveAll(tempDir)

// download remote repository
d := downloader.NewDownloader()
path, err := d.DownloadWithType(remoteType, remoteURL, tempDir)
if err == downloader.ErrEmptyURLType {
// url and type empty, proceed with regular scanning
zap.S().Debugf("remote url and type not configured, proceeding with regular scanning")
} else if err != nil {
// some error while downloading remote repository
return
} else {
// successfully downloaded remote repository
iacDirPath = path
}

// create a new runtime executor for processing IaC
Expand Down

0 comments on commit 160743f

Please sign in to comment.