From 9a0169f0cbdf2470e149a32f5fab8ec2369686f3 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 14 Sep 2015 20:11:25 -0400 Subject: clean up privdata excess/lacking newline issue * PrivData converted to newtype (API change). * Stopped stripping trailing newlines when setting PrivData; this was previously done to avoid mistakes when pasting eg passwords with an unwanted newline. Instead, PrivData consumers should use either privDataLines or privDataVal, to extract respectively lines or a value (without internal newlines) from PrivData. --- src/Propellor/Types/PrivData.hs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/Propellor/Types/PrivData.hs') diff --git a/src/Propellor/Types/PrivData.hs b/src/Propellor/Types/PrivData.hs index d713c7cf..c72838cb 100644 --- a/src/Propellor/Types/PrivData.hs +++ b/src/Propellor/Types/PrivData.hs @@ -1,6 +1,9 @@ module Propellor.Types.PrivData where import Propellor.Types.OS +import Utility.PartialPrelude + +import Data.Maybe -- | Note that removing or changing constructors or changing types will -- break the serialized privdata files, so don't do that! @@ -89,7 +92,23 @@ anyContext = Context "any" hostContext :: HostContext hostContext = HostContext Context -type PrivData = String +-- | Contains the actual private data. +-- +-- Note that this may contain exta newlines at the end, or they may have +-- been stripped off, depending on how the user entered the privdata, +-- and which version of propellor stored it. Use the accessor functions +-- below to avoid newline problems. +newtype PrivData = PrivData String + +-- | When PrivData is the content of a file, this is the lines thereof. +privDataLines :: PrivData -> [String] +privDataLines (PrivData s) = lines s + +-- | When the PrivData is a single value, like a password, this extracts +-- it. Note that if multiple lines are present in the PrivData, only +-- the first is returned; there is never a newline in the String. +privDataVal :: PrivData -> String +privDataVal (PrivData s) = fromMaybe "" (headMaybe (lines s)) data SshKeyType = SshRsa | SshDsa | SshEcdsa | SshEd25519 deriving (Read, Show, Ord, Eq, Enum, Bounded) -- cgit v1.2.3