File tree Expand file tree Collapse file tree 6 files changed +89
-40
lines changed
cmd/argocd-k8s-auth/commands Expand file tree Collapse file tree 6 files changed +89
-40
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ builds:
21
21
- -X github.com/argoproj/argo-cd/v3/common.gitCommit={{ .FullCommit }}
22
22
- -X github.com/argoproj/argo-cd/v3/common.gitTreeState={{ .Env.GIT_TREE_STATE }}
23
23
- -X github.com/argoproj/argo-cd/v3/common.kubectlVersion={{ .Env.KUBECTL_VERSION }}
24
- - ' {{ if or (eq .Runtime.Goos "linux") (eq .Runtime.Goos "windows") }} -extldflags="-static"{{ end }} '
24
+ - -extldflags="-static"
25
25
goos :
26
26
- linux
27
27
- windows
@@ -42,15 +42,6 @@ builds:
42
42
goarch : ppc64le
43
43
- goos : windows
44
44
goarch : arm64
45
- overrides :
46
- - goos : darwin
47
- goarch : amd64
48
- env :
49
- - CGO_ENABLED=1
50
- - goos : darwin
51
- goarch : arm64
52
- env :
53
- - CGO_ENABLED=1
54
45
55
46
archives :
56
47
- id : argocd-archive
Original file line number Diff line number Diff line change
1
+ //go:build !darwin || (cgo && darwin)
2
+
1
3
package commands
2
4
3
5
import (
Original file line number Diff line number Diff line change
1
+ //go:build darwin && !cgo
2
+
3
+ // Package commands
4
+ // This file is used when the GOOS is darwin and CGO is not enabled.
5
+ // It provides a no-op implementation of newAzureCommand to allow goreleaser to build
6
+ // a darwin binary on a linux machine.
7
+ package commands
8
+
9
+ import (
10
+ "log"
11
+
12
+ "github.com/spf13/cobra"
13
+
14
+ "github.com/argoproj/argo-cd/v3/util/workloadidentity"
15
+ )
16
+
17
+ func newAzureCommand () * cobra.Command {
18
+ command := & cobra.Command {
19
+ Use : "azure" ,
20
+ Run : func (c * cobra.Command , _ []string ) {
21
+ log .Fatalf (workloadidentity .CGOError )
22
+ },
23
+ }
24
+ return command
25
+ }
Original file line number Diff line number Diff line change 1
1
package workloadidentity
2
2
3
3
import (
4
- "context"
5
4
"time"
6
-
7
- "github.com/Azure/azure-sdk-for-go/sdk/azcore"
8
- "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
9
- "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
10
5
)
11
6
12
7
const (
@@ -22,34 +17,9 @@ type TokenProvider interface {
22
17
GetToken (scope string ) (* Token , error )
23
18
}
24
19
25
- type WorkloadIdentityTokenProvider struct {
26
- tokenCredential azcore.TokenCredential
27
- }
28
-
29
20
// Used to propagate initialization error if any
30
21
var initError error
31
22
32
- func NewWorkloadIdentityTokenProvider () TokenProvider {
33
- cred , err := azidentity .NewDefaultAzureCredential (& azidentity.DefaultAzureCredentialOptions {})
34
- initError = err
35
- return WorkloadIdentityTokenProvider {tokenCredential : cred }
36
- }
37
-
38
- func (c WorkloadIdentityTokenProvider ) GetToken (scope string ) (* Token , error ) {
39
- if initError != nil {
40
- return nil , initError
41
- }
42
-
43
- token , err := c .tokenCredential .GetToken (context .Background (), policy.TokenRequestOptions {
44
- Scopes : []string {scope },
45
- })
46
- if err != nil {
47
- return nil , err
48
- }
49
-
50
- return & Token {AccessToken : token .Token , ExpiresOn : token .ExpiresOn }, nil
51
- }
52
-
53
23
func CalculateCacheExpiryBasedOnTokenExpiry (tokenExpiry time.Time ) time.Duration {
54
24
// Calculate the cache expiry as 5 minutes before the token expires
55
25
cacheExpiry := time .Until (tokenExpiry ) - time .Minute * 5
Original file line number Diff line number Diff line change
1
+ //go:build !darwin || (cgo && darwin)
2
+
3
+ package workloadidentity
4
+
5
+ import (
6
+ "context"
7
+
8
+ "github.com/Azure/azure-sdk-for-go/sdk/azcore"
9
+ "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
10
+ "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
11
+ )
12
+
13
+ type WorkloadIdentityTokenProvider struct {
14
+ tokenCredential azcore.TokenCredential
15
+ }
16
+
17
+ func NewWorkloadIdentityTokenProvider () TokenProvider {
18
+ cred , err := azidentity .NewDefaultAzureCredential (& azidentity.DefaultAzureCredentialOptions {})
19
+ initError = err
20
+ return WorkloadIdentityTokenProvider {tokenCredential : cred }
21
+ }
22
+
23
+ func (c WorkloadIdentityTokenProvider ) GetToken (scope string ) (* Token , error ) {
24
+ if initError != nil {
25
+ return nil , initError
26
+ }
27
+
28
+ token , err := c .tokenCredential .GetToken (context .Background (), policy.TokenRequestOptions {
29
+ Scopes : []string {scope },
30
+ })
31
+ if err != nil {
32
+ return nil , err
33
+ }
34
+
35
+ return & Token {AccessToken : token .Token , ExpiresOn : token .ExpiresOn }, nil
36
+ }
Original file line number Diff line number Diff line change
1
+ //go:build darwin && !cgo
2
+
3
+ // Package workloadidentity
4
+ // This file is used when the GOOS is darwin and CGO is not enabled.
5
+ // It provides a no-op implementation of the WorkloadIdentityTokenProvider to allow goreleaser to build
6
+ // a darwin binary on a linux machine.
7
+ package workloadidentity
8
+
9
+ import (
10
+ "errors"
11
+ )
12
+
13
+ type WorkloadIdentityTokenProvider struct {
14
+ }
15
+
16
+ const CGOError = "CGO is not enabled, cannot use workload identity token provider"
17
+
18
+ // Code that does not require CGO
19
+ func NewWorkloadIdentityTokenProvider () TokenProvider {
20
+ panic (CGOError )
21
+ }
22
+
23
+ func (c WorkloadIdentityTokenProvider ) GetToken (scope string ) (* Token , error ) {
24
+ return nil , errors .New (CGOError )
25
+ }
You can’t perform that action at this time.
0 commit comments