Skip to content

Commit 35e4870

Browse files
committed
feat: add timeout to getting azure default credentials
Signed-off-by: Matthew H. Irby <[email protected]>
1 parent 9a7f129 commit 35e4870

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

internal/command/client.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"net/http"
2222
"strings"
23+
"time"
2324

2425
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
2526
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
@@ -107,6 +108,10 @@ type azure struct {
107108
func (a *azure) GetAccessToken(ctx context.Context) (string, error) {
108109
log := log.FromContext(ctx)
109110

111+
// Try Azure with a short timeout
112+
timeoutCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
113+
defer cancel()
114+
110115
// To prevent clogging logs every time JWT is generated
111116
initializing := a.cred == nil
112117

@@ -122,7 +127,7 @@ func (a *azure) GetAccessToken(ctx context.Context) (string, error) {
122127
log.Info(fmt.Sprintf("generating Default Azure Credentials with scopes %s", strings.Join(a.scopes, " ")))
123128

124129
// Request a token with the provided scopes
125-
token, err := a.cred.GetToken(ctx, policy.TokenRequestOptions{
130+
token, err := a.cred.GetToken(timeoutCtx, policy.TokenRequestOptions{
126131
Scopes: a.scopes,
127132
})
128133
if err != nil {

0 commit comments

Comments
 (0)