-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more flexibility in our ability to specify codeservers (#3081)
* Add explicit types for share host and uri * Ensure we identify servers correctly * Remove ability to pass args to auth.login and remove logic for CodeServers config * PR feedback: special structure for coderserver URI * Add port to CodeserverId
- Loading branch information
1 parent
36b8ac2
commit f61a4dd
Showing
13 changed files
with
161 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 21 additions & 12 deletions
33
unison-cli/src/Unison/Codebase/Editor/HandleInput/AuthLogin.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,37 @@ | ||
module Unison.Codebase.Editor.HandleInput.AuthLogin (authLogin) where | ||
|
||
import Control.Monad.Reader | ||
import qualified Data.Text as Text | ||
import Network.URI (URIAuth (..), parseURI) | ||
import System.IO.Unsafe (unsafePerformIO) | ||
import Unison.Auth.OAuth | ||
import Unison.Auth.Types (Host (..)) | ||
import Unison.Auth.OAuth (authenticateCodeserver) | ||
import Unison.Codebase.Editor.HandleInput.LoopState | ||
import Unison.Codebase.Editor.Output (Output (CredentialFailureMsg, Success)) | ||
import Unison.Prelude | ||
import Unison.Share.Types | ||
import qualified UnliftIO | ||
import UnliftIO.Environment (lookupEnv) | ||
|
||
defaultShareHost :: Host | ||
defaultShareHost = unsafePerformIO $ do | ||
-- | This is the URI where the share API is based. | ||
defaultShareURI :: CodeserverURI | ||
defaultShareURI = unsafePerformIO $ do | ||
lookupEnv "UNISON_SHARE_HOST" <&> \case | ||
-- TODO: swap to production share before release. | ||
Nothing -> Host "share-next.us-west-2.unison-lang.org" | ||
Just shareHost -> Host (Text.pack shareHost) | ||
{-# NOINLINE defaultShareHost #-} | ||
Nothing -> | ||
CodeserverURI | ||
{ codeserverScheme = "https:", | ||
codeserverAuthority = URIAuth {uriUserInfo = "", uriRegName = "share-next.us-west-2.unison-lang.org", uriPort = ""}, | ||
codeserverPath = "/api" | ||
} | ||
Just shareHost -> | ||
fromMaybe (error $ "Share Host is not a valid URI: " <> shareHost) $ do | ||
uri <- parseURI shareHost | ||
codeserverFromURI uri | ||
{-# NOINLINE defaultShareURI #-} | ||
|
||
authLogin :: UnliftIO.MonadUnliftIO m => Maybe Host -> Action m i v () | ||
authLogin mayHost = do | ||
let host = fromMaybe defaultShareHost mayHost | ||
authLogin :: UnliftIO.MonadUnliftIO m => Action m i v () | ||
authLogin = do | ||
let host = defaultShareURI | ||
credsMan <- asks credentialManager | ||
(Action . lift . lift . lift $ authenticateHost credsMan host) >>= \case | ||
(Action . lift . lift . lift $ authenticateCodeserver credsMan host) >>= \case | ||
Left err -> respond (CredentialFailureMsg err) | ||
Right () -> respond Success |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.