MCPcopy Index your code
hub / github.com/coder/coder / ensureTokenBackend

Method ensureTokenBackend

cli/root.go:881–901  ·  view source on GitHub ↗

ensureTokenBackend returns the session token storage backend, creating it if necessary. This must be called after flags are parsed so we can respect the value of the --use-keyring flag.

()

Source from the content-addressed store, hash-verified

879// This must be called after flags are parsed so we can respect the value of the --use-keyring
880// flag.
881func (r *RootCmd) ensureTokenBackend() sessionstore.Backend {
882 if r.tokenBackend == nil {
883 // Checking for the --global-config directory being set is a bit wonky but necessary
884 // to allow extensions that invoke the CLI with this flag (e.g. VS code) to continue
885 // working without modification. In the future we should modify these extensions to
886 // either access the credential in the keyring (like Coder Desktop) or some other
887 // approach that doesn't rely on the session token being stored on disk.
888 assumeExtensionInUse := r.globalConfig != config.DefaultDir() && !r.useKeyringWithGlobalConfig
889 keyringSupported := runtime.GOOS == "windows" || runtime.GOOS == "darwin"
890 if r.useKeyring && !assumeExtensionInUse && keyringSupported {
891 serviceName := sessionstore.DefaultServiceName
892 if r.keyringServiceName != "" {
893 serviceName = r.keyringServiceName
894 }
895 r.tokenBackend = sessionstore.NewKeyringWithService(serviceName)
896 } else {
897 r.tokenBackend = sessionstore.NewFile(r.createConfig)
898 }
899 }
900 return r.tokenBackend
901}
902
903// WithKeyringServiceName sets a custom keyring service name for testing purposes.
904// This allows tests to use isolated keyring storage while still exercising the

Callers 6

loginWithPasswordMethod · 0.95
loginMethod · 0.95
loginTokenMethod · 0.95
InitClientMethod · 0.95
TryInitClientMethod · 0.95
logoutMethod · 0.95

Calls 3

DefaultDirFunction · 0.92
NewKeyringWithServiceFunction · 0.92
NewFileFunction · 0.92

Tested by

no test coverage detected