Skip to content

Commit

Permalink
fix: ensure use_local_config is correctly applied and validated (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
onematchfox authored Jul 28, 2023
1 parent 08682d2 commit a1d2840
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions internal/provider/model_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,33 +183,33 @@ func (p ArgoCDProviderConfig) setCoreOpts(opts *apiclient.ClientOptions) (bool,
func (p ArgoCDProviderConfig) setLocalConfigOpts(opts *apiclient.ClientOptions) (bool, diag.Diagnostics) {
var diags diag.Diagnostics

useLocalConfig := opts.PortForward || opts.PortForwardNamespace != ""
useLocalConfig := p.UseLocalConfig.ValueBool()
switch useLocalConfig {
case true:
if opts.ServerAddr != "" {
diags.AddWarning("setting `server_addr` alongside `use_local_config = true` is unnecessary and not recommended as this will overwrite the address retrieved from the local ArgoCD context.", "")
}

if !p.Username.IsNull() {
diags.AddWarning("`username` is ignored when `use_local_config = true`.", "")
}

opts.Context = getDefaultString(p.Context, "ARGOCD_CONTEXT")

cp := getDefaultString(p.ConfigPath, "ARGOCD_CONFIG_PATH")

if cp != "" {
opts.ConfigPath = p.ConfigPath.ValueString()
return useLocalConfig, nil
break
}

cp, err := localconfig.DefaultLocalConfigPath()
if err == nil {
opts.ConfigPath = cp
return useLocalConfig, nil
break
}

diags.Append(diagnostics.Error("failed to find default ArgoCD config path", err)...)

if opts.ServerAddr != "" {
diags.AddWarning("setting `server_addr` alongside `use_local_config = true` is unnecessary and not recommended as this will overwrite the address retrieved from the local ArgoCD context.", "")
}

if !p.Username.IsNull() {
diags.AddWarning("`username` is ignored when `use_local_config = true`.", "")
}
case false:
// Log warnings if explicit configuration has been provided for local config when `use_local_config` is not enabled.
if !p.ConfigPath.IsNull() {
Expand Down

0 comments on commit a1d2840

Please sign in to comment.