Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure use_local_config is correctly applied and validated #321

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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