Skip to content

Commit 9838250

Browse files
blakepetterssonBlake Pettersson
andauthored
Add local config support (#150)
* feat: add ability to specify local config This is useful for cases when a user has previously logged in with sso; when a local config path has been set the `apiClient` will take the token from the config. * deps: upgrade argocd The behaviour of `localconfig.DefaultLocalConfigPath` has changed between `2.2.x` and `2.3.x`, so to ensure that the correct default path is being taken, upgrade argocd along with its dependencies. * docs: update index.md Co-authored-by: Blake Pettersson <[email protected]>
1 parent 15df238 commit 9838250

File tree

4 files changed

+297
-677
lines changed

4 files changed

+297
-677
lines changed

argocd/provider.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/argoproj/argo-cd/v2/pkg/apiclient"
1111
"github.com/argoproj/argo-cd/v2/pkg/apiclient/session"
1212
"github.com/argoproj/argo-cd/v2/util/io"
13+
"github.com/argoproj/argo-cd/v2/util/localconfig"
1314
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1415
"k8s.io/client-go/rest"
1516
"k8s.io/client-go/tools/clientcmd"
@@ -44,6 +45,8 @@ func Provider() *schema.Provider {
4445
ConflictsWith: []string{
4546
"username",
4647
"password",
48+
"use_local_config",
49+
"config_path",
4750
},
4851
},
4952
"username": {
@@ -52,10 +55,13 @@ func Provider() *schema.Provider {
5255
DefaultFunc: schema.EnvDefaultFunc("ARGOCD_AUTH_USERNAME", nil),
5356
ConflictsWith: []string{
5457
"auth_token",
58+
"use_local_config",
59+
"config_path",
5560
},
5661
AtLeastOneOf: []string{
5762
"password",
5863
"auth_token",
64+
"use_local_config",
5965
},
6066
},
6167
"password": {
@@ -64,10 +70,13 @@ func Provider() *schema.Provider {
6470
DefaultFunc: schema.EnvDefaultFunc("ARGOCD_AUTH_PASSWORD", nil),
6571
ConflictsWith: []string{
6672
"auth_token",
73+
"use_local_config",
74+
"config_path",
6775
},
6876
AtLeastOneOf: []string{
6977
"username",
7078
"auth_token",
79+
"use_local_config",
7180
},
7281
},
7382
"cert_file": {
@@ -92,6 +101,25 @@ func Provider() *schema.Provider {
92101
Type: schema.TypeBool,
93102
Optional: true,
94103
},
104+
"use_local_config": {
105+
Type: schema.TypeBool,
106+
Optional: true,
107+
ConflictsWith: []string{
108+
"username",
109+
"password",
110+
"auth_token",
111+
},
112+
},
113+
"config_path": {
114+
Type: schema.TypeString,
115+
Optional: true,
116+
DefaultFunc: schema.EnvDefaultFunc("ARGOCD_CONFIG_PATH", nil),
117+
ConflictsWith: []string{
118+
"username",
119+
"password",
120+
"auth_token",
121+
},
122+
},
95123
"grpc_web_root_path": {
96124
Type: schema.TypeString,
97125
Optional: true,
@@ -148,6 +176,20 @@ func initApiClient(d *schema.ResourceData) (
148176
opts.ServerAddr = v.(string)
149177
}
150178

179+
if v, ok := d.GetOk("use_local_config"); ok {
180+
if v.(bool) {
181+
if v, ok := d.GetOk("config_path"); ok {
182+
opts.ConfigPath = v.(string)
183+
} else {
184+
path, err := localconfig.DefaultLocalConfigPath()
185+
if err != nil {
186+
return nil, err
187+
}
188+
opts.ConfigPath = path
189+
}
190+
}
191+
}
192+
151193
if v, ok := d.GetOk("plain_text"); ok {
152194
opts.PlainText = v.(bool)
153195
}

docs/index.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ provider "argocd" {
1414
## Argument Reference
1515

1616
* `server_addr` - (Required) ArgoCD server address with port.
17-
* `auth_token` - (Optional) ArgoCD authentication token, taked precedence over `username`/`password`. Can be set through the `ARGOCD_AUTH_TOKEN` environment variable.
17+
* `use_local_config` - (Optional) use the authentication settings found in the local config file. Useful when you have previously logged in using SSO. Conflicts with
18+
`auth_token`, `username` and `password`.
19+
* `config_path` (Optional) - Override the default config path of `$HOME/.config/argocd/config`. Only relevant when using `use_local_config` above.
20+
Can be set through the `ARGOCD_CONFIG_PATH` environment variable.
21+
* `auth_token` - (Optional) ArgoCD authentication token, takes precedence over `username`/`password`. Can be set through the `ARGOCD_AUTH_TOKEN` environment variable.
1822
* `username` - (Optional) authentication username. Can be set through the `ARGOCD_AUTH_USERNAME` environment variable.
1923
* `password` - (Optional) authentication password. Can be set through the `ARGOCD_AUTH_PASSWORD` environment variable.
2024
* `cert_file` - (Optional) Additional root CA certificates file to add to the client TLS connection pool.

go.mod

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,51 +6,38 @@ require (
66
cloud.google.com/go/storage v1.14.0 // indirect
77
github.com/Masterminds/semver v1.5.0
88
github.com/apparentlymart/go-cidr v1.1.0 // indirect
9-
github.com/argoproj/argo-cd/v2 v2.2.5
10-
github.com/argoproj/gitops-engine v0.5.2
9+
github.com/argoproj/argo-cd/v2 v2.3.0
10+
github.com/argoproj/gitops-engine v0.6.0
1111
github.com/argoproj/pkg v0.11.1-0.20211203175135-36c59d8fafe0
1212
github.com/aws/aws-sdk-go v1.38.65 // indirect
13-
github.com/caddyserver/caddy v1.0.3 // indirect
14-
github.com/casbin/casbin v1.9.1 // indirect
15-
github.com/checkpoint-restore/go-criu/v4 v4.1.0 // indirect
1613
github.com/cristalhq/jwt/v3 v3.1.0
17-
github.com/go-bindata/go-bindata v3.1.1+incompatible // indirect
1814
github.com/golang/protobuf v1.5.2
19-
github.com/golang/snappy v0.0.3 // indirect
2015
github.com/hashicorp/go-getter v1.5.4 // indirect
2116
github.com/hashicorp/go-uuid v1.0.2 // indirect
2217
github.com/hashicorp/hcl/v2 v2.8.2 // indirect
2318
github.com/hashicorp/terraform-json v0.13.0 // indirect
2419
github.com/hashicorp/terraform-plugin-sdk/v2 v2.7.1
25-
github.com/miekg/dns v1.1.35 // indirect
2620
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
27-
github.com/robfig/cron v1.1.0
28-
github.com/spf13/jwalterweatherman v1.1.0 // indirect
21+
github.com/robfig/cron v1.2.0
2922
github.com/stretchr/testify v1.7.0
30-
github.com/thecodeteam/goscaleio v0.1.0 // indirect
3123
github.com/ulikunitz/xz v0.5.10 // indirect
32-
go.etcd.io/etcd v0.5.0-alpha.5.0.20200910180754-dd1b699fc489 // indirect
33-
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e
34-
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
35-
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect
36-
golang.org/x/tools v0.1.3 // indirect
37-
google.golang.org/api v0.44.0-impersonate-preview // indirect
38-
k8s.io/apimachinery v0.22.2
24+
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
25+
k8s.io/apimachinery v0.23.1
3926
k8s.io/client-go v11.0.1-0.20190816222228-6d55c1b1f1ca+incompatible
40-
k8s.io/heapster v1.2.0-beta.1 // indirect
4127
modernc.org/mathutil v1.0.0
4228
)
4329

4430
replace (
31+
github.com/go-check/check v1.0.0-20180628173108-788fd7840127 => github.com/go-check/check v0.0.0-20180628173108-788fd7840127
4532
github.com/golang/protobuf => github.com/golang/protobuf v1.4.2
4633
github.com/gorilla/websocket => github.com/gorilla/websocket v1.4.2
4734
github.com/grpc-ecosystem/grpc-gateway => github.com/grpc-ecosystem/grpc-gateway v1.16.0
4835
github.com/improbable-eng/grpc-web => github.com/improbable-eng/grpc-web v0.0.0-20181111100011-16092bd1d58a
4936

50-
k8s.io/api => k8s.io/api v0.22.2
37+
k8s.io/api => k8s.io/api v0.23.1
5138
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.22.2
5239
k8s.io/apimachinery => k8s.io/apimachinery v0.22.4-rc.0
53-
k8s.io/apiserver => k8s.io/apiserver v0.22.2
40+
k8s.io/apiserver => k8s.io/apiserver v0.23.1
5441
k8s.io/cli-runtime => k8s.io/cli-runtime v0.22.2
5542
k8s.io/client-go => k8s.io/client-go v0.22.2
5643
k8s.io/cloud-provider => k8s.io/cloud-provider v0.22.2
@@ -65,7 +52,7 @@ replace (
6552
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.22.2
6653
k8s.io/kube-proxy => k8s.io/kube-proxy v0.22.2
6754
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.22.2
68-
k8s.io/kubectl => k8s.io/kubectl v0.22.2
55+
k8s.io/kubectl => k8s.io/kubectl v0.23.1
6956
k8s.io/kubelet => k8s.io/kubelet v0.22.2
7057
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.22.2
7158
k8s.io/metrics => k8s.io/metrics v0.22.2

0 commit comments

Comments
 (0)