diff options
author | Andrew Cady <d@jerkface.net> | 2016-04-08 20:38:18 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2016-04-08 20:38:18 -0400 |
commit | 6db17bc0e35641b9b039ee5498eb62c7c585ae2b (patch) | |
tree | c99c4d1ce5306da5d22a72d89a12571bddf72f93 /acme-certify.hs | |
parent | 3afa92161f020b9b26347e72e6ce813f48527ec0 (diff) |
slight refactor
Diffstat (limited to 'acme-certify.hs')
-rw-r--r-- | acme-certify.hs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/acme-certify.hs b/acme-certify.hs index 352be21..2b666af 100644 --- a/acme-certify.hs +++ b/acme-certify.hs | |||
@@ -35,7 +35,7 @@ Just stagingDirectoryUrl = parseAbsoluteURI "https://acme-staging.api.letsencryp | |||
35 | Just defaultTerms = parseAbsoluteURI "https://letsencrypt.org/documents/LE-SA-v1.0.1-July-27-2015.pdf" | 35 | Just defaultTerms = parseAbsoluteURI "https://letsencrypt.org/documents/LE-SA-v1.0.1-July-27-2015.pdf" |
36 | 36 | ||
37 | main :: IO () | 37 | main :: IO () |
38 | main = execParser opts >>= go | 38 | main = execParser opts >>= go >>= either (error . ("Error: " ++)) return |
39 | where | 39 | where |
40 | opts = info (helper <*> cmdopts) (fullDesc <> progDesc detailedDescription <> Opt.header "Let's Encrypt! ACME client") | 40 | opts = info (helper <*> cmdopts) (fullDesc <> progDesc detailedDescription <> Opt.header "Let's Encrypt! ACME client") |
41 | detailedDescription = unwords | 41 | detailedDescription = unwords |
@@ -98,7 +98,7 @@ cmdopts = CmdOpts <$> strOption (long "key" <> metavar "FILE" <> | |||
98 | , "making ACME requests; only useful for testing." | 98 | , "making ACME requests; only useful for testing." |
99 | ])) | 99 | ])) |
100 | 100 | ||
101 | go :: CmdOpts -> IO () | 101 | go :: CmdOpts -> IO (Either String ()) |
102 | go CmdOpts { .. } = do | 102 | go CmdOpts { .. } = do |
103 | let terms = fromMaybe defaultTerms (join $ parseAbsoluteURI <$> optTerms) | 103 | let terms = fromMaybe defaultTerms (join $ parseAbsoluteURI <$> optTerms) |
104 | directoryUrl = if optStaging then stagingDirectoryUrl else liveDirectoryUrl | 104 | directoryUrl = if optStaging then stagingDirectoryUrl else liveDirectoryUrl |
@@ -131,11 +131,15 @@ go CmdOpts { .. } = do | |||
131 | 131 | ||
132 | certificate <- certify directoryUrl keys ((,) terms <$> email) (fileProvisioner challengeDir) certReq | 132 | certificate <- certify directoryUrl keys ((,) terms <$> email) (fileProvisioner challengeDir) certReq |
133 | 133 | ||
134 | let saveCombined = combinedCert issuerCert dh domainKeys >=> writeFile domainCombinedFile | 134 | let save = saveCertificate issuerCert dh domainKeys domainCombinedFile domainCertFile |
135 | savePEM = writeX509 >=> writeFile domainCertFile | 135 | mapM save certificate |
136 | saveBoth x509 = savePEM x509 >> saveCombined x509 | ||
137 | 136 | ||
138 | either (error . ("Error: " ++)) saveBoth certificate | 137 | saveCertificate :: X509 -> Maybe DHP -> Keys -> FilePath -> FilePath -> X509 -> IO () |
138 | saveCertificate issuerCert dh domainKeys domainCombinedFile domainCertFile = saveBoth | ||
139 | where | ||
140 | saveCombined = combinedCert issuerCert dh domainKeys >=> writeFile domainCombinedFile | ||
141 | savePEM = writeX509 >=> writeFile domainCertFile | ||
142 | saveBoth x509 = savePEM x509 >> saveCombined x509 | ||
139 | 143 | ||
140 | genKey :: IO String | 144 | genKey :: IO String |
141 | genKey = withOpenSSL $ do | 145 | genKey = withOpenSSL $ do |