in pkg/internal/token/usernamepasswordcredential.go [20:62]
func newUsernamePasswordCredential(opts *Options, record azidentity.AuthenticationRecord) (CredentialProvider, error) {
if opts.ClientID == "" {
return nil, fmt.Errorf("client ID cannot be empty")
}
if opts.TenantID == "" {
return nil, fmt.Errorf("tenant ID cannot be empty")
}
if opts.Username == "" {
return nil, fmt.Errorf("username cannot be empty")
}
if opts.Password == "" {
return nil, fmt.Errorf("password cannot be empty")
}
var (
c azidentity.Cache
err error
)
if opts.UsePersistentCache {
c, err = cache.New(nil)
if err != nil {
klog.V(5).Infof("failed to create cache: %v", err)
}
}
azOpts := &azidentity.UsernamePasswordCredentialOptions{
ClientOptions: azcore.ClientOptions{Cloud: opts.GetCloudConfiguration()},
AuthenticationRecord: record,
Cache: c,
DisableInstanceDiscovery: opts.DisableInstanceDiscovery,
}
if opts.httpClient != nil {
azOpts.ClientOptions.Transport = opts.httpClient
}
cred, err := azidentity.NewUsernamePasswordCredential(
opts.TenantID, opts.ClientID, opts.Username, opts.Password,
azOpts)
if err != nil {
return nil, fmt.Errorf("failed to create username password credential: %w", err)
}
return &UsernamePasswordCredential{cred: cred}, nil
}