2012-01-10 19:36:54 +00:00
|
|
|
{- git-annex trust log
|
2011-01-26 19:37:16 +00:00
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2010-2012 Joey Hess <id@joeyh.name>
|
2011-01-26 19:37:16 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2011-01-26 19:37:16 +00:00
|
|
|
-}
|
|
|
|
|
2011-10-15 20:21:08 +00:00
|
|
|
module Logs.Trust (
|
2013-08-31 21:38:33 +00:00
|
|
|
module X,
|
add ConfigMonitor thread
Monitors git-annex branch for changes, which are noticed by the Merger
thread whenever the branch ref is changed (either due to an incoming push,
or a local change), and refreshes cached config values for modified config
files.
Rate limited to run no more often than once per minute. This is important
because frequent git-annex branch changes happen when files are being
added, or transferred, etc.
A primary use case is that, when preferred content changes are made,
and get pushed to remotes, the remotes start honoring those settings.
Other use cases include propigating repository description and trust
changes to remotes, and learning when a remote has added a new special
remote, so the webapp can present the GUI to enable that special remote
locally.
Also added a uuid.log cache. All other config files already had caches.
2012-10-20 20:37:06 +00:00
|
|
|
trustLog,
|
2011-01-26 19:37:16 +00:00
|
|
|
TrustLevel(..),
|
|
|
|
trustGet,
|
2013-04-25 01:53:58 +00:00
|
|
|
trustMap,
|
2012-01-10 03:31:44 +00:00
|
|
|
trustPartition,
|
2012-11-11 04:24:32 +00:00
|
|
|
trustExclude,
|
2012-09-23 17:50:31 +00:00
|
|
|
lookupTrust,
|
add ConfigMonitor thread
Monitors git-annex branch for changes, which are noticed by the Merger
thread whenever the branch ref is changed (either due to an incoming push,
or a local change), and refreshes cached config values for modified config
files.
Rate limited to run no more often than once per minute. This is important
because frequent git-annex branch changes happen when files are being
added, or transferred, etc.
A primary use case is that, when preferred content changes are made,
and get pushed to remotes, the remotes start honoring those settings.
Other use cases include propigating repository description and trust
changes to remotes, and learning when a remote has added a new special
remote, so the webapp can present the GUI to enable that special remote
locally.
Also added a uuid.log cache. All other config files already had caches.
2012-10-20 20:37:06 +00:00
|
|
|
trustMapLoad,
|
2011-01-26 19:37:16 +00:00
|
|
|
) where
|
|
|
|
|
|
|
|
import qualified Data.Map as M
|
2014-10-14 18:10:22 +00:00
|
|
|
import Data.Default
|
2011-01-26 19:37:16 +00:00
|
|
|
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.Common
|
2011-06-24 01:25:39 +00:00
|
|
|
import Types.TrustLevel
|
2011-01-26 19:37:16 +00:00
|
|
|
import qualified Annex
|
2013-08-29 22:51:22 +00:00
|
|
|
import Logs
|
2012-01-10 17:11:16 +00:00
|
|
|
import Remote.List
|
|
|
|
import qualified Types.Remote
|
2014-09-05 17:44:09 +00:00
|
|
|
import Logs.Trust.Basic as X
|
2011-10-06 19:55:50 +00:00
|
|
|
|
2011-11-18 17:22:48 +00:00
|
|
|
{- Returns a list of UUIDs that the trustLog indicates have the
|
|
|
|
- specified trust level.
|
|
|
|
- Note that the list can be incomplete for SemiTrusted, since that's
|
|
|
|
- the default. -}
|
2011-01-26 19:37:16 +00:00
|
|
|
trustGet :: TrustLevel -> Annex [UUID]
|
2011-10-06 19:55:50 +00:00
|
|
|
trustGet level = M.keys . M.filter (== level) <$> trustMap
|
2011-01-26 19:37:16 +00:00
|
|
|
|
2012-09-23 17:50:31 +00:00
|
|
|
{- Returns the TrustLevel of a given repo UUID. -}
|
|
|
|
lookupTrust :: UUID -> Annex TrustLevel
|
2014-10-14 18:10:22 +00:00
|
|
|
lookupTrust u = (fromMaybe def . M.lookup u) <$> trustMap
|
2012-09-23 17:50:31 +00:00
|
|
|
|
2011-11-18 17:22:48 +00:00
|
|
|
{- Partitions a list of UUIDs to those matching a TrustLevel and not. -}
|
|
|
|
trustPartition :: TrustLevel -> [UUID] -> Annex ([UUID], [UUID])
|
|
|
|
trustPartition level ls
|
|
|
|
| level == SemiTrusted = do
|
|
|
|
t <- trustGet Trusted
|
|
|
|
u <- trustGet UnTrusted
|
2011-12-02 23:21:56 +00:00
|
|
|
d <- trustGet DeadTrusted
|
|
|
|
let uncandidates = t ++ u ++ d
|
2011-11-18 17:22:48 +00:00
|
|
|
return $ partition (`notElem` uncandidates) ls
|
|
|
|
| otherwise = do
|
|
|
|
candidates <- trustGet level
|
|
|
|
return $ partition (`elem` candidates) ls
|
|
|
|
|
2012-11-11 04:24:32 +00:00
|
|
|
{- Filters UUIDs to those not matching a TrustLevel. -}
|
2013-04-03 07:52:41 +00:00
|
|
|
trustExclude :: TrustLevel -> [UUID] -> Annex [UUID]
|
2012-11-11 04:24:32 +00:00
|
|
|
trustExclude level ls = snd <$> trustPartition level ls
|
|
|
|
|
add ConfigMonitor thread
Monitors git-annex branch for changes, which are noticed by the Merger
thread whenever the branch ref is changed (either due to an incoming push,
or a local change), and refreshes cached config values for modified config
files.
Rate limited to run no more often than once per minute. This is important
because frequent git-annex branch changes happen when files are being
added, or transferred, etc.
A primary use case is that, when preferred content changes are made,
and get pushed to remotes, the remotes start honoring those settings.
Other use cases include propigating repository description and trust
changes to remotes, and learning when a remote has added a new special
remote, so the webapp can present the GUI to enable that special remote
locally.
Also added a uuid.log cache. All other config files already had caches.
2012-10-20 20:37:06 +00:00
|
|
|
{- trustLog in a map, overridden with any values from forcetrust or
|
|
|
|
- the git config. The map is cached for speed. -}
|
2011-06-24 01:25:39 +00:00
|
|
|
trustMap :: Annex TrustMap
|
add ConfigMonitor thread
Monitors git-annex branch for changes, which are noticed by the Merger
thread whenever the branch ref is changed (either due to an incoming push,
or a local change), and refreshes cached config values for modified config
files.
Rate limited to run no more often than once per minute. This is important
because frequent git-annex branch changes happen when files are being
added, or transferred, etc.
A primary use case is that, when preferred content changes are made,
and get pushed to remotes, the remotes start honoring those settings.
Other use cases include propigating repository description and trust
changes to remotes, and learning when a remote has added a new special
remote, so the webapp can present the GUI to enable that special remote
locally.
Also added a uuid.log cache. All other config files already had caches.
2012-10-20 20:37:06 +00:00
|
|
|
trustMap = maybe trustMapLoad return =<< Annex.getState Annex.trustmap
|
|
|
|
|
|
|
|
{- Loads the map, updating the cache, -}
|
|
|
|
trustMapLoad :: Annex TrustMap
|
|
|
|
trustMapLoad = do
|
|
|
|
overrides <- Annex.getState Annex.forcetrust
|
2017-09-04 20:39:56 +00:00
|
|
|
l <- remoteList
|
2018-08-30 15:41:44 +00:00
|
|
|
-- Exports are not trusted, since they are not key/value stores.
|
|
|
|
-- This does not apply to appendonly exports, which are key/value
|
|
|
|
-- stores.
|
|
|
|
let untrustworthy r = pure (not (Types.Remote.appendonly r))
|
|
|
|
<&&> Types.Remote.isExportSupported r
|
|
|
|
exports <- filterM untrustworthy l
|
2017-09-04 20:39:56 +00:00
|
|
|
let exportoverrides = M.fromList $
|
|
|
|
map (\r -> (Types.Remote.uuid r, UnTrusted)) exports
|
add ConfigMonitor thread
Monitors git-annex branch for changes, which are noticed by the Merger
thread whenever the branch ref is changed (either due to an incoming push,
or a local change), and refreshes cached config values for modified config
files.
Rate limited to run no more often than once per minute. This is important
because frequent git-annex branch changes happen when files are being
added, or transferred, etc.
A primary use case is that, when preferred content changes are made,
and get pushed to remotes, the remotes start honoring those settings.
Other use cases include propigating repository description and trust
changes to remotes, and learning when a remote has added a new special
remote, so the webapp can present the GUI to enable that special remote
locally.
Also added a uuid.log cache. All other config files already had caches.
2012-10-20 20:37:06 +00:00
|
|
|
logged <- trustMapRaw
|
2017-09-04 20:39:56 +00:00
|
|
|
let configured = M.fromList $ mapMaybe configuredtrust l
|
2018-04-13 19:16:07 +00:00
|
|
|
let m = M.unionWith min exportoverrides $
|
2017-09-04 20:39:56 +00:00
|
|
|
M.union overrides $
|
|
|
|
M.union configured logged
|
add ConfigMonitor thread
Monitors git-annex branch for changes, which are noticed by the Merger
thread whenever the branch ref is changed (either due to an incoming push,
or a local change), and refreshes cached config values for modified config
files.
Rate limited to run no more often than once per minute. This is important
because frequent git-annex branch changes happen when files are being
added, or transferred, etc.
A primary use case is that, when preferred content changes are made,
and get pushed to remotes, the remotes start honoring those settings.
Other use cases include propigating repository description and trust
changes to remotes, and learning when a remote has added a new special
remote, so the webapp can present the GUI to enable that special remote
locally.
Also added a uuid.log cache. All other config files already had caches.
2012-10-20 20:37:06 +00:00
|
|
|
Annex.changeState $ \s -> s { Annex.trustmap = Just m }
|
|
|
|
return m
|
2012-11-11 04:51:07 +00:00
|
|
|
where
|
2013-01-01 17:52:47 +00:00
|
|
|
configuredtrust r = (\l -> Just (Types.Remote.uuid r, l))
|
|
|
|
=<< readTrustLevel
|
|
|
|
=<< remoteAnnexTrustLevel (Types.Remote.gitconfig r)
|