diff options
| author | Joey Hess <joey@kitenet.net> | 2014-05-14 19:41:05 -0400 |
|---|---|---|
| committer | Joey Hess <joey@kitenet.net> | 2014-05-14 19:41:05 -0400 |
| commit | 7115d1ec162b4059b3e8e8f84bd8d5898c1db025 (patch) | |
| tree | 42c1cce54e890e1d56484794ab33129132d8fee2 /Propellor/PrivData.hs | |
| parent | ffe371a9d42cded461236e972a24a142419d7fc4 (diff) | |
moved source code to src
This is to work around OSX's brain-damange regarding filename case
insensitivity.
Avoided moving config.hs, because it's a config file. Put in a symlink to
make build work.
Diffstat (limited to 'Propellor/PrivData.hs')
| -rw-r--r-- | Propellor/PrivData.hs | 91 |
1 files changed, 0 insertions, 91 deletions
diff --git a/Propellor/PrivData.hs b/Propellor/PrivData.hs deleted file mode 100644 index ad2c8d22..00000000 --- a/Propellor/PrivData.hs +++ /dev/null @@ -1,91 +0,0 @@ -{-# LANGUAGE PackageImports #-} - -module Propellor.PrivData where - -import qualified Data.Map as M -import Control.Applicative -import System.FilePath -import System.IO -import System.Directory -import Data.Maybe -import Data.List -import Control.Monad -import "mtl" Control.Monad.Reader - -import Propellor.Types -import Propellor.Attr -import Propellor.Message -import Utility.Monad -import Utility.PartialPrelude -import Utility.Exception -import Utility.Process -import Utility.Tmp -import Utility.SafeCommand -import Utility.Misc - --- | When the specified PrivDataField is available on the host Propellor --- is provisioning, it provies the data to the action. Otherwise, it prints --- a message to help the user make the necessary private data available. -withPrivData :: PrivDataField -> (String -> Propellor Result) -> Propellor Result -withPrivData field a = maybe missing a =<< liftIO (getPrivData field) - where - missing = do - host <- getHostName - let host' = if ".docker" `isSuffixOf` host - then "$parent_host" - else host - liftIO $ do - warningMessage $ "Missing privdata " ++ show field - putStrLn $ "Fix this by running: propellor --set "++host'++" '" ++ show field ++ "'" - return FailedChange - -getPrivData :: PrivDataField -> IO (Maybe String) -getPrivData field = do - m <- catchDefaultIO Nothing $ readish <$> readFile privDataLocal - return $ maybe Nothing (M.lookup field) m - -setPrivData :: HostName -> PrivDataField -> IO () -setPrivData host field = do - putStrLn "Enter private data on stdin; ctrl-D when done:" - value <- chomp <$> hGetContentsStrict stdin - makePrivDataDir - let f = privDataFile host - m <- fromMaybe M.empty . readish <$> gpgDecrypt f - let m' = M.insert field value m - gpgEncrypt f (show m') - putStrLn "Private data set." - void $ boolSystem "git" [Param "add", File f] - where - chomp s - | end s == "\n" = chomp (beginning s) - | otherwise = s - -makePrivDataDir :: IO () -makePrivDataDir = createDirectoryIfMissing False privDataDir - -privDataDir :: FilePath -privDataDir = "privdata" - -privDataFile :: HostName -> FilePath -privDataFile host = privDataDir </> host ++ ".gpg" - -privDataLocal :: FilePath -privDataLocal = privDataDir </> "local" - -gpgDecrypt :: FilePath -> IO String -gpgDecrypt f = ifM (doesFileExist f) - ( readProcess "gpg" ["--decrypt", f] - , return "" - ) - -gpgEncrypt :: FilePath -> String -> IO () -gpgEncrypt f s = do - encrypted <- writeReadProcessEnv "gpg" - [ "--default-recipient-self" - , "--armor" - , "--encrypt" - ] - Nothing - (Just $ flip hPutStr s) - Nothing - viaTmp writeFile f encrypted |
