github.com/argoproj/argo-cd/v3@v3.2.1/cmd/argocd-k8s-auth/commands/azure_cgo.go (about)

     1  //go:build !darwin || (cgo && darwin)
     2  
     3  package commands
     4  
     5  import (
     6  	"fmt"
     7  	"os"
     8  
     9  	"github.com/Azure/kubelogin/pkg/token"
    10  	"github.com/spf13/cobra"
    11  
    12  	"github.com/argoproj/argo-cd/v3/util/errors"
    13  )
    14  
    15  var (
    16  	envServerApplicationID = "AAD_SERVER_APPLICATION_ID"
    17  	envEnvironmentName     = "AAD_ENVIRONMENT_NAME"
    18  )
    19  
    20  const (
    21  	DEFAULT_AAD_SERVER_APPLICATION_ID = "6dae42f8-4368-4678-94ff-3960e28e3630"
    22  )
    23  
    24  func newAzureCommand() *cobra.Command {
    25  	command := &cobra.Command{
    26  		Use: "azure",
    27  		Run: func(c *cobra.Command, _ []string) {
    28  			o := token.OptionsWithEnv()
    29  			if o.LoginMethod == "" { // no environment variable overrides
    30  				// we'll use default of WorkloadIdentityLogin for the login flow
    31  				o.LoginMethod = token.WorkloadIdentityLogin
    32  			}
    33  			o.ServerID = DEFAULT_AAD_SERVER_APPLICATION_ID
    34  			if v, ok := os.LookupEnv(envServerApplicationID); ok {
    35  				o.ServerID = v
    36  			}
    37  			if v, ok := os.LookupEnv(envEnvironmentName); ok {
    38  				o.Environment = v
    39  			}
    40  			tp, err := token.GetTokenProvider(o)
    41  			errors.CheckError(err)
    42  			tok, err := tp.GetAccessToken(c.Context())
    43  			errors.CheckError(err)
    44  			_, _ = fmt.Fprint(os.Stdout, formatJSON(tok.Token, tok.ExpiresOn))
    45  		},
    46  	}
    47  	return command
    48  }