summaryrefslogtreecommitdiff
path: root/P2P/Auth.hs
blob: 5c3feb7132acca01b34d0fc8bc16b2dbd3634d0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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"