diff options
author | Andrew Cady <d@jerkface.net> | 2016-04-09 19:19:21 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2016-04-09 19:19:24 -0400 |
commit | 5ccdc88c25f9a94e7b5db135a0876d606685a690 (patch) | |
tree | 0c1b3d5ad5cac02afcd004cb5b5f70cbb21f383e /acme-certify.hs | |
parent | 6224e4d1dc99244fbad13dc0613fa16e87c20396 (diff) |
implement code to install & clean up remote temporary files
(via ssh)
Diffstat (limited to 'acme-certify.hs')
-rw-r--r-- | acme-certify.hs | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/acme-certify.hs b/acme-certify.hs index 579622f..1e9655c 100644 --- a/acme-certify.hs +++ b/acme-certify.hs | |||
@@ -37,6 +37,8 @@ import Options.Applicative hiding (header) | |||
37 | import qualified Options.Applicative as Opt | 37 | import qualified Options.Applicative as Opt |
38 | import System.Directory | 38 | import System.Directory |
39 | import System.IO | 39 | import System.IO |
40 | import System.Posix.Escape | ||
41 | import System.Process | ||
40 | import Text.Domain.Validate hiding (validate) | 42 | import Text.Domain.Validate hiding (validate) |
41 | import Text.Email.Validate | 43 | import Text.Email.Validate |
42 | 44 | ||
@@ -171,15 +173,21 @@ runUpdate UpdateOpts { .. } = do | |||
171 | 173 | ||
172 | 174 | ||
173 | certSpecs :: [CertSpec] <- forM certReqDomains $ \(host, domains) -> do | 175 | certSpecs :: [CertSpec] <- forM certReqDomains $ \(host, domains) -> do |
174 | provisioners <- mapM (chooseProvisioner host) domains | 176 | provisioners <- mapM (chooseProvisioner host) domains |
175 | return $ certSpec globalCertificateDir keys (host, provisioners) | 177 | return $ certSpec globalCertificateDir keys (host, provisioners) |
176 | 178 | ||
177 | mapM_ print certSpecs | 179 | mapM_ print certSpecs |
180 | |||
181 | h <- remoteTemp "localhost" "/tmp/whatevs 'bro'" "this content\ncontains stuff'" | ||
182 | threadDelay $ 1000*1000*10 | ||
183 | removeTemp h | ||
184 | |||
178 | error "Error: unimplemented" | 185 | error "Error: unimplemented" |
179 | 186 | ||
180 | where | 187 | where |
181 | chooseProvisioner :: String -> String -> IO (DomainName, HttpProvisioner) | 188 | chooseProvisioner :: String -> String -> IO (DomainName, HttpProvisioner) |
182 | chooseProvisioner host domain = do -- TODO: implement | 189 | chooseProvisioner host domain -- TODO: implement |
190 | = do | ||
183 | let errmsg = "whatever" | 191 | let errmsg = "whatever" |
184 | dir <- ensureWritableDir "/var/www/html/.well-known/acme-challenge/" errmsg | 192 | dir <- ensureWritableDir "/var/www/html/.well-known/acme-challenge/" errmsg |
185 | return (domainName' domain, provisionViaFile dir) | 193 | return (domainName' domain, provisionViaFile dir) |
@@ -197,6 +205,18 @@ runUpdate UpdateOpts { .. } = do | |||
197 | map (<..> unpack domain) $ sort -- relying on the fact that '.' sorts first | 205 | map (<..> unpack domain) $ sort -- relying on the fact that '.' sorts first |
198 | $ concat $ HashMap.lookup domain subs & toListOf (_Just . _String . to (words . unpack)) | 206 | $ concat $ HashMap.lookup domain subs & toListOf (_Just . _String . to (words . unpack)) |
199 | 207 | ||
208 | data TempRemover = TempRemover { removeTemp :: IO () } | ||
209 | remoteTemp :: String -> FilePath -> String -> IO TempRemover | ||
210 | remoteTemp host fileName content = do | ||
211 | (inp,out,err,_pid) <- ssh $ unlines | ||
212 | [ "printf '%s' " ++ escape content ++ " > " ++ escape fileName | ||
213 | , "trap " ++ (escape . unwords) ["rm -f", escape fileName] ++ " EXIT" | ||
214 | , "read line" | ||
215 | ] | ||
216 | return $ TempRemover $ mapM_ hClose [inp, out, err] | ||
217 | where | ||
218 | ssh cmd = runInteractiveProcess "ssh" (host : words "-- sh -c" ++ [escape cmd]) Nothing Nothing | ||
219 | |||
200 | runCertify :: CertifyOpts -> IO (Either String ()) | 220 | runCertify :: CertifyOpts -> IO (Either String ()) |
201 | runCertify CertifyOpts{..} = do | 221 | runCertify CertifyOpts{..} = do |
202 | let terms = fromMaybe defaultTerms (join $ parseAbsoluteURI <$> optTerms) | 222 | let terms = fromMaybe defaultTerms (join $ parseAbsoluteURI <$> optTerms) |