Skip to content

Commit

Permalink
fix moduleName parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
jhendrixMSFT committed Nov 6, 2023
1 parent d236ee8 commit 39ad285
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion sdk/azidentity/client_assertion_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func NewClientAssertionCredential(tenantID, clientID string, getAssertion func(c
DisableInstanceDiscovery: options.DisableInstanceDiscovery,
TokenCachePersistenceOptions: options.TokenCachePersistenceOptions,
}
c, err := newConfidentialClient(component+"."+credNameAssertion, tenantID, clientID, credNameAssertion, cred, msalOpts, options.ClientOptions)
c, err := newConfidentialClient(tenantID, clientID, credNameAssertion, cred, msalOpts, options.ClientOptions)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/azidentity/client_certificate_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func NewClientCertificateCredential(tenantID string, clientID string, certs []*x
SendX5C: options.SendCertificateChain,
TokenCachePersistenceOptions: options.TokenCachePersistenceOptions,
}
c, err := newConfidentialClient(component+"."+credNameCert, tenantID, clientID, credNameCert, cred, msalOpts, options.ClientOptions)
c, err := newConfidentialClient(tenantID, clientID, credNameCert, cred, msalOpts, options.ClientOptions)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/azidentity/client_secret_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func NewClientSecretCredential(tenantID string, clientID string, clientSecret st
DisableInstanceDiscovery: options.DisableInstanceDiscovery,
TokenCachePersistenceOptions: options.TokenCachePersistenceOptions,
}
c, err := newConfidentialClient(component+"."+credNameSecret, tenantID, clientID, credNameSecret, cred, msalOpts, options.ClientOptions)
c, err := newConfidentialClient(tenantID, clientID, credNameSecret, cred, msalOpts, options.ClientOptions)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions sdk/azidentity/confidential_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ type confidentialClient struct {
azClient *azcore.Client
}

func newConfidentialClient(clientName, tenantID, clientID, name string, cred confidential.Credential, opts confidentialClientOptions, clientOpts azcore.ClientOptions) (*confidentialClient, error) {
func newConfidentialClient(tenantID, clientID, name string, cred confidential.Credential, opts confidentialClientOptions, clientOpts azcore.ClientOptions) (*confidentialClient, error) {
if !validTenantID(tenantID) {
return nil, errInvalidTenantID
}
host, err := setAuthorityHost(clientOpts.Cloud)
if err != nil {
return nil, err
}
client, err := azcore.NewClient(clientName, version, runtime.PipelineOptions{
client, err := azcore.NewClient(module, version, runtime.PipelineOptions{
Tracing: runtime.TracingOptions{
Namespace: traceNamespace,
},
Expand Down
2 changes: 1 addition & 1 deletion sdk/azidentity/device_code_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func NewDeviceCodeCredential(options *DeviceCodeCredentialOptions) (*DeviceCodeC
Record: cp.AuthenticationRecord,
TokenCachePersistenceOptions: cp.TokenCachePersistenceOptions,
}
c, err := newPublicClient(component+"."+credNameDeviceCode, cp.TenantID, cp.ClientID, credNameDeviceCode, msalOpts, cp.ClientOptions)
c, err := newPublicClient(cp.TenantID, cp.ClientID, credNameDeviceCode, msalOpts, cp.ClientOptions)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/azidentity/interactive_browser_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func NewInteractiveBrowserCredential(options *InteractiveBrowserCredentialOption
RedirectURL: cp.RedirectURL,
TokenCachePersistenceOptions: cp.TokenCachePersistenceOptions,
}
c, err := newPublicClient(component+"."+credNameBrowser, cp.TenantID, cp.ClientID, credNameBrowser, msalOpts, cp.ClientOptions)
c, err := newPublicClient(cp.TenantID, cp.ClientID, credNameBrowser, msalOpts, cp.ClientOptions)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions sdk/azidentity/managed_identity_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func setIMDSRetryOptionDefaults(o *policy.RetryOptions) {
// that are passed into it along with a default pipeline.
// options: ManagedIdentityCredentialOptions configure policies for the pipeline and the authority host that
// will be used to retrieve tokens and authenticate
func newManagedIdentityClient(clientName string, options *ManagedIdentityCredentialOptions) (*managedIdentityClient, error) {
func newManagedIdentityClient(options *ManagedIdentityCredentialOptions) (*managedIdentityClient, error) {
if options == nil {
options = &ManagedIdentityCredentialOptions{}
}
Expand Down Expand Up @@ -150,7 +150,7 @@ func newManagedIdentityClient(clientName string, options *ManagedIdentityCredent
setIMDSRetryOptionDefaults(&cp.Retry)
}

client, err := azcore.NewClient(clientName, version, runtime.PipelineOptions{
client, err := azcore.NewClient(module, version, runtime.PipelineOptions{
Tracing: runtime.TracingOptions{
Namespace: traceNamespace,
},
Expand Down
8 changes: 4 additions & 4 deletions sdk/azidentity/managed_identity_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestManagedIdentityClient_UserAgent(t *testing.T) {
Transport: &mockSTS{}, PerCallPolicies: []policy.Policy{userAgentValidatingPolicy{t: t}},
},
}
client, err := newManagedIdentityClient(miClientName, &options)
client, err := newManagedIdentityClient(&options)
if err != nil {
t.Fatal(err)
}
Expand All @@ -68,7 +68,7 @@ func TestManagedIdentityClient_ApplicationID(t *testing.T) {
},
}
options.Telemetry.ApplicationID = appID
client, err := newManagedIdentityClient(miClientName, &options)
client, err := newManagedIdentityClient(&options)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -98,7 +98,7 @@ func TestManagedIdentityClient_IMDSErrors(t *testing.T) {
srv, close := mock.NewServer(mock.WithTransformAllRequestsToTestServerUrl())
defer close()
srv.SetResponse(mock.WithBody([]byte(test.body)), mock.WithStatusCode(test.code))
client, err := newManagedIdentityClient(miClientName, &ManagedIdentityCredentialOptions{
client, err := newManagedIdentityClient(&ManagedIdentityCredentialOptions{
ClientOptions: azcore.ClientOptions{Transport: srv},
})
if err != nil {
Expand Down Expand Up @@ -158,7 +158,7 @@ func TestManagedIdentityClient_UserAssignedIDWarning(t *testing.T) {
msgs = append(msgs, msg)
}
})
client, err := newManagedIdentityClient(miClientName, &ManagedIdentityCredentialOptions{
client, err := newManagedIdentityClient(&ManagedIdentityCredentialOptions{
ID: id,
})
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions sdk/azidentity/managed_identity_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
)

const credNameManagedIdentity = "ManagedIdentityCredential"
const miClientName = component + "." + credNameManagedIdentity

type managedIdentityIDKind int

Expand Down Expand Up @@ -81,7 +80,7 @@ func NewManagedIdentityCredential(options *ManagedIdentityCredentialOptions) (*M
if options == nil {
options = &ManagedIdentityCredentialOptions{}
}
mic, err := newManagedIdentityClient(miClientName, options)
mic, err := newManagedIdentityClient(options)
if err != nil {
return nil, err
}
Expand All @@ -94,7 +93,7 @@ func NewManagedIdentityCredential(options *ManagedIdentityCredentialOptions) (*M
clientID = options.ID.String()
}
// similarly, it's okay to give MSAL an incorrect tenant because MSAL won't use the value
c, err := newConfidentialClient(miClientName, "common", clientID, credNameManagedIdentity, cred, confidentialClientOptions{}, options.ClientOptions)
c, err := newConfidentialClient("common", clientID, credNameManagedIdentity, cred, confidentialClientOptions{}, options.ClientOptions)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/azidentity/on_behalf_of_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func newOnBehalfOfCredential(tenantID, clientID, userAssertion string, cred conf
DisableInstanceDiscovery: options.DisableInstanceDiscovery,
SendX5C: options.SendCertificateChain,
}
c, err := newConfidentialClient(component+"."+credNameOBO, tenantID, clientID, credNameOBO, cred, opts, options.ClientOptions)
c, err := newConfidentialClient(tenantID, clientID, credNameOBO, cred, opts, options.ClientOptions)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions sdk/azidentity/public_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type publicClient struct {

var errScopeRequired = errors.New("authenticating in this environment requires specifying a scope in TokenRequestOptions")

func newPublicClient(clientName, tenantID, clientID, name string, o publicClientOptions, clientOpts azcore.ClientOptions) (*publicClient, error) {
func newPublicClient(tenantID, clientID, name string, o publicClientOptions, clientOpts azcore.ClientOptions) (*publicClient, error) {
if !validTenantID(tenantID) {
return nil, errInvalidTenantID
}
Expand Down Expand Up @@ -81,7 +81,7 @@ func newPublicClient(clientName, tenantID, clientID, name string, o publicClient
if audience != "" {
defaultScope = []string{audience + defaultSuffix}
}
client, err := azcore.NewClient(clientName, version, runtime.PipelineOptions{
client, err := azcore.NewClient(module, version, runtime.PipelineOptions{
Tracing: runtime.TracingOptions{
Namespace: traceNamespace,
},
Expand Down
2 changes: 1 addition & 1 deletion sdk/azidentity/username_password_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func NewUsernamePasswordCredential(tenantID string, clientID string, username st
TokenCachePersistenceOptions: options.TokenCachePersistenceOptions,
Username: username,
}
c, err := newPublicClient(component+"."+credNameUserPassword, tenantID, clientID, credNameUserPassword, opts, options.ClientOptions)
c, err := newPublicClient(tenantID, clientID, credNameUserPassword, opts, options.ClientOptions)
if err != nil {
return nil, err
}
Expand Down
3 changes: 3 additions & 0 deletions sdk/azidentity/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const (
// UserAgent is the string to be used in the user agent string when making requests.
component = "azidentity"

// module is the fully qualified name of the module used in telemetry and distributed tracing.
module = "github.com/Azure/azure-sdk-for-go/sdk/" + component

// Version is the semantic version (see http://semver.org) of this module.
version = "v1.5.0-beta.2"
)
8 changes: 6 additions & 2 deletions sdk/azidentity/workload_identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
)

const credNameWorkloadIdentity = "WorkloadIdentityCredential"
Expand Down Expand Up @@ -83,7 +84,6 @@ func NewWorkloadIdentityCredential(options *WorkloadIdentityCredentialOptions) (
ClientOptions: options.ClientOptions,
DisableInstanceDiscovery: options.DisableInstanceDiscovery,
}
// TODO: this will incorrectly report ClientAssertionCredential in traces
cred, err := NewClientAssertionCredential(tenantID, clientID, w.getAssertion, &caco)
if err != nil {
return nil, err
Expand All @@ -96,7 +96,11 @@ func NewWorkloadIdentityCredential(options *WorkloadIdentityCredentialOptions) (

// GetToken requests an access token from Microsoft Entra ID. Azure SDK clients call this method automatically.
func (w *WorkloadIdentityCredential) GetToken(ctx context.Context, opts policy.TokenRequestOptions) (azcore.AccessToken, error) {
return w.cred.GetToken(ctx, opts)
var err error
ctx, endSpan := runtime.StartSpan(ctx, credNameWorkloadIdentity+"."+traceOpGetToken, w.cred.client.azClient.Tracer(), nil)
defer func() { endSpan(err) }()
tk, err := w.cred.GetToken(ctx, opts)
return tk, err
}

// getAssertion returns the specified file's content, which is expected to be a Kubernetes service account token.
Expand Down

0 comments on commit 39ad285

Please sign in to comment.