From 6145dfe4b9da77d7e97b700a15b9f4c708a67a6f Mon Sep 17 00:00:00 2001 From: OneMatchFox <878612+onematchfox@users.noreply.github.com> Date: Fri, 28 Jul 2023 08:11:14 +0200 Subject: [PATCH] fix: ensure `use_local_config` is correctly applied and validated --- internal/provider/model_provider.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/internal/provider/model_provider.go b/internal/provider/model_provider.go index aff03619..5c0893e4 100644 --- a/internal/provider/model_provider.go +++ b/internal/provider/model_provider.go @@ -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() {