summaryrefslogtreecommitdiff
path: root/Remote
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-11-22 14:18:34 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-11-22 14:18:34 -0400
commit8166ebdb34c513af648072e03682c8c503f57bdd (patch)
tree8c9ee4b158066611ebdd90ffe814046bf46403ca /Remote
parentfb500b7482279be5a1c7f0104331d6c41ed7b649 (diff)
unified AuthToken type between webapp and tor
Diffstat (limited to 'Remote')
-rw-r--r--Remote/Helper/P2P.hs14
-rw-r--r--Remote/Helper/Tor.hs12
2 files changed, 9 insertions, 17 deletions
diff --git a/Remote/Helper/P2P.hs b/Remote/Helper/P2P.hs
index eaa534fbe..9d9a3847b 100644
--- a/Remote/Helper/P2P.hs
+++ b/Remote/Helper/P2P.hs
@@ -12,6 +12,7 @@ module Remote.Helper.P2P where
import qualified Utility.SimpleProtocol as Proto
import Types.Key
import Types.UUID
+import Utility.AuthToken
import Utility.Applicative
import Utility.PartialPrelude
@@ -23,15 +24,6 @@ import System.Exit (ExitCode(..))
import System.IO
import qualified Data.ByteString.Lazy as L
-newtype AuthToken = AuthToken String
- deriving (Show)
-
-mkAuthToken :: String -> Maybe AuthToken
-mkAuthToken = fmap AuthToken . headMaybe . lines
-
-nullAuthToken :: AuthToken
-nullAuthToken = AuthToken ""
-
newtype Offset = Offset Integer
deriving (Show)
@@ -111,10 +103,6 @@ instance Proto.Serializable Len where
serialize (Len n) = show n
deserialize = Len <$$> readish
-instance Proto.Serializable AuthToken where
- serialize (AuthToken s) = s
- deserialize = Just . AuthToken
-
instance Proto.Serializable Service where
serialize UploadPack = "git-upload-pack"
serialize ReceivePack = "git-receive-pack"
diff --git a/Remote/Helper/Tor.hs b/Remote/Helper/Tor.hs
index e91083362..25d192023 100644
--- a/Remote/Helper/Tor.hs
+++ b/Remote/Helper/Tor.hs
@@ -8,19 +8,23 @@
module Remote.Helper.Tor where
import Annex.Common
-import Remote.Helper.P2P (mkAuthToken, AuthToken)
+import Utility.AuthToken
import Creds
import Utility.Tor
import Utility.Env
import Network.Socket
+import qualified Data.Text as T
-getTorAuthToken :: OnionAddress -> Annex (Maybe AuthToken)
-getTorAuthToken (OnionAddress onionaddress) =
- maybe Nothing mkAuthToken <$> getM id
+-- Read the first line of the creds file. Environment variable overrides.
+getTorAuthTokenFor :: OnionAddress -> Annex (Maybe AuthToken)
+getTorAuthTokenFor (OnionAddress onionaddress) =
+ maybe Nothing mk <$> getM id
[ liftIO $ getEnv torAuthTokenEnv
, readCacheCreds onionaddress
]
+ where
+ mk = toAuthToken . T.pack . takeWhile (/= '\n')
torAuthTokenEnv :: String
torAuthTokenEnv = "GIT_ANNEX_TOR_AUTHTOKEN"