-
Notifications
You must be signed in to change notification settings - Fork 435
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Replace more usages of go-autorest #4775
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -19,13 +19,10 @@ package scope | |||||||
import ( | ||||||||
"context" | ||||||||
"reflect" | ||||||||
"strings" | ||||||||
|
||||||||
"github.com/Azure/azure-sdk-for-go/sdk/azcore" | ||||||||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud" | ||||||||
"github.com/Azure/azure-sdk-for-go/sdk/azidentity" | ||||||||
"github.com/Azure/go-autorest/autorest" | ||||||||
"github.com/jongio/azidext/go/azidext" | ||||||||
"github.com/pkg/errors" | ||||||||
corev1 "k8s.io/api/core/v1" | ||||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||||||
|
@@ -40,7 +37,6 @@ const AzureSecretKey = "clientSecret" | |||||||
|
||||||||
// CredentialsProvider defines the behavior for azure identity based credential providers. | ||||||||
type CredentialsProvider interface { | ||||||||
GetAuthorizer(ctx context.Context, tokenCredential azcore.TokenCredential, tokenAudience string) (autorest.Authorizer, error) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My dumb grep also shows this which isn't strictly related I don't think, but is also unused AFAICT: cluster-api-provider-azure/util/azure/azure.go Lines 75 to 76 in d139d07
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also this?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your dumb grep is smarter than I was--thanks! Love to remove dead code. |
||||||||
GetClientID() string | ||||||||
GetClientSecret(ctx context.Context) (string, error) | ||||||||
GetTenantID() string | ||||||||
|
@@ -95,11 +91,6 @@ func NewAzureClusterCredentialsProvider(ctx context.Context, kubeClient client.C | |||||||
}, nil | ||||||||
} | ||||||||
|
||||||||
// GetAuthorizer returns an Azure authorizer based on the provided azure identity. It delegates to AzureCredentialsProvider with AzureCluster metadata. | ||||||||
func (p *AzureClusterCredentialsProvider) GetAuthorizer(ctx context.Context, tokenCredential azcore.TokenCredential, tokenAudience string) (autorest.Authorizer, error) { | ||||||||
return p.AzureCredentialsProvider.GetAuthorizer(ctx, tokenCredential, tokenAudience) | ||||||||
} | ||||||||
|
||||||||
// GetTokenCredential returns an Azure TokenCredential based on the provided azure identity. | ||||||||
func (p *AzureClusterCredentialsProvider) GetTokenCredential(ctx context.Context, resourceManagerEndpoint, activeDirectoryEndpoint, tokenAudience string) (azcore.TokenCredential, error) { | ||||||||
return p.AzureCredentialsProvider.GetTokenCredential(ctx, resourceManagerEndpoint, activeDirectoryEndpoint, tokenAudience, p.AzureCluster.ObjectMeta) | ||||||||
|
@@ -132,11 +123,6 @@ func NewManagedControlPlaneCredentialsProvider(ctx context.Context, kubeClient c | |||||||
}, nil | ||||||||
} | ||||||||
|
||||||||
// GetAuthorizer returns an Azure authorizer based on the provided azure identity. It delegates to AzureCredentialsProvider with AzureManagedControlPlane metadata. | ||||||||
func (p *ManagedControlPlaneCredentialsProvider) GetAuthorizer(ctx context.Context, tokenCredential azcore.TokenCredential, tokenAudience string) (autorest.Authorizer, error) { | ||||||||
return p.AzureCredentialsProvider.GetAuthorizer(ctx, tokenCredential, tokenAudience) | ||||||||
} | ||||||||
|
||||||||
// GetTokenCredential returns an Azure TokenCredential based on the provided azure identity. | ||||||||
func (p *ManagedControlPlaneCredentialsProvider) GetTokenCredential(ctx context.Context, resourceManagerEndpoint, activeDirectoryEndpoint, tokenAudience string) (azcore.TokenCredential, error) { | ||||||||
return p.AzureCredentialsProvider.GetTokenCredential(ctx, resourceManagerEndpoint, activeDirectoryEndpoint, tokenAudience, p.AzureManagedControlPlane.ObjectMeta) | ||||||||
|
@@ -212,18 +198,6 @@ func (p *AzureCredentialsProvider) GetTokenCredential(ctx context.Context, resou | |||||||
return cred, nil | ||||||||
} | ||||||||
|
||||||||
// GetAuthorizer returns an Azure authorizer based on the provided azure identity, cluster metadata, and tokenCredential. | ||||||||
func (p *AzureCredentialsProvider) GetAuthorizer(ctx context.Context, cred azcore.TokenCredential, tokenAudience string) (autorest.Authorizer, error) { | ||||||||
// We must use TokenAudience for StackCloud, otherwise we get an | ||||||||
// AADSTS500011 error from the API | ||||||||
scope := tokenAudience | ||||||||
if !strings.HasSuffix(scope, "/.default") { | ||||||||
scope += "/.default" | ||||||||
} | ||||||||
authorizer := azidext.NewTokenCredentialAdapter(cred, []string{scope}) | ||||||||
return authorizer, nil | ||||||||
} | ||||||||
|
||||||||
// GetClientID returns the Client ID associated with the AzureCredentialsProvider's Identity. | ||||||||
func (p *AzureCredentialsProvider) GetClientID() string { | ||||||||
return p.Identity.Spec.ClientID | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like I should technically point out that constants for these would be good, but since the SDK doesn't even expose these that I can find, I'm not gonna push to do that here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's frustrating that there aren't any constants for these in the SDK. We could define them locally, but I didn't see a good common package to house them at first glance.