upload :: Text -> FilePath -> FilePath -> Maybe FilePath -> AWS ()
upload dom pubp privp chainp = do
    (pub, priv, chain) <- liftAWS $
        (,,) <$> loadKey pubp "Reading public key from {}"
             <*> loadKey privp "Reading private key from {}"
             <*> loadChain chainp

    say "Upload Certificate {}" [dom]
    send_ UploadServerCertificate
        { uscCertificateBody       = pub
        , uscPrivateKey            = priv
        , uscCertificateChain      = chain
        , uscPath                  = Nothing
        , usdServerCertificateName = dom
        }

    say "Created Certificate {}" [dom]
  where
    loadKey path fmt = FS.readTextFile path <* say fmt [path]

    loadChain (Just p) = Just <$> loadKey p "Reading certificate chain from {}"
    loadChain Nothing  = return Nothing
upload :: Text -> FilePath -> FilePath -> Maybe FilePath -> AWS ()
upload dom pubp privp chainp = do
    (pub, priv, chain) <- liftAWS $
        (,,) <$> loadKey pubp "Reading public key from {}"
             <*> loadKey privp "Reading private key from {}"
             <*> loadChain chainp

    say "Upload Certificate {}" [dom]
    send_ UploadServerCertificate
        { uscCertificateBody       = pub
        , uscPrivateKey            = priv
        , uscCertificateChain      = chain
        , uscPath                  = Nothing
        , usdServerCertificateName = dom
        }

    say "Created Certificate {}" [dom]
  where
    loadKey path fmt = FS.readTextFile path <* say fmt [path]

    loadChain (Just p) = Just <$> loadKey p "Reading certificate chain from {}"
    loadChain Nothing  = return Nothing
upload dom pubp privp chainp = do
    (pub, priv, chain) <- liftAWS $
        (,,) <$> loadKey pubp "Reading public key from {}"
             <*> loadKey privp "Reading private key from {}"
             <*> loadChain chainp

    say "Upload Certificate {}" [dom]
    send_ UploadServerCertificate
        { uscCertificateBody       = pub
        , uscPrivateKey            = priv
        , uscCertificateChain      = chain
        , uscPath                  = Nothing
        , usdServerCertificateName = dom
        }

    say "Created Certificate {}" [dom]
  where
    loadKey path fmt = FS.readTextFile path <* say fmt [path]

    loadChain (Just p) = Just <$> loadKey p "Reading certificate chain from {}"
    loadChain Nothing  = return Nothing