summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2016-10-28 18:11:30 -0400
committerAndrew Cady <d@jerkface.net>2016-10-28 18:57:10 -0400
commitd489dcbc4ed286c54e4d1fc6502cf7e074a60dc2 (patch)
treef0fe866b8af1e46573dd5ab3a3ded475ca20b147
parent1a03d33cb840b5484f5d3f0954e29643332d5993 (diff)
factor out function 'configGetCertReqs'
-rw-r--r--acme-certify.hs30
1 files changed, 17 insertions, 13 deletions
diff --git a/acme-certify.hs b/acme-certify.hs
index b246a66..71309fb 100644
--- a/acme-certify.hs
+++ b/acme-certify.hs
@@ -233,17 +233,29 @@ readSignedObject =
233 B.readFile >=> return . 233 B.readFile >=> return .
234 either error (map (X509.decodeSignedObject . pemContent)) . pemParseBS 234 either error (map (X509.decodeSignedObject . pemContent)) . pemParseBS
235 235
236configGetCertReqs :: Config -> IO [(String, DomainName, [VHostSpec])]
237configGetCertReqs hostsConfig = do
238 fmap concat $ forM (Config.keys hostsConfig) $ \host ->
239 do
240 hostParts <- (Config.subconfig host hostsConfig >>= Config.subconfig "domains") <&> extractObject
241 return $ flip map (HashMap.keys hostParts) $ \domain ->
242 (unpack host, domainName' $ unpack domain, combineSubdomains domain hostParts)
243
244combineSubdomains :: AsPrimitive v => Text -> HashMap.HashMap Text v -> [VHostSpec]
245combineSubdomains domain subs =
246 map (makeVHostSpec (domainName' $ unpack domain)) $
247 sort -- '.' sorts first
248 $ concat $ HashMap.lookup domain subs & toListOf (_Just . _String . to (words . unpack))
249
250extractObject :: Config -> Object
251extractObject (Config _ o) = o
236 252
237runUpdate :: UpdateOpts -> IO () 253runUpdate :: UpdateOpts -> IO ()
238runUpdate UpdateOpts { .. } = do 254runUpdate UpdateOpts { .. } = do
239 issuerCert <- readX509 letsEncryptX3CrossSigned 255 issuerCert <- readX509 letsEncryptX3CrossSigned
240 256
241 config <- Config.load $ fromMaybe defaultUpdateConfigFile updateConfigFile 257 config <- Config.load $ fromMaybe defaultUpdateConfigFile updateConfigFile
242 hostsConfig <- Config.subconfig "hosts" config 258 certReqDomains <- configGetCertReqs =<< Config.subconfig "hosts" config
243 certReqDomains <- fmap concat $ forM (Config.keys hostsConfig) $ \host -> do
244 hostParts <- (Config.subconfig host hostsConfig >>= Config.subconfig "domains") <&> extractObject
245 return $ flip map (HashMap.keys hostParts) $ \domain ->
246 (unpack host, domainName' $ unpack domain, combineSubdomains domain hostParts)
247 259
248 globalCertificateDir <- getHomeDirectory <&> (</> if updateStaging then ".acme/fake-certs" else ".acme/certs") 260 globalCertificateDir <- getHomeDirectory <&> (</> if updateStaging then ".acme/fake-certs" else ".acme/certs")
249 createDirectoryIfMissing True globalCertificateDir 261 createDirectoryIfMissing True globalCertificateDir
@@ -281,8 +293,6 @@ runUpdate UpdateOpts { .. } = do
281 else print =<< fetchCertificate directoryUrl terms email issuerCert spec 293 else print =<< fetchCertificate directoryUrl terms email issuerCert spec
282 294
283 where 295 where
284 extractObject :: Config -> Object
285 extractObject (Config _ o) = o
286 296
287 elemOrNull :: Eq a => [a] -> a -> Bool 297 elemOrNull :: Eq a => [a] -> a -> Bool
288 elemOrNull xs x = null xs || x `elem` xs 298 elemOrNull xs x = null xs || x `elem` xs
@@ -312,12 +322,6 @@ runUpdate UpdateOpts { .. } = do
312 csUserKeys = keys 322 csUserKeys = keys
313 csCertificateDir = baseDir </> host </> domainToString domain 323 csCertificateDir = baseDir </> host </> domainToString domain
314 324
315 combineSubdomains :: AsPrimitive v => Text -> HashMap.HashMap Text v -> [VHostSpec]
316 combineSubdomains domain subs =
317 map (makeVHostSpec (domainName' $ unpack domain)) $
318 sort -- '.' sorts first
319 $ concat $ HashMap.lookup domain subs & toListOf (_Just . _String . to (words . unpack))
320
321domainToString :: DomainName -> String 325domainToString :: DomainName -> String
322domainToString = unpack . decodeUtf8 . Text.Domain.Validate.toByteString 326domainToString = unpack . decodeUtf8 . Text.Domain.Validate.toByteString
323 327