summaryrefslogtreecommitdiff
path: root/src/Propellor/Types/PrivData.hs
diff options
context:
space:
mode:
authorJoey Hess2014-12-07 14:57:35 -0400
committerJoey Hess2014-12-07 15:03:06 -0400
commit9ca332e48169ac19dad050a7f99e0db523d8d9c4 (patch)
treea1bbe51c18c64317a19d0dbd887fae4355a3bc50 /src/Propellor/Types/PrivData.hs
parent8c12047b6b6be67e086d60d79a95490598601a7a (diff)
Fixed privdata introspection for User.hasPassword and User.hasSomePassword
This is not a complete fix for the problem that Info doen't propigate from the called property when code does something like: do hostname <- asks hostName ensureProperty $ foo hostname Instead, I just eliminated the need to implement hasPassword that way, by making the PrivData Info use a HostContext which automatically gets the right hostname passed to it. All other uses of withPrivData don't have the problem. It's still possible for the user to run into the problem if they write something like the above, where foo is a property that uses privdata. However, all properties that take a Context now also accept a HostContext, so it's at least less likely the user needs to write that.
Diffstat (limited to 'src/Propellor/Types/PrivData.hs')
-rw-r--r--src/Propellor/Types/PrivData.hs31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/Propellor/Types/PrivData.hs b/src/Propellor/Types/PrivData.hs
index 16d6cdb1..a18e7cec 100644
--- a/src/Propellor/Types/PrivData.hs
+++ b/src/Propellor/Types/PrivData.hs
@@ -15,7 +15,7 @@ data PrivDataField
| GpgKey
deriving (Read, Show, Ord, Eq)
--- | Context in which a PrivDataField is used.
+-- | A context in which a PrivDataField is used.
--
-- Often this will be a domain name. For example,
-- Context "www.example.com" could be used for the SSL cert
@@ -24,10 +24,39 @@ data PrivDataField
newtype Context = Context String
deriving (Read, Show, Ord, Eq)
+-- | A context that varies depending on the HostName where it's used.
+newtype HostContext = HostContext { mkHostContext :: HostName -> Context }
+
+instance Show HostContext where
+ show hc = show $ mkHostContext hc "<hostname>"
+
+instance Ord HostContext where
+ a <= b = show a <= show b
+
+instance Eq HostContext where
+ a == b = show a == show b
+
+-- | Class of things that can be used as a Context.
+class IsContext c where
+ asContext :: HostName -> c -> Context
+ asHostContext :: c -> HostContext
+
+instance IsContext HostContext where
+ asContext = flip mkHostContext
+ asHostContext = id
+
+instance IsContext Context where
+ asContext _ c = c
+ asHostContext = HostContext . const
+
-- | Use when a PrivDataField is not dependent on any paricular context.
anyContext :: Context
anyContext = Context "any"
+-- | Makes a HostContext that consists just of the hostname.
+hostContext :: HostContext
+hostContext = HostContext Context
+
type PrivData = String
data SshKeyType = SshRsa | SshDsa | SshEcdsa | SshEd25519