Skip to content

Commit

Permalink
Unexport AzureCLITokenProvider (Azure#15427)
Browse files Browse the repository at this point in the history
  • Loading branch information
chlowell authored and vindicatesociety committed Sep 18, 2021
1 parent a0946c6 commit a02c91b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 2 additions & 0 deletions sdk/azidentity/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
### Features Added

### Breaking Changes
* Unexported `AzureCLICredentialOptions.TokenProvider` and its type,
`AzureCLITokenProvider`

### Bug Fixes

Expand Down
14 changes: 7 additions & 7 deletions sdk/azidentity/azure_cli_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ import (
azruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
)

// AzureCLITokenProvider can be used to supply the AzureCLICredential with an alternate token provider
type AzureCLITokenProvider func(ctx context.Context, resource string) ([]byte, error)
// used by tests to fake invoking the CLI
type azureCLITokenProvider func(ctx context.Context, resource string) ([]byte, error)

// AzureCLICredentialOptions contains options used to configure the AzureCLICredential
// All zero-value fields will be initialized with their default values.
type AzureCLICredentialOptions struct {
TokenProvider AzureCLITokenProvider
tokenProvider azureCLITokenProvider
}

// init returns an instance of AzureCLICredentialOptions initialized with default values.
func (o *AzureCLICredentialOptions) init() {
if o.TokenProvider == nil {
o.TokenProvider = defaultTokenProvider()
if o.tokenProvider == nil {
o.tokenProvider = defaultTokenProvider()
}
}

// AzureCLICredential enables authentication to Azure Active Directory using the Azure CLI command "az account get-access-token".
type AzureCLICredential struct {
tokenProvider AzureCLITokenProvider
tokenProvider azureCLITokenProvider
}

// NewAzureCLICredential constructs a new AzureCLICredential with the details needed to authenticate against Azure Active Directory
Expand All @@ -50,7 +50,7 @@ func NewAzureCLICredential(options *AzureCLICredentialOptions) (*AzureCLICredent
}
cp.init()
return &AzureCLICredential{
tokenProvider: cp.TokenProvider,
tokenProvider: cp.tokenProvider,
}, nil
}

Expand Down
6 changes: 3 additions & 3 deletions sdk/azidentity/azure_cli_credential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (

func TestAzureCLICredential_GetTokenSuccess(t *testing.T) {
options := AzureCLICredentialOptions{}
options.TokenProvider = mockCLITokenProviderSuccess
options.tokenProvider = mockCLITokenProviderSuccess
cred, err := NewAzureCLICredential(&options)
if err != nil {
t.Fatalf("Unable to create credential. Received: %v", err)
Expand All @@ -48,7 +48,7 @@ func TestAzureCLICredential_GetTokenSuccess(t *testing.T) {

func TestAzureCLICredential_GetTokenInvalidToken(t *testing.T) {
options := AzureCLICredentialOptions{}
options.TokenProvider = mockCLITokenProviderFailure
options.tokenProvider = mockCLITokenProviderFailure
cred, err := NewAzureCLICredential(&options)
if err != nil {
t.Fatalf("Unable to create credential. Received: %v", err)
Expand All @@ -64,7 +64,7 @@ func TestBearerPolicy_AzureCLICredential(t *testing.T) {
defer close()
srv.AppendResponse(mock.WithStatusCode(http.StatusOK))
options := AzureCLICredentialOptions{}
options.TokenProvider = mockCLITokenProviderSuccess
options.tokenProvider = mockCLITokenProviderSuccess
cred, err := NewAzureCLICredential(&options)
if err != nil {
t.Fatalf("Did not expect an error but received: %v", err)
Expand Down

0 comments on commit a02c91b

Please sign in to comment.