diff options
author | Andrew Cady <d@jerkface.net> | 2016-01-21 22:37:29 -0500 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2016-01-21 22:37:29 -0500 |
commit | 6fe3bd340f0fed8910758a32bbd86ccee135bf18 (patch) | |
tree | d3a86ee2394a74522f2e0889c816e0abe8dc18f3 | |
parent | c8f622463afa168dba3183bd0a025ef17965cffb (diff) |
helper function to replace "flip unless" ugliness
-rw-r--r-- | acme.hs | 15 |
1 files changed, 10 insertions, 5 deletions
@@ -131,6 +131,10 @@ readKeys privKeyFile = do | |||
131 | 131 | ||
132 | data ChallengeRequest = ChallengeRequest { crUri :: String, crToken :: ByteString, crThumbToken :: ByteString } | 132 | data ChallengeRequest = ChallengeRequest { crUri :: String, crToken :: ByteString, crThumbToken :: ByteString } |
133 | 133 | ||
134 | otherwiseM :: Monad m => m Bool -> m () -> m () | ||
135 | a `otherwiseM` b = a >>= flip unless b | ||
136 | infixl 0 `otherwiseM` | ||
137 | |||
134 | go :: CmdOpts -> IO () | 138 | go :: CmdOpts -> IO () |
135 | go CmdOpts{..} = do | 139 | go 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 |
172 | a </> b = a ++ "/" ++ b | 176 | a </> b = a ++ "/" ++ b |
177 | infixr 5 </> | ||
173 | 178 | ||
174 | canProvision :: String -> FilePath -> IO Bool | 179 | canProvision :: String -> FilePath -> IO Bool |
175 | canProvision domain challengeDir = do | 180 | canProvision domain challengeDir = do |