Skip to content

Commit

Permalink
add new flag to ignore proxy (#572)
Browse files Browse the repository at this point in the history
* add new flag to ignore proxy

* add new flag to ignore proxy

* remove chat from integration tests

* Update chat.go

* change ignore proxy validation
  • Loading branch information
pedrompflopes authored Sep 7, 2023
1 parent 66b8fda commit 6f52362
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions internal/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func NewAstCLI(
rootCmd.PersistentFlags().String(params.AccessKeySecretFlag, "", params.AccessKeySecretFlagUsage)
rootCmd.PersistentFlags().Bool(params.InsecureFlag, false, params.InsecureFlagUsage)
rootCmd.PersistentFlags().String(params.ProxyFlag, "", params.ProxyFlagUsage)
rootCmd.PersistentFlags().Bool(params.IgnoreProxyFlag, false, params.IgnoreProxyFlagUsage)
rootCmd.PersistentFlags().String(params.ProxyTypeFlag, "", params.ProxyTypeFlagUsage)
rootCmd.PersistentFlags().String(params.NtlmProxyDomainFlag, "", params.NtlmProxyDomainFlagUsage)
rootCmd.PersistentFlags().String(params.TimeoutFlag, "", params.TimeoutFlagUsage)
Expand Down Expand Up @@ -124,6 +125,7 @@ func NewAstCLI(
_ = viper.BindPFlag(params.BaseAuthURIKey, rootCmd.PersistentFlags().Lookup(params.BaseAuthURIFlag))
_ = viper.BindPFlag(params.AstAPIKey, rootCmd.PersistentFlags().Lookup(params.AstAPIKeyFlag))
_ = viper.BindPFlag(params.AgentNameKey, rootCmd.PersistentFlags().Lookup(params.AgentFlag))
_ = viper.BindPFlag(params.IgnoreProxyKey, rootCmd.PersistentFlags().Lookup(params.IgnoreProxyFlag))
// Key here is the actual flag since it doesn't use an environment variable
_ = viper.BindPFlag(params.DebugFlag, rootCmd.PersistentFlags().Lookup(params.DebugFlag))
_ = viper.BindPFlag(params.InsecureFlag, rootCmd.PersistentFlags().Lookup(params.InsecureFlag))
Expand Down
1 change: 1 addition & 0 deletions internal/params/binds.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var EnvVarsBinds = []struct {
{ProxyDomainKey, ProxyDomainEnv, ""},
{BaseAuthURIKey, BaseAuthURIEnv, ""},
{AstAPIKey, AstAPIKeyEnv, ""},
{IgnoreProxyKey, IgnoreProxyEnv, ""},
{AgentNameKey, AgentNameEnv, "ASTCLI"},
{CodeBashingPathKey, ScansPathEnv, "api/codebashing/lessons"},
{ScansPathKey, ScansPathEnv, "api/scans"},
Expand Down
1 change: 1 addition & 0 deletions internal/params/envs.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ const (
FeatureFlagsEnv = "CX_FEATURE_FLAGS_PATH"
UploadURLEnv = "CX_UPLOAD_URL"
PolicyEvaluationPathEnv = "CX_POLICY_EVALUATION_PATH"
IgnoreProxyEnv = "CX_IGNORE_PROXY"
)
2 changes: 2 additions & 0 deletions internal/params/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const (
BaseURIFlag = "base-uri"
ProxyFlag = "proxy"
ProxyFlagUsage = "Proxy server to send communication through"
IgnoreProxyFlag = "ignore-proxy"
IgnoreProxyFlagUsage = "Ignore proxy configuration"
ProxyTypeFlag = "proxy-auth-type"
ProxyTypeFlagUsage = "Proxy authentication type, (basic or ntlm)"
TimeoutFlag = "timeout"
Expand Down
1 change: 1 addition & 0 deletions internal/params/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var (
ScansPathKey = strings.ToLower(ScansPathEnv)
GroupsPathKey = strings.ToLower(GroupsPathEnv)
AgentNameKey = strings.ToLower(AgentNameEnv)
IgnoreProxyKey = strings.ToLower(IgnoreProxyEnv)
CodeBashingPathKey = strings.ToLower(CodeBashingPathEnv)
ProjectsPathKey = strings.ToLower(ProjectsPathEnv)
ResultsPathKey = strings.ToLower(ResultsPathEnv)
Expand Down
5 changes: 4 additions & 1 deletion internal/wrappers/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,12 @@ func setAgentName(req *http.Request) {
func GetClient(timeout uint) *http.Client {
proxyTypeStr := viper.GetString(commonParams.ProxyTypeKey)
proxyStr := viper.GetString(commonParams.ProxyKey)
ignoreProxy := viper.GetBool(commonParams.IgnoreProxyKey)

var client *http.Client
if proxyTypeStr == ntlmProxyToken {
if ignoreProxy {
client = basicProxyClient(timeout, "")
} else if proxyTypeStr == ntlmProxyToken {
client = ntmlProxyClient(timeout, proxyStr)
} else {
client = basicProxyClient(timeout, proxyStr)
Expand Down

0 comments on commit 6f52362

Please sign in to comment.