diff options
author | Andrew Cady <d@jerkface.net> | 2016-04-09 14:08:38 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2016-04-09 14:08:38 -0400 |
commit | 9bf06242513945fbadd6fcd20b41efd0f1b073c2 (patch) | |
tree | ce514d5829e4d8323c32608ae31092d3d27d84be | |
parent | f246697d0b7ee5b0fd4e6145ef39531e75d21af5 (diff) |
stub parsing of yaml config file
-rw-r--r-- | acme-certify.cabal | 3 | ||||
-rw-r--r-- | acme-certify.hs | 48 |
2 files changed, 37 insertions, 14 deletions
diff --git a/acme-certify.cabal b/acme-certify.cabal index 2cd61e9..22dcd20 100644 --- a/acme-certify.cabal +++ b/acme-certify.cabal | |||
@@ -28,7 +28,8 @@ executable acme | |||
28 | build-depends: base, base-prelude, acme-certify, | 28 | build-depends: base, base-prelude, acme-certify, |
29 | cryptonite, aeson, bytestring, base64-bytestring, SHA, | 29 | cryptonite, aeson, bytestring, base64-bytestring, SHA, |
30 | text, HsOpenSSL, optparse-applicative, time, | 30 | text, HsOpenSSL, optparse-applicative, time, |
31 | email-validate, network-uri, directory, yaml-config | 31 | email-validate, network-uri, directory, yaml-config, |
32 | yaml, unordered-containers, lens, lens-aeson | ||
32 | default-language: Haskell2010 | 33 | default-language: Haskell2010 |
33 | 34 | ||
34 | -- test-suite acme-certify-test | 35 | -- test-suite acme-certify-test |
diff --git a/acme-certify.hs b/acme-certify.hs index fc44d77..48901c9 100644 --- a/acme-certify.hs +++ b/acme-certify.hs | |||
@@ -13,26 +13,31 @@ | |||
13 | module Main where | 13 | module Main where |
14 | 14 | ||
15 | import BasePrelude | 15 | import BasePrelude |
16 | import Network.ACME (HttpProvisioner, Keys (..), | 16 | import Control.Lens hiding ((&)) |
17 | canProvision, certify, | 17 | import Data.Aeson.Lens |
18 | ensureWritableDir, provisionViaFile, | 18 | import qualified Data.HashMap.Strict as HashMap |
19 | readKeys, (</>)) | 19 | import Data.Text (unpack) |
20 | import Network.ACME.Issuer (letsEncryptX1CrossSigned) | 20 | import Data.Yaml (Object) |
21 | import qualified Data.Yaml.Config as Config | ||
22 | import Data.Yaml.Config.Internal (Config (..)) | ||
23 | import Network.ACME (HttpProvisioner, Keys (..), | ||
24 | canProvision, certify, | ||
25 | ensureWritableDir, provisionViaFile, | ||
26 | readKeys, (</>)) | ||
27 | import Network.ACME.Issuer (letsEncryptX1CrossSigned) | ||
21 | import Network.URI | 28 | import Network.URI |
22 | import OpenSSL | 29 | import OpenSSL |
23 | import OpenSSL.DH | 30 | import OpenSSL.DH |
24 | import OpenSSL.PEM | 31 | import OpenSSL.PEM |
25 | import OpenSSL.RSA | 32 | import OpenSSL.RSA |
26 | import OpenSSL.X509 (X509) | 33 | import OpenSSL.X509 (X509) |
27 | import Options.Applicative hiding (header) | 34 | import Options.Applicative hiding (header) |
28 | import qualified Options.Applicative as Opt | 35 | import qualified Options.Applicative as Opt |
29 | import System.Directory | 36 | import System.Directory |
30 | import System.IO | 37 | import System.IO |
31 | import Text.Domain.Validate hiding (validate) | 38 | import Text.Domain.Validate hiding (validate) |
32 | import Text.Email.Validate | 39 | import Text.Email.Validate |
33 | 40 | ||
34 | import qualified Data.Yaml.Config as Yaml | ||
35 | |||
36 | stagingDirectoryUrl, liveDirectoryUrl, defaultTerms :: URI | 41 | stagingDirectoryUrl, liveDirectoryUrl, defaultTerms :: URI |
37 | Just liveDirectoryUrl = parseAbsoluteURI "https://acme-v01.api.letsencrypt.org/directory" | 42 | Just liveDirectoryUrl = parseAbsoluteURI "https://acme-v01.api.letsencrypt.org/directory" |
38 | Just stagingDirectoryUrl = parseAbsoluteURI "https://acme-staging.api.letsencrypt.org/directory" | 43 | Just stagingDirectoryUrl = parseAbsoluteURI "https://acme-staging.api.letsencrypt.org/directory" |
@@ -135,9 +140,23 @@ certifyOpts = fmap Certify $ | |||
135 | , "making ACME requests" | 140 | , "making ACME requests" |
136 | ])) | 141 | ])) |
137 | 142 | ||
143 | -- lookup' :: (Monad m, FromJSON a) => Config.Key -> Config -> m a | ||
144 | |||
145 | extractObject :: Config -> Object | ||
146 | extractObject (Config _ o) = o | ||
147 | |||
138 | runUpdate :: UpdateOpts -> IO () | 148 | runUpdate :: UpdateOpts -> IO () |
139 | runUpdate UpdateOpts{..} = do | 149 | runUpdate UpdateOpts { .. } = do |
140 | error "test" | 150 | config <- Config.load "config.yaml" |
151 | hosts <- Config.subconfig "hosts" config | ||
152 | forM_ (Config.keys hosts) $ \host -> do | ||
153 | domains <- extractObject <$> (Config.subconfig host hosts >>= Config.subconfig "domains") | ||
154 | putStrLn $ unpack host ++ ": " | ||
155 | forM_ (HashMap.keys domains) $ \domain -> do | ||
156 | let subdomains = map (<..> unpack domain) $ sort $ concat $ HashMap.lookup domain domains & toListOf (_Just . _String . to (words . unpack)) | ||
157 | putStrLn $ " " ++ unwords subdomains | ||
158 | putStrLn "" | ||
159 | error "Error: unimplemented" | ||
141 | 160 | ||
142 | runCertify :: CertifyOpts -> IO (Either String ()) | 161 | runCertify :: CertifyOpts -> IO (Either String ()) |
143 | runCertify CertifyOpts{..} = do | 162 | runCertify CertifyOpts{..} = do |
@@ -232,3 +251,6 @@ otherwiseM :: Monad m => m Bool -> m () -> m () | |||
232 | a `otherwiseM` b = a >>= flip unless b | 251 | a `otherwiseM` b = a >>= flip unless b |
233 | infixl 0 `otherwiseM` | 252 | infixl 0 `otherwiseM` |
234 | 253 | ||
254 | (<..>) :: String -> String -> String | ||
255 | "." <..> dom = dom | ||
256 | sub <..> dom = sub ++ "." ++ dom | ||