summaryrefslogtreecommitdiff
path: root/src/Propellor/PrivData.hs
diff options
context:
space:
mode:
authorJoey Hess2014-07-06 17:37:10 -0400
committerJoey Hess2014-07-06 17:37:10 -0400
commite2019aa7a8e18549df359bac39b325a86f448ccc (patch)
tree022803c41221e721cd35b909ba4f18873f56e185 /src/Propellor/PrivData.hs
parent2fde19656e4e1af257aeab7e323f2860b60f2211 (diff)
propellor spin
Diffstat (limited to 'src/Propellor/PrivData.hs')
-rw-r--r--src/Propellor/PrivData.hs12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/Propellor/PrivData.hs b/src/Propellor/PrivData.hs
index 0194c969..e9e7e47f 100644
--- a/src/Propellor/PrivData.hs
+++ b/src/Propellor/PrivData.hs
@@ -29,6 +29,8 @@ import Utility.FileMode
import Utility.Env
import Utility.Table
+type PrivMap = M.Map (PrivDataField, Context) PrivData
+
-- | Allows a Property to access the value of a specific PrivDataField,
-- for use in a specific Context.
--
@@ -68,7 +70,13 @@ getLocalPrivData field context =
where
localcache = catchDefaultIO Nothing $ readish <$> readFile privDataLocal
-getPrivData :: PrivDataField -> Context -> (M.Map (PrivDataField, Context) PrivData) -> Maybe PrivData
+{- Get only the set of PrivData that the Host's Info says it uses. -}
+filterPrivData :: Host -> PrivMap -> PrivMap
+filterPrivData host = M.filterWithKey (\k _v -> S.member k used)
+ where
+ used = _privDataFields $ hostInfo host
+
+getPrivData :: PrivDataField -> Context -> PrivMap -> Maybe PrivData
getPrivData field context = M.lookup (field, context)
setPrivData :: PrivDataField -> Context -> IO ()
@@ -124,7 +132,7 @@ setPrivDataTo field context value = do
| end s == "\n" = chomp (beginning s)
| otherwise = s
-decryptPrivData :: IO (M.Map (PrivDataField, Context) PrivData)
+decryptPrivData :: IO PrivMap
decryptPrivData = fromMaybe M.empty . readish <$> gpgDecrypt privDataFile
makePrivDataDir :: IO ()