func getAccessToken(cfg config, environment azure.Environment) (*adal.ServicePrincipalToken, error) {
	// Try to retrive token with MSI.
	if cfg.UseManagedIdentityExtension {
		log.Info("Using managed identity extension to retrieve access token for Azure API.")
		msiEndpoint, err := adal.GetMSIVMEndpoint()
		if err != nil {
			return nil, fmt.Errorf("failed to get the managed service identity endpoint: %v", err)
		}

		token, err := adal.NewServicePrincipalTokenFromMSI(msiEndpoint, environment.ServiceManagementEndpoint)
		if err != nil {
			return nil, fmt.Errorf("failed to create the managed service identity token: %v", err)
		}
		return token, nil
	}

	// Try to retrieve token with service principal credentials.
	if len(cfg.ClientID) > 0 && len(cfg.ClientSecret) > 0 {
		log.Info("Using client_id+client_secret to retrieve access token for Azure API.")
		oauthConfig, err := adal.NewOAuthConfig(environment.ActiveDirectoryEndpoint, cfg.TenantID)
		if err != nil {
			return nil, fmt.Errorf("failed to retrieve OAuth config: %v", err)
		}

		token, err := adal.NewServicePrincipalToken(*oauthConfig, cfg.ClientID, cfg.ClientSecret, environment.ResourceManagerEndpoint)
		if err != nil {
			return nil, fmt.Errorf("failed to create service principal token: %v", err)
		}
		return token, nil
	}

	return nil, fmt.Errorf("no credentials provided for Azure API")
}
func getAccessToken(cfg config, environment azure.Environment) (*adal.ServicePrincipalToken, error) {
	
	if cfg.UseManagedIdentityExtension {
		log.Info("Using managed identity extension to retrieve access token for Azure API.")
		msiEndpoint, err := adal.GetMSIVMEndpoint()
		if err != nil {
			return nil, fmt.Errorf("failed to get the managed service identity endpoint: %v", err)
		}

		token, err := adal.NewServicePrincipalTokenFromMSI(msiEndpoint, environment.ServiceManagementEndpoint)
		if err != nil {
			return nil, fmt.Errorf("failed to create the managed service identity token: %v", err)
		}
		return token, nil
	}

	
	if len(cfg.ClientID) > 0 && len(cfg.ClientSecret) > 0 {
		log.Info("Using client_id+client_secret to retrieve access token for Azure API.")
		oauthConfig, err := adal.NewOAuthConfig(environment.ActiveDirectoryEndpoint, cfg.TenantID)
		if err != nil {
			return nil, fmt.Errorf("failed to retrieve OAuth config: %v", err)
		}

		token, err := adal.NewServicePrincipalToken(*oauthConfig, cfg.ClientID, cfg.ClientSecret, environment.ResourceManagerEndpoint)
		if err != nil {
			return nil, fmt.Errorf("failed to create service principal token: %v", err)
		}
		return token, nil
	}

	return nil, fmt.Errorf("no credentials provided for Azure API")
}
func getAccessToken ( cfg config , environment azure . Environment ) ( * adal . ServicePrincipalToken , error ) { // Try to retrive token with MSI. if cfg . UseManagedIdentityExtension { log . Info ( " " ) msiEndpoint , err := adal . GetMSIVMEndpoint ( ) if err != nil { return nil , fmt . Errorf ( " " , err ) } token , err := adal . NewServicePrincipalTokenFromMSI ( msiEndpoint , environment . ServiceManagementEndpoint ) if err != nil { return nil , fmt . Errorf ( " " , err ) } return token , nil } // Try to retrieve token with service principal credentials. if len ( cfg . ClientID ) > 0 && len ( cfg . ClientSecret ) > 0 { log . Info ( " " ) oauthConfig , err := adal . NewOAuthConfig ( environment . ActiveDirectoryEndpoint , cfg . TenantID ) if err != nil { return nil , fmt . Errorf ( " " , err ) } token , err := adal . NewServicePrincipalToken ( * oauthConfig , cfg . ClientID , cfg . ClientSecret , environment . ResourceManagerEndpoint ) if err != nil { return nil , fmt . Errorf ( " " , err ) } return token , nil } return nil , fmt . Errorf ( " " ) }
// getAccessToken retrieves Azure API access token.
getAccessToken retrieves Azure API access token .