From def53b64cc17b95eb5729dd97a800dfe1257b352 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 6 Sep 2015 08:19:02 -0700 Subject: Added Propellor.Property.Rsync. WIP; untested Convert Info to use Data.Dynamic, so properties can export and consume info of any type that is Typeable and a Monoid, including data types private to a module. (API change) Thanks to Joachim Breitner for the idea. --- src/Propellor/Property/Ssh.hs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'src/Propellor/Property/Ssh.hs') diff --git a/src/Propellor/Property/Ssh.hs b/src/Propellor/Property/Ssh.hs index fca7d037..c85694db 100644 --- a/src/Propellor/Property/Ssh.hs +++ b/src/Propellor/Property/Ssh.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE DeriveDataTypeable #-} + module Propellor.Property.Ssh ( PubKeyText, sshdConfig, @@ -27,6 +29,7 @@ import Propellor import qualified Propellor.Property.File as File import qualified Propellor.Property.Service as Service import Propellor.Property.User +import Propellor.Types.Info import Utility.FileMode import System.PosixCompat @@ -169,11 +172,25 @@ keyFile keytype ispub = "/etc/ssh/ssh_host_" ++ fromKeyType keytype ++ "_key" ++ -- configure the host to use it. Normally this does not need to be used; -- use 'hostKey' instead. pubKey :: SshKeyType -> PubKeyText -> Property HasInfo -pubKey t k = pureInfoProperty ("ssh pubkey known") $ - mempty { _sshPubKey = M.singleton t k } +pubKey t k = pureInfoProperty ("ssh pubkey known") + (SshPubKeyInfo (M.singleton t k)) + +getPubKey :: Propellor (M.Map SshKeyType PubKeyText) +getPubKey = fromSshPubKeyInfo <$> askInfo + +newtype SshPubKeyInfo = SshPubKeyInfo + { fromSshPubKeyInfo :: M.Map SshKeyType PubKeyText } + deriving (Eq, Ord, Typeable) + +instance IsInfo SshPubKeyInfo where + propigateInfo _ = False -getPubKey :: Propellor (M.Map SshKeyType String) -getPubKey = asks (_sshPubKey . hostInfo) +instance Monoid SshPubKeyInfo where + mempty = SshPubKeyInfo M.empty + mappend (SshPubKeyInfo old) (SshPubKeyInfo new) = + -- new first because union prefers values from the first + -- parameter when there is a duplicate key + SshPubKeyInfo (new `M.union` old) -- | Sets up a user with a ssh private key and public key pair from the -- PrivData. -- cgit v1.2.3