Skip to content

Commit da98679

Browse files
committed
Propagate Credential File changes
1 parent 6b6a6ea commit da98679

File tree

6 files changed

+13
-15
lines changed

6 files changed

+13
-15
lines changed

lib/unison-credentials/src/Unison/Auth/CredentialManager.hs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module Unison.Auth.CredentialManager
44
( saveCredentials,
55
CredentialManager,
6-
newCredentialManager,
6+
globalCredentialManager,
77
getCodeserverCredentials,
88
getOrCreatePersonalKey,
99
isExpired,
@@ -30,10 +30,10 @@ import UnliftIO qualified
3030
newtype CredentialManager = CredentialManager (UnliftIO.MVar (Maybe Credentials {- Credentials may or may not be initialized -}))
3131

3232
-- | A global CredentialManager instance/singleton.
33-
globalCredentialsManager :: CredentialManager
34-
globalCredentialsManager = unsafePerformIO do
33+
globalCredentialManager :: CredentialManager
34+
globalCredentialManager = unsafePerformIO do
3535
CredentialManager <$> UnliftIO.newMVar Nothing
36-
{-# NOINLINE globalCredentialsManager #-}
36+
{-# NOINLINE globalCredentialManager #-}
3737

3838
-- | Fetches the user's personal key from the active profile, if it exists.
3939
-- Otherwise it creates a new personal key, saves it to the active profile, and returns it.
@@ -74,9 +74,6 @@ getCodeserverCredentials credMan aud = runExceptT do
7474
True -> throwE (ReauthRequired aud)
7575
False -> pure codeserverCreds
7676

77-
newCredentialManager :: CredentialManager
78-
newCredentialManager = globalCredentialsManager
79-
8077
-- | Checks whether CodeserverCredentials are expired.
8178
isExpired :: (MonadIO m) => CodeserverCredentials -> m Bool
8279
isExpired CodeserverCredentials {fetchTime, tokens = Tokens {expiresIn}} = liftIO do

parser-typechecker/src/Unison/Codebase/SqliteCodebase/Migrations.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ ensureCodebaseIsUpToDate localOrRemote root getDeclType termBuffer declBuffer sh
162162

163163
Region.displayConsoleRegions do
164164
(`UnliftIO.finally` finalizeRegion) do
165-
credMan <- CredMan.newCredentialManager
165+
let credMan = CredMan.globalCredentialManager
166166
keyThumbprint <- PK.personalKeyThumbprint <$> CredMan.getOrCreatePersonalKey credMan
167167
let migs = migrations keyThumbprint regionVar getDeclType termBuffer declBuffer root
168168
-- The highest schema that this ucm knows how to migrate to.

unison-cli/src/Unison/Auth/Tokens.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Network.HTTP.Client.TLS qualified as HTTP
1010
import Network.HTTP.Types qualified as Network
1111
import System.Environment (lookupEnv)
1212
import Unison.Auth.CredentialManager
13+
import Unison.Auth.CredentialManager qualified as CredMan
1314
import Unison.Auth.Discovery (fetchDiscoveryDoc)
1415
import Unison.Auth.Types
1516
import Unison.Auth.UserInfo (getUserInfo)
@@ -37,7 +38,7 @@ newTokenProvider manager host = UnliftIO.try @_ @CredentialFailure $ do
3738
-- If the access token is provided via environment variable, we don't need to refresh it.
3839
pure accessToken
3940
Nothing -> do
40-
creds@CodeserverCredentials {tokens, discoveryURI} <- throwEitherM $ getCodeserverCredentials manager host
41+
creds@CodeserverCredentials {tokens, discoveryURI} <- throwEitherM $ CredMan.getCodeserverCredentials manager host
4142
let Tokens {accessToken = currentAccessToken} = tokens
4243
expired <- isExpired creds
4344
if expired

unison-cli/src/Unison/Codebase/Transcript/Runner.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ withRunner ::
9696
(Runner -> m r) ->
9797
m r
9898
withRunner isTest verbosity ucmVersion action = do
99-
credMan <- AuthN.newCredentialManager
99+
let credMan = AuthN.globalCredentialManager
100100
authenticatedHTTPClient <- initTranscriptAuthenticatedHTTPClient credMan
101101

102102
-- If we're in a transcript test, configure the environment to use a non-existent fzf binary

unison-cli/src/Unison/MCP/Cli.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ cliToMCP projCtx onError cli = do
107107
MCP.Env {ucmVersion, codebase, runtime, workDir} <- ask
108108
initialPP <- ExceptT . liftIO $ Codebase.runTransactionExceptT codebase $ do
109109
ppForProjectContext projCtx
110-
credMan <- AuthN.newCredentialManager
110+
let credMan = AuthN.globalCredentialManager
111111
let tokenProvider :: AuthN.TokenProvider
112112
tokenProvider = AuthN.newTokenProvider credMan
113113
authenticatedHTTPClient <- AuthN.newAuthenticatedHTTPClient tokenProvider ucmVersion

unison-cli/src/Unison/Main.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ main version = do
147147
Text.putStrLn $ Text.pack progName <> " version: " <> Version.gitDescribeWithDate version
148148
MCPServer -> do
149149
let ucmVersion = Version.gitDescribeWithDate version
150-
credMan <- AuthN.newCredentialManager
150+
let credMan = AuthN.globalCredentialManager
151151
authenticatedHTTPClient <- initTranscriptAuthenticatedHTTPClient ucmVersion credMan
152152
getCodebaseOrExit mCodePathOption SC.DontLock (SC.MigrateAfterPrompt SC.Backup SC.Vacuum) \(_initRes, _, theCodebase) -> do
153153
withRuntimes RTI.Persistent \(runtime, sbRuntime) -> do
@@ -183,7 +183,7 @@ main version = do
183183
let noOpCheckForChanges _ = pure ()
184184
let serverUrl = Nothing
185185
let ucmVersion = Version.gitDescribeWithDate version
186-
credMan <- liftIO $ AuthN.newCredentialManager
186+
let credMan = AuthN.globalCredentialManager
187187
authenticatedHTTPClient <- initTranscriptAuthenticatedHTTPClient ucmVersion credMan
188188
startProjectPath <- Codebase.runTransaction theCodebase Codebase.expectCurrentProjectPath
189189
launch
@@ -211,7 +211,7 @@ main version = do
211211
let noOpCheckForChanges _ = pure ()
212212
let serverUrl = Nothing
213213
let ucmVersion = Version.gitDescribeWithDate version
214-
credMan <- liftIO $ AuthN.newCredentialManager
214+
let credMan = AuthN.globalCredentialManager
215215
authenticatedHTTPClient <- initTranscriptAuthenticatedHTTPClient ucmVersion credMan
216216
startProjectPath <- Codebase.runTransaction theCodebase Codebase.expectCurrentProjectPath
217217
launch
@@ -328,7 +328,7 @@ main version = do
328328
void . Ki.fork scope $ LSP.spawnLsp lspFormattingConfig theCodebase runtime changeSignal
329329
let isTest = False
330330
let ucmVersion = Version.gitDescribeWithDate version
331-
credMan <- liftIO $ AuthN.newCredentialManager
331+
let credMan = AuthN.globalCredentialManager
332332
authenticatedHTTPClient <- initTranscriptAuthenticatedHTTPClient ucmVersion credMan
333333
mcpServerConfig <- MCP.initServer theCodebase runtime sbRuntime (Just currentDir) ucmVersion authenticatedHTTPClient
334334
Server.startServer

0 commit comments

Comments
 (0)