diff options
author | Joey Hess <joeyh@joeyh.name> | 2016-11-22 14:37:19 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2016-11-22 14:37:50 -0400 |
commit | ee611985367b93539c9390a8067d28340dd972ad (patch) | |
tree | 1a1668b50222af075c76be3ef0c94af08792e500 /P2P/Auth.hs | |
parent | d6ceefea050683c6e9022fa04bdefd9e28609990 (diff) |
add P2P.Auth
Diffstat (limited to 'P2P/Auth.hs')
-rw-r--r-- | P2P/Auth.hs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/P2P/Auth.hs b/P2P/Auth.hs new file mode 100644 index 000000000..5c3feb713 --- /dev/null +++ b/P2P/Auth.hs @@ -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" |