summaryrefslogtreecommitdiff
path: root/src/Propellor
diff options
context:
space:
mode:
authorJoey Hess2015-06-29 16:40:01 -0400
committerJoey Hess2015-06-29 16:40:01 -0400
commitfc04d0d81df909904fa655372ee005138f3b6ea7 (patch)
tree356408138591bfb4f9ae19fa778ef88a7f405257 /src/Propellor
parent37a5c05aba1800a8ccf9a98a0bf3abd59ef1d140 (diff)
Added --unset to delete a privdata field.
Diffstat (limited to 'src/Propellor')
-rw-r--r--src/Propellor/CmdLine.hs2
-rw-r--r--src/Propellor/PrivData.hs21
-rw-r--r--src/Propellor/Types/CmdLine.hs1
3 files changed, 19 insertions, 5 deletions
diff --git a/src/Propellor/CmdLine.hs b/src/Propellor/CmdLine.hs
index d29ffbb7..95a633ec 100644
--- a/src/Propellor/CmdLine.hs
+++ b/src/Propellor/CmdLine.hs
@@ -51,6 +51,7 @@ processCmdLine = go =<< getArgs
_ -> Spin <$> mapM hostname ps <*> pure Nothing
go ("--add-key":k:[]) = return $ AddKey k
go ("--set":f:c:[]) = withprivfield f c Set
+ go ("--unset":f:c:[]) = withprivfield f c Unset
go ("--dump":f:c:[]) = withprivfield f c Dump
go ("--edit":f:c:[]) = withprivfield f c Edit
go ("--list-fields":[]) = return ListFields
@@ -94,6 +95,7 @@ defaultMain hostlist = do
go _ (Continue cmdline) = go False cmdline
go _ Check = return ()
go _ (Set field context) = setPrivData field context
+ go _ (Unset field context) = unsetPrivData field context
go _ (Dump field context) = dumpPrivData field context
go _ (Edit field context) = editPrivData field context
go _ ListFields = listPrivDataFields hostlist
diff --git a/src/Propellor/PrivData.hs b/src/Propellor/PrivData.hs
index 71aa820d..d0426e75 100644
--- a/src/Propellor/PrivData.hs
+++ b/src/Propellor/PrivData.hs
@@ -6,6 +6,7 @@ module Propellor.PrivData (
withSomePrivData,
addPrivData,
setPrivData,
+ unsetPrivData,
dumpPrivData,
editPrivData,
filterPrivData,
@@ -143,6 +144,11 @@ setPrivData field context = do
putStrLn "Enter private data on stdin; ctrl-D when done:"
setPrivDataTo field context =<< hGetContentsStrict stdin
+unsetPrivData :: PrivDataField -> Context -> IO ()
+unsetPrivData field context = do
+ modifyPrivData $ M.delete (field, context)
+ putStrLn "Private data unset."
+
dumpPrivData :: PrivDataField -> Context -> IO ()
dumpPrivData field context =
maybe (error "Requested privdata is not set.") putStrLn
@@ -192,17 +198,22 @@ listPrivDataFields hosts = do
setPrivDataTo :: PrivDataField -> Context -> PrivData -> IO ()
setPrivDataTo field context value = do
- makePrivDataDir
- m <- decryptPrivData
- let m' = M.insert (field, context) (chomp value) m
- gpgEncrypt privDataFile (show m')
+ modifyPrivData set
putStrLn "Private data set."
- void $ boolSystem "git" [Param "add", File privDataFile]
where
+ set = M.insert (field, context) (chomp value)
chomp s
| end s == "\n" = chomp (beginning s)
| otherwise = s
+modifyPrivData :: (PrivMap -> PrivMap) -> IO ()
+modifyPrivData f = do
+ makePrivDataDir
+ m <- decryptPrivData
+ let m' = f m
+ gpgEncrypt privDataFile (show m')
+ void $ boolSystem "git" [Param "add", File privDataFile]
+
decryptPrivData :: IO PrivMap
decryptPrivData = fromMaybe M.empty . readish <$> gpgDecrypt privDataFile
diff --git a/src/Propellor/Types/CmdLine.hs b/src/Propellor/Types/CmdLine.hs
index bd0cbdfd..96949957 100644
--- a/src/Propellor/Types/CmdLine.hs
+++ b/src/Propellor/Types/CmdLine.hs
@@ -10,6 +10,7 @@ data CmdLine
| Spin [HostName] (Maybe HostName)
| SimpleRun HostName
| Set PrivDataField Context
+ | Unset PrivDataField Context
| Dump PrivDataField Context
| Edit PrivDataField Context
| ListFields