diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Propellor/CmdLine.hs | 3 | ||||
| -rw-r--r-- | src/Propellor/PrivData.hs | 30 | ||||
| -rw-r--r-- | src/Propellor/Types.hs | 1 |
3 files changed, 23 insertions, 11 deletions
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 31850217..c2af4284 100644 --- a/src/Propellor/PrivData.hs +++ b/src/Propellor/PrivData.hs @@ -56,6 +56,25 @@ dumpPrivData host field = maybe (error "Requested privdata is not set.") putStrLn =<< getPrivDataFor host field +editPrivData :: HostName -> PrivDataField -> IO () +editPrivData host field = do + v <- getPrivDataFor host field + v' <- withTmpFile "propellorXXXX" $ \f h -> do + hClose h + maybe noop (writeFileProtected f) v + editor <- getEnvDefault "EDITOR" "vi" + unlessM (boolSystem editor [File f]) $ + error "Editor failed; aborting." + 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 @@ -73,17 +92,6 @@ setPrivDataTo host field value = do getPrivDataFor :: HostName -> PrivDataField -> IO (Maybe String) getPrivDataFor host field = M.lookup field <$> decryptPrivData host -editPrivData :: HostName -> PrivDataField -> IO () -editPrivData host field = do - v <- getPrivDataFor host field - v' <- withTmpFile "propellorXXXX" $ \f _h -> do - maybe noop (writeFileProtected f) v - editor <- getEnvDefault "EDITOR" "vi" - unlessM (boolSystem editor [File f]) $ - error "Editor failed; aborting." - readFile f - setPrivDataTo host field v' - decryptPrivData :: HostName -> IO (M.Map PrivDataField String) decryptPrivData host = fromMaybe M.empty . readish <$> gpgDecrypt (privDataFile host) 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 |
