Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cmd/auth/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/databricks/cli/libs/auth"
"github.com/databricks/cli/libs/auth/storage"
"github.com/databricks/cli/libs/auth/u2m"
"github.com/databricks/cli/libs/browser"
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/databrickscfg"
Expand All @@ -21,7 +22,6 @@ import (
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/config"
"github.com/databricks/databricks-sdk-go/config/experimental/auth/authconv"
"github.com/databricks/databricks-sdk-go/credentials/u2m"
"github.com/spf13/cobra"
"golang.org/x/oauth2"
)
Expand All @@ -47,8 +47,7 @@ const (
discoveryFallbackTip = "\n\nTip: you can specify a workspace directly with: databricks auth login --host <url>"
// discoveryHostEnvVar overrides the default https://login.databricks.com
// host used by the discovery login flow. Intended for testing and
// development against non-production environments. See WithDiscoveryHost
// in github.com/databricks/databricks-sdk-go/credentials/u2m.
// development against non-production environments.
discoveryHostEnvVar = "DATABRICKS_DISCOVERY_HOST"
)

Expand Down Expand Up @@ -735,7 +734,8 @@ func discoveryLogin(ctx context.Context, in discoveryLoginInputs) error {
// cluster_id, serverless_compute_id) from a prior login to a different host
// type must be cleared so they don't leak into the new profile. account_id
// and workspace_id are re-added from discovery/introspection results.
clearKeys = append(clearKeys,
clearKeys = append(
clearKeys,
"account_id",
"workspace_id",
databrickscfg.ExperimentalIsUnifiedHostKey,
Expand Down
2 changes: 1 addition & 1 deletion cmd/auth/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import (

"github.com/databricks/cli/libs/auth"
"github.com/databricks/cli/libs/auth/storage"
"github.com/databricks/cli/libs/auth/u2m"
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/databrickscfg/profile"
"github.com/databricks/cli/libs/env"
"github.com/databricks/cli/libs/log"
"github.com/databricks/databricks-sdk-go/credentials/u2m"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down
4 changes: 2 additions & 2 deletions cmd/auth/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/libs/auth"
"github.com/databricks/cli/libs/auth/storage"
"github.com/databricks/cli/libs/auth/u2m"
"github.com/databricks/cli/libs/auth/u2m/cache"
"github.com/databricks/cli/libs/browser"
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/databrickscfg"
Expand All @@ -20,8 +22,6 @@ import (
"github.com/databricks/cli/libs/flags"
"github.com/databricks/cli/libs/log"
"github.com/databricks/databricks-sdk-go/config"
"github.com/databricks/databricks-sdk-go/credentials/u2m"
"github.com/databricks/databricks-sdk-go/credentials/u2m/cache"
"github.com/spf13/cobra"
"golang.org/x/oauth2"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/auth/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (

"github.com/databricks/cli/libs/auth"
"github.com/databricks/cli/libs/auth/storage"
"github.com/databricks/cli/libs/auth/u2m"
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/databrickscfg/profile"
"github.com/databricks/cli/libs/env"
"github.com/databricks/databricks-sdk-go/credentials/u2m"
"github.com/databricks/databricks-sdk-go/httpclient/fixtures"
"github.com/stretchr/testify/assert"
"golang.org/x/oauth2"
Expand Down
2 changes: 1 addition & 1 deletion libs/auth/arguments.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package auth

import (
"github.com/databricks/cli/libs/auth/u2m"
"github.com/databricks/databricks-sdk-go/config"
"github.com/databricks/databricks-sdk-go/credentials/u2m"
)

// WorkspaceIDNone is a sentinel value persisted to .databrickscfg when the
Expand Down
2 changes: 1 addition & 1 deletion libs/auth/arguments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http/httptest"
"testing"

"github.com/databricks/databricks-sdk-go/credentials/u2m"
"github.com/databricks/cli/libs/auth/u2m"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
2 changes: 1 addition & 1 deletion libs/auth/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"errors"

"github.com/databricks/cli/libs/auth/storage"
"github.com/databricks/cli/libs/auth/u2m"
"github.com/databricks/databricks-sdk-go/config"
"github.com/databricks/databricks-sdk-go/config/credentials"
"github.com/databricks/databricks-sdk-go/config/experimental/auth"
"github.com/databricks/databricks-sdk-go/config/experimental/auth/authconv"
"github.com/databricks/databricks-sdk-go/credentials/u2m"
)

// The credentials chain used by the CLI. It is a custom implementation
Expand Down
2 changes: 1 addition & 1 deletion libs/auth/credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"testing"

"github.com/databricks/cli/libs/auth/storage"
"github.com/databricks/cli/libs/auth/u2m"
"github.com/databricks/databricks-sdk-go/config"
"github.com/databricks/databricks-sdk-go/config/experimental/auth"
"github.com/databricks/databricks-sdk-go/credentials/u2m"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/oauth2"
Expand Down
2 changes: 1 addition & 1 deletion libs/auth/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"net/http"
"strings"

"github.com/databricks/cli/libs/auth/u2m"
"github.com/databricks/databricks-sdk-go/apierr"
"github.com/databricks/databricks-sdk-go/config"
"github.com/databricks/databricks-sdk-go/credentials/u2m"
)

// Auth type names returned by credential providers.
Expand Down
12 changes: 6 additions & 6 deletions libs/auth/storage/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"errors"
"fmt"

"github.com/databricks/cli/libs/auth/u2m"
"github.com/databricks/cli/libs/auth/u2m/cache"
"github.com/databricks/cli/libs/databrickscfg"
"github.com/databricks/cli/libs/env"
"github.com/databricks/cli/libs/log"
"github.com/databricks/databricks-sdk-go/credentials/u2m"
"github.com/databricks/databricks-sdk-go/credentials/u2m/cache"
)

// storeFactories bundles the constructors ResolveStore depends on. Extracted
Expand Down Expand Up @@ -46,9 +46,9 @@ func defaultStoreFactories() storeFactories {
// fallback does not persist auth_storage = plaintext to [__settings__];
// pinning happens only on successful login.
//
// Every CLI code path that calls u2m.NewPersistentAuth must route the result
// through u2m.WithTokenCache, otherwise the SDK defaults to the file cache
// and splits the user's tokens across two backends.
// Every CLI code path that calls u2m.NewPersistentAuth must supply the cache
// returned by this package, otherwise U2M uses an in-memory cache and bypasses
// the user's configured storage backend.
func ResolveStore(ctx context.Context, override StorageMode) (Store, StorageMode, error) {
return resolveStoreForReadWith(ctx, override, defaultStoreFactories())
}
Expand All @@ -75,7 +75,7 @@ func ResolveStoreForLogin(ctx context.Context, override StorageMode) (Store, Sto
return resolveStoreForLoginWith(ctx, override, defaultStoreFactories())
}

// OAuthTokenCache adapts a CLI Store to the SDK's u2m_cache.TokenCache for the
// OAuthTokenCache adapts a CLI Store to the U2M cache.TokenCache for the
// U2M PersistentAuth flow, applying the not-found hint so a cache miss carries
// actionable "run databricks auth login" guidance. Use on read and credential
// paths. M2M/OIDC callers use the CLI Store directly and must not route through
Expand Down
2 changes: 1 addition & 1 deletion libs/auth/storage/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"path/filepath"
"testing"

"github.com/databricks/cli/libs/auth/u2m"
"github.com/databricks/cli/libs/databrickscfg"
"github.com/databricks/cli/libs/env"
"github.com/databricks/databricks-sdk-go/credentials/u2m"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/oauth2"
Expand Down
6 changes: 3 additions & 3 deletions libs/auth/storage/dual_writing_cache.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package storage

import (
"github.com/databricks/databricks-sdk-go/credentials/u2m"
u2m_cache "github.com/databricks/databricks-sdk-go/credentials/u2m/cache"
"github.com/databricks/cli/libs/auth/u2m"
u2m_cache "github.com/databricks/cli/libs/auth/u2m/cache"
"golang.org/x/oauth2"
)

Expand All @@ -12,7 +12,7 @@ import (
// implemented inside PersistentAuth.dualWrite in the SDK, now moved
// caller-side per the cache-ownership split between SDK and CLI.
//
// Mirroring happens inside Store, so every SDK-internal write (Challenge,
// Mirroring happens inside Store, so every U2M-internal write (Challenge,
// refresh, discovery) dual-writes without requiring each call site to invoke
// a helper explicitly.
type DualWritingTokenCache struct {
Expand Down
4 changes: 2 additions & 2 deletions libs/auth/storage/dual_writing_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"sync"
"testing"

"github.com/databricks/databricks-sdk-go/credentials/u2m"
u2m_cache "github.com/databricks/databricks-sdk-go/credentials/u2m/cache"
"github.com/databricks/cli/libs/auth/u2m"
u2m_cache "github.com/databricks/cli/libs/auth/u2m/cache"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/oauth2"
Expand Down
2 changes: 1 addition & 1 deletion libs/auth/storage/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

// keyringServiceName is the service name used for every entry the CLI writes
// to the OS-native secure store. The account field carries the per-entry
// cache key the SDK passes through TokenCache.Store / Lookup.
// cache key the U2M manager passes through TokenCache.Store / Lookup.
const keyringServiceName = "databricks-cli"

// keyringProbeAccountPrefix is prefixed onto a per-call random suffix to form
Expand Down
6 changes: 3 additions & 3 deletions libs/auth/storage/not_found_hint.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"os"
"path/filepath"

"github.com/databricks/cli/libs/auth/u2m/cache"
"github.com/databricks/cli/libs/env"
"github.com/databricks/databricks-sdk-go/credentials/u2m/cache"
"golang.org/x/oauth2"
)

Expand All @@ -19,7 +19,7 @@ import (
// their cached credentials are no longer being read.
//
// errors.Is(err, cache.ErrNotFound) continues to return true because the
// wrap uses %w; the SDK's branches on ErrNotFound still fire.
// wrap uses %w; PersistentAuth's branches on ErrNotFound still fire.
//
// Store is delegated unchanged; only Lookup needs the message polish.
type notFoundHintCache struct {
Expand All @@ -45,7 +45,7 @@ func (c *notFoundHintCache) Lookup(key string) (*oauth2.Token, error) {

// notFoundHint replaces cache.ErrNotFound's terse "token not found" string
// with an actionable message while still satisfying errors.Is(err,
// cache.ErrNotFound). The SDK's loadToken wraps every cache error with
// cache.ErrNotFound). PersistentAuth.loadToken wraps every cache error with
// "cache: %w", and fmt.Errorf("...: %w", ErrNotFound) would tack the
// original "token not found" onto the end of our hint, producing
// "cache: <hint>: token not found". A custom type lets us own the
Expand Down
2 changes: 1 addition & 1 deletion libs/auth/storage/not_found_hint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"path/filepath"
"testing"

"github.com/databricks/databricks-sdk-go/credentials/u2m/cache"
"github.com/databricks/cli/libs/auth/u2m/cache"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/oauth2"
Expand Down
45 changes: 0 additions & 45 deletions libs/auth/storage/sdku2m.go

This file was deleted.

6 changes: 3 additions & 3 deletions libs/auth/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
// ErrNotFound is returned by Store.Lookup when no entry exists for the key, or
// when a stored entry cannot be decoded by this CLI version (an unknown format
// is treated as a miss so the caller re-mints rather than failing). It is the
// CLI-owned counterpart to the SDK's u2m_cache.ErrNotFound; the adapter in
// ToU2MTokenCache translates between the two.
// CLI-owned counterpart to the U2M cache.ErrNotFound; the adapter in
// ToU2MTokenCache translates between the storage and OAuth layers.
var ErrNotFound = errors.New("token not found")

// Entry is the value held in the CLI token store. It wraps the credential so
Expand All @@ -33,7 +33,7 @@ type Entry struct {
// policy of its own. Implementations are the plaintext file cache and the OS
// keyring cache. The interface is owned by the CLI rather than the SDK so the
// entry schema can evolve (metadata, per-entry resilience) without being
// constrained by the SDK's U2M-internal u2m_cache.TokenCache, which only
// constrained by the U2M-internal cache.TokenCache, which only
// carries a bare *oauth2.Token.
type Store interface {
// Put writes e under key, replacing any existing entry.
Expand Down
43 changes: 43 additions & 0 deletions libs/auth/storage/u2m.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package storage

import (
"errors"

"github.com/databricks/cli/libs/auth/u2m/cache"
"golang.org/x/oauth2"
)

// ToU2MTokenCache adapts a CLI Store to the U2M cache.TokenCache interface.
// The Store(key, nil) delete convention maps to Store.Delete.
func ToU2MTokenCache(s Store) cache.TokenCache {
return &u2mTokenCache{store: s}
}

// u2mTokenCache is the ToU2MTokenCache adapter.
type u2mTokenCache struct {
store Store
}

// Store implements cache.TokenCache. A nil token is the U2M delete
// signal; everything else is a plain put with no metadata.
func (tc *u2mTokenCache) Store(key string, t *oauth2.Token) error {
if t == nil {
return tc.store.Delete(key)
}
return tc.store.Put(key, Entry{Token: t})
}

// Lookup implements cache.TokenCache, translating the storage miss sentinel
// to the U2M package's sentinel.
func (tc *u2mTokenCache) Lookup(key string) (*oauth2.Token, error) {
e, err := tc.store.Lookup(key)
if err != nil {
if errors.Is(err, ErrNotFound) {
return nil, cache.ErrNotFound
}
return nil, err
}
return e.Token, nil
}

var _ cache.TokenCache = (*u2mTokenCache)(nil)
Loading
Loading