summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2016-01-21 22:37:29 -0500
committerAndrew Cady <d@jerkface.net>2016-01-21 22:37:29 -0500
commit6fe3bd340f0fed8910758a32bbd86ccee135bf18 (patch)
treed3a86ee2394a74522f2e0889c816e0abe8dc18f3
parentc8f622463afa168dba3183bd0a025ef17965cffb (diff)
helper function to replace "flip unless" ugliness
-rw-r--r--acme.hs15
1 files changed, 10 insertions, 5 deletions
diff --git a/acme.hs b/acme.hs
index 199a441..dc11452 100644
--- a/acme.hs
+++ b/acme.hs
@@ -131,6 +131,10 @@ readKeys privKeyFile = do
131 131
132data ChallengeRequest = ChallengeRequest { crUri :: String, crToken :: ByteString, crThumbToken :: ByteString } 132data ChallengeRequest = ChallengeRequest { crUri :: String, crToken :: ByteString, crThumbToken :: ByteString }
133 133
134otherwiseM :: Monad m => m Bool -> m () -> m ()
135a `otherwiseM` b = a >>= flip unless b
136infixl 0 `otherwiseM`
137
134go :: CmdOpts -> IO () 138go :: CmdOpts -> IO ()
135go CmdOpts{..} = do 139go CmdOpts{..} = do
136 let terms = fromMaybe defaultTerms optTerms 140 let terms = fromMaybe defaultTerms optTerms
@@ -141,21 +145,21 @@ go CmdOpts{..} = do
141 domainDir = fromMaybe optDomain optDomainDir 145 domainDir = fromMaybe optDomain optDomainDir
142 privKeyFile = optKeyFile 146 privKeyFile = optKeyFile
143 147
144 doesFileExist privKeyFile >>= flip unless (genKey privKeyFile) 148 doesFileExist privKeyFile `otherwiseM` genKey privKeyFile
145 149
146 doesDirectoryExist optDomain >>= flip unless (createDirectory domainDir) 150 doesDirectoryExist optDomain `otherwiseM` createDirectory domainDir
147 doesFileExist domainKeyFile >>= flip unless (genKey domainKeyFile) 151 doesFileExist domainKeyFile `otherwiseM` genKey domainKeyFile
148 152
149 keys <- readKeys privKeyFile 153 keys <- readKeys privKeyFile
150 154
151 doesFileExist domainCSRFile >>= flip unless (genReq domainKeyFile optDomain >>= B.writeFile domainCSRFile) 155 doesFileExist domainCSRFile `otherwiseM` genReq domainKeyFile optDomain >>= writeFile domainCSRFile
152 156
153 csrData <- B.readFile domainCSRFile 157 csrData <- B.readFile domainCSRFile
154 158
155 ensureWritable optChallengeDir "challenge directory" 159 ensureWritable optChallengeDir "challenge directory"
156 ensureWritable domainDir "domain directory" 160 ensureWritable domainDir "domain directory"
157 161
158 canProvision optDomain optChallengeDir >>= flip unless (error "Error: cannot provision files to web server via challenge directory") 162 canProvision optDomain optChallengeDir `otherwiseM` error "Error: cannot provision files to web server via challenge directory"
159 163
160 runACME directoryUrl keys $ do 164 runACME directoryUrl keys $ do
161 forM_ optEmail $ register terms >=> statusReport 165 forM_ optEmail $ register terms >=> statusReport
@@ -170,6 +174,7 @@ go CmdOpts{..} = do
170 174
171(</>) :: String -> String -> String 175(</>) :: String -> String -> String
172a </> b = a ++ "/" ++ b 176a </> b = a ++ "/" ++ b
177infixr 5 </>
173 178
174canProvision :: String -> FilePath -> IO Bool 179canProvision :: String -> FilePath -> IO Bool
175canProvision domain challengeDir = do 180canProvision domain challengeDir = do