-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Devang Gaur
committed
Mar 3, 2021
1 parent
81e9b7f
commit d03f7c3
Showing
6 changed files
with
100 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package runtime | ||
|
||
import ( | ||
"github.com/accurics/terrascan/pkg/config" | ||
"github.com/accurics/terrascan/pkg/utils" | ||
"go.uber.org/zap" | ||
) | ||
|
||
// read the config file and update scan and skip rules | ||
func (e *Executor) initPolicyPathsFromConfigFile() error { | ||
if e.configFile == "" { | ||
return nil | ||
} | ||
|
||
configReader, err := config.NewTerrascanConfigReader(e.configFile) | ||
if err != nil { | ||
zap.S().Error("error loading config file", zap.Error(err)) | ||
return err | ||
} | ||
|
||
absoluteRepoPath, absolutePolicyPath, err := utils.GetAbsPolicyConfigPaths(config.GetPolicyRepoPath(), config.GetPolicyBasePath()) | ||
if err != nil { | ||
zap.S().Error("error processing provided policy paths", zap.Error(err)) | ||
return err | ||
} | ||
|
||
if len(configReader.GetPolicyConfig().RepoPath) > 0 { | ||
config.Global.RepoPath = absoluteRepoPath | ||
} | ||
|
||
if len(configReader.GetPolicyConfig().BasePath) > 0 { | ||
config.Global.BasePath = absolutePolicyPath | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package utils | ||
|
||
import ( | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/pkg/errors" | ||
"go.uber.org/zap" | ||
) | ||
|
||
// GetAbsPolicyConfigPaths tranforms the provided policy repo path and base path into absolute paths | ||
func GetAbsPolicyConfigPaths(repoPath, policyPath string) (string, string, error) { | ||
absoluteRepoPath, err := GetAbsPath(repoPath) | ||
if err != nil { | ||
return repoPath, policyPath, errors.Errorf("invalid repository path `%s`, error : `%v`", repoPath, err) | ||
} | ||
|
||
absolutePolicyPath, err := GetAbsPath(policyPath) | ||
if err != nil { | ||
return absoluteRepoPath, policyPath, errors.Errorf("invalid policyPath `%s`, error : `%v`", policyPath, err) | ||
} | ||
|
||
if strings.HasPrefix(absolutePolicyPath, absoluteRepoPath) { | ||
return absoluteRepoPath, absolutePolicyPath, nil | ||
} | ||
|
||
zap.S().Debugf("policy path, `%s` ,does not fall under base repo path's `%s` directory structure", absolutePolicyPath, absoluteRepoPath) | ||
zap.S().Debugf("appending policy path: `%s` to the repo path: `%s`. checking ...", policyPath, absoluteRepoPath) | ||
|
||
absolutePolicyPath = filepath.Join(absoluteRepoPath, policyPath) | ||
return absoluteRepoPath, absolutePolicyPath, nil | ||
} |