add P2P.Auth

This commit is contained in:
Joey Hess 2016-11-22 14:37:19 -04:00
parent b08799893f
commit 158ef45d76
No known key found for this signature in database
GPG key ID: C910D9222512E3C7
3 changed files with 32 additions and 1 deletions

View file

@ -156,7 +156,7 @@ readCacheCredPair storage = maybe Nothing decodeCredPair
<$> readCacheCreds (credPairFile storage)
readCacheCreds :: FilePath -> Annex (Maybe Creds)
readCacheCreds f = liftIO . catchMaybeIO . readFile =<< cacheCredsFile f
readCacheCreds f = liftIO . catchMaybeIO . readFileStrict =<< cacheCredsFile f
cacheCredsFile :: FilePath -> Annex FilePath
cacheCredsFile basefile = do

30
P2P/Auth.hs Normal file
View file

@ -0,0 +1,30 @@
{- P2P protocol, authorization
-
- Copyright 2016 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module P2P.Auth where
import Common
import Utility.AuthToken
import qualified Data.Text as T
-- Use .git/annex/creds/p2p to hold AuthTokens of authorized peers.
getAuthTokens :: Annex AllowedAuthTokens
getAuthTokens = allowedAuthTokens <$> getAuthTokens'
getAuthTokens' :: Annex [AuthTokens]
getAuthTokens' = mapMaybe toAuthToken
. map T.pack
. lines
. fromMaybe []
<$> readCacheCreds "tor"
addAuthToken :: AuthToken -> Annex ()
addAuthToken t = do
ts <- getAuthTokens'
let d = unlines $ map (T.unpack . fromAuthToken) (t:ts)
writeCacheCreds d "tor"

View file

@ -904,6 +904,7 @@ Executable git-annex
Messages.Internal
Messages.JSON
Messages.Progress
P2P.Auth
P2P.IO
P2P.Protocol
Remote