func (c AggregateClient) GetKubeConfig(ctx context.Context, ac *v1alpha3.AKSCluster) ([]byte, error) {
	creds, err := c.ManagedClusters.ListClusterAdminCredentials(ctx, ac.Spec.ResourceGroupName, meta.GetExternalName(ac))
	if err != nil {
		return nil, err
	}
	if creds.Kubeconfigs == nil || len(*creds.Kubeconfigs) == 0 || (*creds.Kubeconfigs)[0].Value == nil {
		return nil, errors.Errorf("zero kubeconfig credentials returned")
	}
	return *((*creds.Kubeconfigs)[0].Value), nil
}
GetKubeConfig produces a kubeconfig file that configures access to the
supplied AKS cluster.
package compute
import (
	"context"
	"fmt"
	"time"
	"github.com/Azure/azure-sdk-for-go/services/authorization/mgmt/2015-07-01/authorization"
	authorizationmgmt "github.com/Azure/azure-sdk-for-go/services/authorization/mgmt/2015-07-01/authorization"
	"github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2018-03-31/containerservice"
	"github.com/Azure/azure-sdk-for-go/services/graphrbac/1.6/graphrbac"
	"github.com/Azure/go-autorest/autorest"
	"github.com/Azure/go-autorest/autorest/adal"
	"github.com/Azure/go-autorest/autorest/date"
	"github.com/Azure/go-autorest/autorest/to"
	"github.com/google/uuid"
	"github.com/pkg/errors"
	"github.com/crossplane/crossplane-runtime/pkg/meta"
	"github.com/crossplane/crossplane-runtime/pkg/resource"
	"github.com/crossplane/provider-azure/apis/compute/v1alpha3"
	azure "github.com/crossplane/provider-azure/pkg/clients"
)
const (
	AgentPoolProfileName = "agentpool"
	NetworkContributorRoleID = "/providers/Microsoft.Authorization/roleDefinitions/4d97b98b-1d4f-4787-a291-c67834d212e7"
	appCredsValidYears = 5
)
type AKSClient interface {
	GetManagedCluster(ctx context.Context, ac *v1alpha3.AKSCluster) (containerservice.ManagedCluster, error)
	EnsureManagedCluster(ctx context.Context, ac *v1alpha3.AKSCluster, secret string) error
	DeleteManagedCluster(ctx context.Context, ac *v1alpha3.AKSCluster) error
	GetKubeConfig(ctx context.Context, ac *v1alpha3.AKSCluster) ([]byte, error)
}
type AggregateClient struct {
	ManagedClusters   containerservice.ManagedClustersClient
	Applications      graphrbac.ApplicationsClient
	ServicePrincipals graphrbac.ServicePrincipalsClient
	RoleAssignments   authorization.RoleAssignmentsClient
}
func NewAggregateClient(creds map[string]string, auth autorest.Authorizer) (AKSClient, error) {
	mcc := containerservice.NewManagedClustersClient(creds[azure.CredentialsKeySubscriptionID])
	mcc.Authorizer = auth
	_ = mcc.AddToUserAgent(azure.UserAgent)
	rac := authorization.NewRoleAssignmentsClient(creds[azure.CredentialsKeySubscriptionID])
	rac.Authorizer = auth
	_ = rac.AddToUserAgent(azure.UserAgent)
	cfg, err := adal.NewOAuthConfig(creds[azure.CredentialsKeyActiveDirectoryEndpointURL], creds[azure.CredentialsKeyTenantID])
	if err != nil {
		return nil, errors.Wrap(err, "cannot create OAuth configuration")
	}
	token, err := adal.NewServicePrincipalToken(*cfg,
		creds[azure.CredentialsKeyClientID],
		creds[azure.CredentialsKeyClientSecret],
		creds[azure.CredentialsKeyActiveDirectoryGraphResourceID])
	if err != nil {
		return nil, errors.Wrap(err, "cannot create service principal token")
	}
	if err := token.Refresh(); err != nil {
		return nil, errors.Wrap(err, "cannot refresh service principal token")
	}
	ta := autorest.NewBearerAuthorizer(token)
	ac := graphrbac.NewApplicationsClient(creds[azure.CredentialsKeyTenantID])
	ac.Authorizer = ta
	_ = ac.AddToUserAgent(azure.UserAgent)
	spc := graphrbac.NewServicePrincipalsClient(creds[azure.CredentialsKeyTenantID])
	spc.Authorizer = ta
	_ = spc.AddToUserAgent(azure.UserAgent)
	return AggregateClient{
		ManagedClusters:   mcc,
		Applications:      ac,
		ServicePrincipals: spc,
		RoleAssignments:   rac,
	}, nil
}
func (c AggregateClient) GetManagedCluster(ctx context.Context, ac *v1alpha3.AKSCluster) (containerservice.ManagedCluster, error) {
	return c.ManagedClusters.Get(ctx, ac.Spec.ResourceGroupName, meta.GetExternalName(ac))
}
func (c AggregateClient) EnsureManagedCluster(ctx context.Context, ac *v1alpha3.AKSCluster, secret string) error {
	app, err := c.ensureApplication(ctx, meta.GetExternalName(ac), secret)
	if err != nil {
		return err
	}
	sp, err := c.ensureServicePrincipal(ctx, to.String(app.AppID))
	if err != nil {
		return err
	}
	if err := c.ensureRoleAssignment(ctx, to.String(sp.ObjectID), NetworkContributorRoleID, ac.Spec.VnetSubnetID); err != nil {
		return err
	}
	mc := newManagedCluster(ac, to.String(app.AppID), secret)
	_, err = c.ManagedClusters.CreateOrUpdate(ctx, ac.Spec.ResourceGroupName, meta.GetExternalName(ac), mc)
	return err
}
func (c AggregateClient) DeleteManagedCluster(ctx context.Context, ac *v1alpha3.AKSCluster) error {
	if err := c.deleteApplication(ctx, meta.GetExternalName(ac)); err != nil {
		return err
	}
	_, err := c.ManagedClusters.Delete(ctx, ac.Spec.ResourceGroupName, meta.GetExternalName(ac))
	return err
}