Skip to content

Commit 9830d52

Browse files
committed
fix comments after refactoring
1 parent b806338 commit 9830d52

17 files changed

+131
-132
lines changed

credentials_provider.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ type entraidCredentialsProvider struct {
2626
rwLock sync.RWMutex
2727
}
2828

29-
// onTokenNext is a method that is called when the token manager receives a new manager.
29+
// onTokenNext is a method that is called when the token manager receives a new token.
3030
func (e *entraidCredentialsProvider) onTokenNext(t *token.Token) {
3131
e.rwLock.RLock()
3232
defer e.rwLock.RUnlock()
33-
// Notify all listeners with the new manager.
33+
// Notify all listeners with the new token.
3434
for _, listener := range e.listeners {
3535
listener.OnNext(t)
3636
}
@@ -64,7 +64,7 @@ func (e *entraidCredentialsProvider) Subscribe(listener auth.CredentialsListener
6464
}
6565

6666
if !alreadySubscribed {
67-
// Get the manager from the identity provider.
67+
// add new listener
6868
e.listeners = append(e.listeners, listener)
6969
}
7070
e.rwLock.Unlock()
@@ -105,7 +105,7 @@ func (e *entraidCredentialsProvider) Subscribe(listener auth.CredentialsListener
105105

106106
// newCredentialsProvider creates a new credentials provider.
107107
// It takes a TokenManager and CredentialProviderOptions as arguments and returns a StreamingCredentialsProvider interface.
108-
// The TokenManager is used to obtain the manager, and the CredentialProviderOptions contains options for the credentials provider.
108+
// The TokenManager is used to obtain the token, and the CredentialProviderOptions contains options for the credentials provider.
109109
// The credentials provider is responsible for managing the credentials and refreshing them when necessary.
110110
// It returns an error if the token manager cannot be started.
111111
func newCredentialsProvider(tokenManager manager.TokenManager, options CredentialsProviderOptions) (auth.StreamingCredentialsProvider, error) {

identity/authority_configuration.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ import "fmt"
44

55
const (
66
// AuthorityTypeDefault is the default authority type.
7-
// This is used to specify the authority type when requesting a manager.
7+
// This is used to specify the authority type when requesting a token.
88
AuthorityTypeDefault = "default"
99
// AuthorityTypeMultiTenant is the multi-tenant authority type.
10-
// This is used to specify the multi-tenant authority type when requesting a manager.
11-
// This type of authority is used to authenticate the identity when requesting a manager.
10+
// This is used to specify the multi-tenant authority type when requesting a token.
11+
// This type of authority is used to authenticate the identity when requesting a token.
1212
AuthorityTypeMultiTenant = "multi-tenant"
1313
// AuthorityTypeCustom is the custom authority type.
14-
// This is used to specify the custom authority type when requesting a manager.
14+
// This is used to specify the custom authority type when requesting a token.
1515
AuthorityTypeCustom = "custom"
1616
)
1717

1818
// AuthorityConfiguration represents the authority configuration for the identity provider.
19-
// It is used to configure the authority type and authority URL when requesting a manager.
19+
// It is used to configure the authority type and authority URL when requesting a token.
2020
type AuthorityConfiguration struct {
2121
// AuthorityType is the type of authority used to authenticate with the identity provider.
2222
// This can be either "default", "multi-tenant", or "custom".
@@ -28,7 +28,7 @@ type AuthorityConfiguration struct {
2828
Authority string
2929

3030
// TenantID is the tenant ID of the identity provider.
31-
// This is used to identify the tenant when requesting a manager.
31+
// This is used to identify the tenant when requesting a token.
3232
// This is typically the ID of the Azure Active Directory tenant.
3333
TenantID string
3434
}

identity/azure_default_identity_provider.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
type DefaultAzureIdentityProviderOptions struct {
1515
// AzureOptions is the options used to configure the Azure identity provider.
1616
AzureOptions *azidentity.DefaultAzureCredentialOptions
17-
// Scopes is the list of scopes used to request a manager from the identity provider.
17+
// Scopes is the list of scopes used to request a token from the identity provider.
1818
Scopes []string
1919

2020
// credFactory is a factory for creating the default Azure credential.
@@ -56,8 +56,8 @@ func NewDefaultAzureIdentityProvider(opts DefaultAzureIdentityProviderOptions) (
5656
}, nil
5757
}
5858

59-
// RequestToken requests a manager from the Azure Default Identity provider.
60-
// It returns the manager, the expiration time, and an error if any.
59+
// RequestToken requests a token from the Azure Default Identity provider.
60+
// It returns the token, the expiration time, and an error if any.
6161
func (a *DefaultAzureIdentityProvider) RequestToken() (shared.IdentityProviderResponse, error) {
6262
credFactory := a.credFactory
6363
if credFactory == nil {
@@ -70,7 +70,7 @@ func (a *DefaultAzureIdentityProvider) RequestToken() (shared.IdentityProviderRe
7070

7171
token, err := cred.GetToken(context.TODO(), policy.TokenRequestOptions{Scopes: a.scopes})
7272
if err != nil {
73-
return nil, fmt.Errorf("failed to get manager: %w", err)
73+
return nil, fmt.Errorf("failed to get token: %w", err)
7474
}
7575

7676
return shared.NewIDPResponse(shared.ResponseTypeAccessToken, &token)

identity/azure_default_identity_provider_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ func TestAzureDefaultIdentityProvider_RequestToken(t *testing.T) {
3636
t.Fatalf("failed to create DefaultAzureIdentityProvider: %v", err)
3737
}
3838

39-
// Request a manager from the provider in incorrect environment
39+
// Request a token from the provider in incorrect environment
4040
// should fail.
4141
token, err := provider.RequestToken()
42-
assert.Nil(t, token, "manager should be nil")
43-
assert.Error(t, err, "failed to request manager")
42+
assert.Nil(t, token, "token should be nil")
43+
assert.Error(t, err, "failed to request token")
4444

4545
// use mockAzureCredential to simulate the environment
4646
mToken := azcore.AccessToken{
@@ -52,10 +52,10 @@ func TestAzureDefaultIdentityProvider_RequestToken(t *testing.T) {
5252
mCredFactory.On("NewDefaultAzureCredential", mock.Anything).Return(mCreds, nil)
5353
provider.credFactory = mCredFactory
5454
token, err = provider.RequestToken()
55-
assert.NotNil(t, token, "manager should not be nil")
56-
assert.NoError(t, err, "failed to request manager")
57-
assert.Equal(t, shared.ResponseTypeAccessToken, token.Type(), "manager type should be access manager")
58-
assert.Equal(t, mToken, token.AccessToken(), "access manager should be equal to testJWTToken")
55+
assert.NotNil(t, token, "token should not be nil")
56+
assert.NoError(t, err, "failed to request token")
57+
assert.Equal(t, shared.ResponseTypeAccessToken, token.Type(), "token type should be access token")
58+
assert.Equal(t, mToken, token.AccessToken(), "access token should be equal to testJWTToken")
5959
}
6060

6161
func TestAzureDefaultIdentityProvider_RequestTokenWithScopes(t *testing.T) {
@@ -69,10 +69,10 @@ func TestAzureDefaultIdentityProvider_RequestTokenWithScopes(t *testing.T) {
6969
}
7070

7171
t.Run("RequestToken with custom scopes", func(t *testing.T) {
72-
// Request a manager from the provider
72+
// Request a token from the provider
7373
token, err := provider.RequestToken()
74-
assert.Nil(t, token, "manager should be nil")
75-
assert.Error(t, err, "failed to request manager")
74+
assert.Nil(t, token, "token should be nil")
75+
assert.Error(t, err, "failed to request token")
7676

7777
// use mockAzureCredential to simulate the environment
7878
mToken := azcore.AccessToken{
@@ -84,18 +84,18 @@ func TestAzureDefaultIdentityProvider_RequestTokenWithScopes(t *testing.T) {
8484
mCredFactory.On("NewDefaultAzureCredential", mock.Anything).Return(mCreds, nil)
8585
provider.credFactory = mCredFactory
8686
token, err = provider.RequestToken()
87-
assert.NotNil(t, token, "manager should not be nil")
88-
assert.NoError(t, err, "failed to request manager")
89-
assert.Equal(t, shared.ResponseTypeAccessToken, token.Type(), "manager type should be access manager")
90-
assert.Equal(t, mToken, token.AccessToken(), "access manager should be equal to testJWTToken")
87+
assert.NotNil(t, token, "token should not be nil")
88+
assert.NoError(t, err, "failed to request token")
89+
assert.Equal(t, shared.ResponseTypeAccessToken, token.Type(), "token type should be access token")
90+
assert.Equal(t, mToken, token.AccessToken(), "access token should be equal to testJWTToken")
9191
})
9292
t.Run("RequestToken with error from credFactory", func(t *testing.T) {
9393
// use mockAzureCredential to simulate the environment
9494
mCredFactory := &mockCredFactory{}
9595
mCredFactory.On("NewDefaultAzureCredential", mock.Anything).Return(nil, assert.AnError)
9696
provider.credFactory = mCredFactory
9797
token, err := provider.RequestToken()
98-
assert.Nil(t, token, "manager should be nil")
99-
assert.Error(t, err, "failed to request manager")
98+
assert.Nil(t, token, "token should be nil")
99+
assert.Error(t, err, "failed to request token")
100100
})
101101
}

identity/confidential_identity_provider.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type ConfidentialIdentityProviderOptions struct {
2727
// ClientPrivateKey is the private key used to authenticate with the identity provider.
2828
ClientPrivateKey crypto.PrivateKey
2929

30-
// Scopes is the list of scopes used to request a manager from the identity provider.
30+
// Scopes is the list of scopes used to request a token from the identity provider.
3131
Scopes []string
3232

3333
// Authority is the authority used to authenticate with the identity provider.
@@ -46,10 +46,10 @@ type ConfidentialIdentityProvider struct {
4646
// credential is the credential used to authenticate with the identity provider.
4747
credential confidential.Credential
4848

49-
// scopes is the list of scopes used to request a manager from the identity provider.
49+
// scopes is the list of scopes used to request a token from the identity provider.
5050
scopes []string
5151

52-
// client confidential is the client used to request a manager from the identity provider.
52+
// client confidential is the client used to request a token from the identity provider.
5353
client confidentialTokenClient
5454
}
5555

@@ -81,7 +81,7 @@ func (d *defaultConfidentialCredFactory) NewCredFromCert(clientCert []*x509.Cert
8181
}
8282

8383
// NewConfidentialIdentityProvider creates a new confidential identity provider.
84-
// It is used to configure the identity provider when requesting a manager.
84+
// It is used to configure the identity provider when requesting a token.
8585
// It is used to specify the client ID, tenant ID, and scopes for the identity.
8686
// It is also used to specify the type of credentials used to authenticate with the identity provider.
8787
// The credentials can be either a client secret or a client certificate.
@@ -153,7 +153,7 @@ func NewConfidentialIdentityProvider(opts ConfidentialIdentityProviderOptions) (
153153
}, nil
154154
}
155155

156-
// RequestToken requests a manager from the identity provider.
156+
// RequestToken requests a token from the identity provider.
157157
// It returns the identity provider response, including the auth result.
158158
func (c *ConfidentialIdentityProvider) RequestToken() (shared.IdentityProviderResponse, error) {
159159
if c.client == nil {

identity/identity_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/stretchr/testify/mock"
1313
)
1414

15-
// testJWTToken is a JWT manager for testing
15+
// testJWTToken is a JWT token for testing
1616
//
1717
// {
1818
// "iss": "test jwt",

identity/managed_identity_provider.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,34 @@ type ManagedIdentityClient interface {
1919
}
2020

2121
// ManagedIdentityProviderOptions represents the options for the managed identity provider.
22-
// It is used to configure the identity provider when requesting a manager.
22+
// It is used to configure the identity provider when requesting a token.
2323
type ManagedIdentityProviderOptions struct {
2424
// UserAssignedClientID is the client ID of the user assigned identity.
25-
// This is used to identify the identity when requesting a manager.
25+
// This is used to identify the identity when requesting a token.
2626
UserAssignedClientID string
2727
// ManagedIdentityType is the type of managed identity.
2828
// This can be either SystemAssigned or UserAssigned.
2929
ManagedIdentityType string
3030
// Scopes is a list of scopes that the identity has access to.
31-
// This is used to specify the permissions that the identity has when requesting a manager.
31+
// This is used to specify the permissions that the identity has when requesting a token.
3232
Scopes []string
3333
}
3434

3535
// ManagedIdentityProvider represents a managed identity provider.
3636
type ManagedIdentityProvider struct {
3737
// userAssignedClientID is the client ID of the user assigned identity.
38-
// This is used to identify the identity when requesting a manager.
38+
// This is used to identify the identity when requesting a token.
3939
userAssignedClientID string
4040

4141
// managedIdentityType is the type of managed identity.
4242
// This can be either SystemAssigned or UserAssigned.
4343
managedIdentityType string
4444

4545
// scopes is a list of scopes that the identity has access to.
46-
// This is used to specify the permissions that the identity has when requesting a manager.
46+
// This is used to specify the permissions that the identity has when requesting a token.
4747
scopes []string
4848

49-
// client is the managed identity client used to request a manager.
49+
// client is the managed identity client used to request a token.
5050
client ManagedIdentityClient
5151
}
5252

@@ -60,7 +60,7 @@ func (c *realManagedIdentityClient) AcquireToken(ctx context.Context, resource s
6060
}
6161

6262
// NewManagedIdentityProvider creates a new managed identity provider for Azure with managed identity.
63-
// It is used to configure the identity provider when requesting a manager.
63+
// It is used to configure the identity provider when requesting a token.
6464
func NewManagedIdentityProvider(opts ManagedIdentityProviderOptions) (*ManagedIdentityProvider, error) {
6565
var client ManagedIdentityClient
6666

@@ -72,7 +72,7 @@ func NewManagedIdentityProvider(opts ManagedIdentityProviderOptions) (*ManagedId
7272
case SystemAssignedIdentity:
7373
// SystemAssignedIdentity is the type of identity that is automatically managed by Azure.
7474
// This type of identity is automatically created and managed by Azure.
75-
// It is used to authenticate the identity when requesting a manager.
75+
// It is used to authenticate the identity when requesting a token.
7676
miClient, err := mi.New(mi.SystemAssigned())
7777
if err != nil {
7878
return nil, fmt.Errorf("couldn't create managed identity client: %w", err)
@@ -99,7 +99,7 @@ func NewManagedIdentityProvider(opts ManagedIdentityProviderOptions) (*ManagedId
9999
}, nil
100100
}
101101

102-
// RequestToken requests a manager from the managed identity provider.
102+
// RequestToken requests a token from the managed identity provider.
103103
// It returns IdentityProviderResponse, which contains the Acc and the expiration time.
104104
func (m *ManagedIdentityProvider) RequestToken() (shared.IdentityProviderResponse, error) {
105105
if m.client == nil {
@@ -113,11 +113,11 @@ func (m *ManagedIdentityProvider) RequestToken() (shared.IdentityProviderRespons
113113
if len(m.scopes) > 0 {
114114
resource = m.scopes[0]
115115
}
116-
// acquire manager using the managed identity client
116+
// acquire token using the managed identity client
117117
// the resource is the URL of the resource that the identity has access to
118118
authResult, err := m.client.AcquireToken(context.TODO(), resource)
119119
if err != nil {
120-
return nil, fmt.Errorf("coudn't acquire manager: %w", err)
120+
return nil, fmt.Errorf("coudn't acquire token: %w", err)
121121
}
122122

123123
return shared.NewIDPResponse(shared.ResponseTypeAuthResult, &authResult)

identity/managed_identity_provider_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func TestRequestToken_ErrorCases(t *testing.T) {
174174
m.On("AcquireToken", mock.Anything, RedisResource).
175175
Return(public.AuthResult{}, errors.New("failed to acquire token"))
176176
},
177-
expectedError: "coudn't acquire manager: failed to acquire token",
177+
expectedError: "coudn't acquire token: failed to acquire token",
178178
},
179179
{
180180
name: "AcquireToken fails with custom resource",
@@ -186,7 +186,7 @@ func TestRequestToken_ErrorCases(t *testing.T) {
186186
m.On("AcquireToken", mock.Anything, "custom-resource").
187187
Return(public.AuthResult{}, errors.New("failed to acquire token"))
188188
},
189-
expectedError: "coudn't acquire manager: failed to acquire token",
189+
expectedError: "coudn't acquire token: failed to acquire token",
190190
},
191191
{
192192
name: "AcquireToken fails with invalid resource",
@@ -198,7 +198,7 @@ func TestRequestToken_ErrorCases(t *testing.T) {
198198
m.On("AcquireToken", mock.Anything, "invalid-resource").
199199
Return(public.AuthResult{}, errors.New("invalid resource"))
200200
},
201-
expectedError: "coudn't acquire manager: invalid resource",
201+
expectedError: "coudn't acquire token: invalid resource",
202202
},
203203
}
204204

identity/providers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ const (
1414
ClientCertificateCredentialType = "ClientCertificate"
1515

1616
// RedisScopeDefault is the default scope for Redis.
17-
// This is used to specify the scope that the identity has access to when requesting a manager.
17+
// This is used to specify the scope that the identity has access to when requesting a token.
1818
// The scope is typically the URL of the resource that the identity has access to.
1919
RedisScopeDefault = "https://redis.azure.com/.default"
2020

2121
// RedisResource is the default resource for Redis.
22-
// This is used to specify the resource that the identity has access to when requesting a manager.
22+
// This is used to specify the resource that the identity has access to when requesting a token.
2323
// The resource is typically the URL of the resource that the identity has access to.
2424
RedisResource = "https://redis.azure.com"
2525
)

manager/defaults.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ func defaultRetryOptionsOr(retryOptions RetryOptions) RetryOptions {
6161
return retryOptions
6262
}
6363

64-
// defaultIdentityProviderResponseParserOr returns the default manager parser if the provided manager parser is not set.
65-
// It sets the default manager parser to the defaultIdentityProviderResponseParser function.
66-
// The default manager parser is used to parse the raw manager and return a Token object.
64+
// defaultIdentityProviderResponseParserOr returns the default token parser if the provided token parser is not set.
65+
// It sets the default token parser to the defaultIdentityProviderResponseParser function.
66+
// The default token parser is used to parse the raw token and return a Token object.
6767
func defaultIdentityProviderResponseParserOr(idpResponseParser shared.IdentityProviderResponseParser) shared.IdentityProviderResponseParser {
6868
if idpResponseParser == nil {
6969
return &defaultIdentityProviderResponseParser{}
@@ -82,9 +82,9 @@ func defaultTokenManagerOptionsOr(options TokenManagerOptions) TokenManagerOptio
8282

8383
type defaultIdentityProviderResponseParser struct{}
8484

85-
// ParseResponse parses the response from the identity provider and extracts the manager.
85+
// ParseResponse parses the response from the identity provider and extracts the token.
8686
// It takes an IdentityProviderResponse as an argument and returns a Token and an error if any.
87-
// The IdentityProviderResponse contains the raw manager and the expiration time.
87+
// The IdentityProviderResponse contains the raw token and the expiration time.
8888
func (*defaultIdentityProviderResponseParser) ParseResponse(response shared.IdentityProviderResponse) (*token.Token, error) {
8989
var username, password, rawToken string
9090
var expiresOn time.Time
@@ -106,7 +106,7 @@ func (*defaultIdentityProviderResponseParser) ParseResponse(response shared.Iden
106106
if response.Type() == shared.ResponseTypeAccessToken {
107107
accessToken := response.AccessToken()
108108
if accessToken.Token == "" {
109-
return nil, fmt.Errorf("access manager is empty")
109+
return nil, fmt.Errorf("access token is empty")
110110
}
111111
token = accessToken.Token
112112
expiresOn = accessToken.ExpiresOn.UTC()
@@ -117,10 +117,10 @@ func (*defaultIdentityProviderResponseParser) ParseResponse(response shared.Iden
117117
Oid string `json:"oid,omitempty"`
118118
}{}
119119

120-
// jwt manager should be verified from the identity provider
120+
// jwt token should be verified from the identity provider
121121
_, _, err := jwt.NewParser().ParseUnverified(token, &claims)
122122
if err != nil {
123-
return nil, fmt.Errorf("failed to parse jwt manager: %w", err)
123+
return nil, fmt.Errorf("failed to parse jwt token: %w", err)
124124
}
125125
rawToken = token
126126
username = claims.Oid
@@ -144,7 +144,7 @@ func (*defaultIdentityProviderResponseParser) ParseResponse(response shared.Iden
144144
return nil, fmt.Errorf("expires on is in the past")
145145
}
146146

147-
// parse manager as jwt manager and get claims
147+
// parse token as jwt token and get claims
148148
return token.New(
149149
username,
150150
password,

0 commit comments

Comments
 (0)