summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Hess2014-06-19 14:56:50 -0400
committerJoey Hess2014-06-19 14:56:50 -0400
commitf674c56119bd9b1bb9af53d5063c57275be77827 (patch)
tree0512c77f1730d796c2af1a5a3490f4eb36261106
parent42594d6b4c14a21efc42e262e52c2c67f30c67c3 (diff)
Add --list-fields to list a host's currently set privdata fields.
-rw-r--r--debian/changelog1
-rw-r--r--src/Propellor/CmdLine.hs3
-rw-r--r--src/Propellor/PrivData.hs7
-rw-r--r--src/Propellor/Types.hs1
4 files changed, 12 insertions, 0 deletions
diff --git a/debian/changelog b/debian/changelog
index 95d0b232..8e9a2b48 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,6 +1,7 @@
propellor (0.7.1) UNRELEASED; urgency=medium
* Add --edit to edit a privdata value in $EDITOR.
+ * Add --list-fields to list a host's currently set privdata fields.
-- Joey Hess <joeyh@debian.org> Thu, 19 Jun 2014 14:27:21 -0400
diff --git a/src/Propellor/CmdLine.hs b/src/Propellor/CmdLine.hs
index c084355b..1027fd8d 100644
--- a/src/Propellor/CmdLine.hs
+++ b/src/Propellor/CmdLine.hs
@@ -30,6 +30,7 @@ usage = do
, " propellor --set hostname field"
, " propellor --dump hostname field"
, " propellor --edit hostname field"
+ , " propellor --list-fields hostname"
]
exitFailure
@@ -43,6 +44,7 @@ processCmdLine = go =<< getArgs
go ("--set":h:f:[]) = withprivfield f (return . Set h)
go ("--dump":h:f:[]) = withprivfield f (return . Dump h)
go ("--edit":h:f:[]) = withprivfield f (return . Edit h)
+ go ("--list-fields":h:[]) = return $ ListFields h
go ("--continue":s:[]) = case readish s of
Just cmdline -> return $ Continue cmdline
Nothing -> errorMessage "--continue serialization failure"
@@ -74,6 +76,7 @@ defaultMain hostlist = do
go _ (Set hn field) = setPrivData hn field
go _ (Dump hn field) = dumpPrivData hn field
go _ (Edit hn field) = editPrivData hn field
+ go _ (ListFields hn) = listPrivDataFields hn
go _ (AddKey keyid) = addKey keyid
go _ (Chain hn) = withhost hn $ \h -> do
r <- runPropellor h $ ensureProperties $ hostProperties h
diff --git a/src/Propellor/PrivData.hs b/src/Propellor/PrivData.hs
index fec6acc3..c2af4284 100644
--- a/src/Propellor/PrivData.hs
+++ b/src/Propellor/PrivData.hs
@@ -68,6 +68,13 @@ editPrivData host field = do
readFile f
setPrivDataTo host field v'
+listPrivDataFields :: HostName -> IO ()
+listPrivDataFields host = do
+ putStrLn (host ++ "'s currently set privdata fields:")
+ mapM_ list . M.keys =<< decryptPrivData host
+ where
+ list = putStrLn . ("\t" ++) . shellEscape . show
+
setPrivDataTo :: HostName -> PrivDataField -> String -> IO ()
setPrivDataTo host field value = do
makePrivDataDir
diff --git a/src/Propellor/Types.hs b/src/Propellor/Types.hs
index 740996be..59652f66 100644
--- a/src/Propellor/Types.hs
+++ b/src/Propellor/Types.hs
@@ -138,6 +138,7 @@ data CmdLine
| Set HostName PrivDataField
| Dump HostName PrivDataField
| Edit HostName PrivDataField
+ | ListFields HostName
| AddKey String
| Continue CmdLine
| Chain HostName