summaryrefslogtreecommitdiff
path: root/src/Propellor/Types/PrivData.hs
diff options
context:
space:
mode:
authorJoey Hess2014-12-14 16:14:05 -0400
committerJoey Hess2014-12-14 16:14:05 -0400
commit23399416f1ba89894f65f61b436c2b0f8378e6c5 (patch)
tree161b0d4bcf18cd7fb9bf58a7a7089b868dad2777 /src/Propellor/Types/PrivData.hs
parent71723ca09f369ccf96462cef1e0200e1615677d1 (diff)
broke up big function to describe PrivDataField
Diffstat (limited to 'src/Propellor/Types/PrivData.hs')
-rw-r--r--src/Propellor/Types/PrivData.hs42
1 files changed, 25 insertions, 17 deletions
diff --git a/src/Propellor/Types/PrivData.hs b/src/Propellor/Types/PrivData.hs
index ab3e108a..f746a74c 100644
--- a/src/Propellor/Types/PrivData.hs
+++ b/src/Propellor/Types/PrivData.hs
@@ -16,23 +16,31 @@ data PrivDataField
| GpgKey
deriving (Read, Show, Ord, Eq)
--- | Explains how the user can generate a particular PrivDataField.
-howtoMkPrivDataField :: PrivDataField -> String
-howtoMkPrivDataField fld = case fld of
- DockerAuthentication -> "/root/.dockercfg" `genbycmd` "docker login"
- SshPubKey keytype _ -> forexample $
- "sshkey.pub" `genbycmd` keygen keytype
- SshPrivKey keytype _ -> forexample $
- "sshkey" `genbycmd` keygen keytype
- SshAuthorizedKeys _ -> forexample "~/.ssh/id_rsa.pub"
- Password username -> "a password for " ++ username
- CryptPassword _ -> "a crypt(3)ed password, which can be generated by, for example: perl -e 'print crypt(shift, q{$6$}.shift)' 'somepassword' 'somesalt'"
- PrivFile f -> "file contents for " ++ f
- GpgKey -> "Either a gpg public key, exported with gpg --export -a, or a gpg private key, exported with gpg --export-secret-key -a"
- where
- genbycmd f cmd = f ++ " generated by running `" ++ cmd ++ "`"
- keygen keytype = "ssh-keygen -t " ++ sshKeyTypeParam keytype ++ " -f sshkey"
- forexample s = "for example, " ++ s
+-- | Combines a PrivDataField with a description of how to generate
+-- its value.
+data PrivDataSource
+ = PrivDataSourceFile PrivDataField FilePath
+ | PrivDataSourceFileFromCommand PrivDataField FilePath String
+ | PrivDataSource PrivDataField String
+
+class IsPrivDataSource s where
+ privDataField :: s -> PrivDataField
+ describePrivDataSource :: s -> Maybe String
+
+instance IsPrivDataSource PrivDataField where
+ privDataField = id
+ describePrivDataSource _ = Nothing
+
+instance IsPrivDataSource PrivDataSource where
+ privDataField s = case s of
+ PrivDataSourceFile f _ -> f
+ PrivDataSourceFileFromCommand f _ _ -> f
+ PrivDataSource f _ -> f
+ describePrivDataSource s = Just $ case s of
+ PrivDataSourceFile _ f -> "< " ++ f
+ PrivDataSourceFileFromCommand _ f c ->
+ "< " ++ f ++ " (created by running, for example, `" ++ c ++ "` )"
+ PrivDataSource _ d -> "< (" ++ d ++ ")"
-- | A context in which a PrivDataField is used.
--