summaryrefslogtreecommitdiff
path: root/P2P
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-11-30 15:26:16 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-11-30 15:26:55 -0400
commitdeca4cd90ad599f859fc9efafe509ed7375c6f39 (patch)
treeb0b9ea6af4bbc1228deb8f444fe23049728be97a /P2P
parentf14c412232808399c609e0dd484b8243af7daa3a (diff)
use P2P auth for git-remote-tor-annex
This changes the environment variable name to the more generic GIT_ANNEX_P2P_AUTHTOKEN. This commit was sponsored by andrea rota.
Diffstat (limited to 'P2P')
-rw-r--r--P2P/Auth.hs15
1 files changed, 13 insertions, 2 deletions
diff --git a/P2P/Auth.hs b/P2P/Auth.hs
index 2c8465900..0025957c7 100644
--- a/P2P/Auth.hs
+++ b/P2P/Auth.hs
@@ -12,6 +12,7 @@ import Creds
import P2P.Address
import Utility.AuthToken
import Utility.Tor
+import Utility.Env
import qualified Data.Text as T
@@ -38,9 +39,19 @@ p2pAuthCredsFile :: FilePath
p2pAuthCredsFile = "p2pauth"
-- | Loads the AuthToken to use when connecting with a given P2P address.
+--
+-- It's loaded from the first line of the creds file, but
+-- GIT_ANNEX_P2P_AUTHTOKEN overrides.
loadP2PRemoteAuthToken :: P2PAddress -> Annex (Maybe AuthToken)
-loadP2PRemoteAuthToken addr = maybe Nothing (toAuthToken . T.pack)
- <$> readCacheCreds (addressCredsFile addr)
+loadP2PRemoteAuthToken addr = maybe Nothing mk <$> getM id
+ [ liftIO $ getEnv "GIT_ANNEX_P2P_AUTHTOKEN"
+ , readCacheCreds (addressCredsFile addr)
+ ]
+ where
+ mk = toAuthToken . T.pack . takeWhile (/= '\n')
+
+p2pAuthTokenEnv :: String
+p2pAuthTokenEnv = "GIT_ANNEX_P2P_AUTHTOKEN"
-- | Stores the AuthToken o use when connecting with a given P2P address.
storeP2PRemoteAuthToken :: P2PAddress -> AuthToken -> Annex ()