nuxeo 0.3.0.2 → 0.3.0.3
raw patch · 3 files changed
+68/−19 lines, 3 filesdep +aesondep +http-conduitdep +http-typesPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
Dependencies added: aeson, http-conduit, http-types, url
API changes (from Hackage documentation)
+ Nuxeo.ElasticSearch: reindex :: String -> String -> String -> IO (Either String String)
Files
- app/Main.hs +22/−14
- nuxeo.cabal +10/−5
- src/Nuxeo/ElasticSearch.hs +36/−0
app/Main.hs view
@@ -4,31 +4,39 @@ import qualified Data.Text as Text import qualified Data.Text.IO as TIO+import Nuxeo.ElasticSearch import Nuxeo.Log import Options.Applicative -data NuxeoCli = NuxeoCli { cliLogFile :: String }+data NuxeoCli = NuxeoCli { cliLogFile :: String+ , cliLogin :: String+ , cliPassword :: String+ , cliUrl :: String } args :: Parser NuxeoCli args = NuxeoCli- <$> strOption (long "log" <> help "Log file")+ <$> option auto (long "log" <> help "Log file" <> value "server.log")+ <*> option auto (long "login" <> help "Instance login")+ <*> option auto (long "password" <> help "Instance password")+ <*> option auto (long "url" <> help "Instance base url") -- | Exemple to extract errors from Nuxeo log nuxeocli :: NuxeoCli -> IO()-nuxeocli (NuxeoCli logFile) = (filter (\l -> nuxeoLogEntryType l == Error) <$> parseNuxeoLog logFile)- >>= mapM_ (\t -> TIO.putStrLn $- Text.replicate 10 "=" <> "\n"- <> Text.replicate 5 " " <> (Text.pack $ show $ nuxeoLogEntryDthr t)- <> "\n" <> Text.replicate 10 "=" <> "\n"- <> (Text.pack $ show $ nuxeoLogEntryType t)- <> " - "- <> nuxeoLogEntryAction t- <> "\n\n"- <> nuxeoLogEntryLog t- )+nuxeocli (NuxeoCli logFile login password url) = (filter (\l -> nuxeoLogEntryType l == Error) <$> parseNuxeoLog logFile)+ >>= mapM_ (\t -> TIO.putStrLn $+ Text.replicate 10 "=" <> "\n"+ <> Text.replicate 5 " " <> (Text.pack $ show $ nuxeoLogEntryDthr t)+ <> "\n" <> Text.replicate 10 "=" <> "\n"+ <> (Text.pack $ show $ nuxeoLogEntryType t)+ <> " - "+ <> nuxeoLogEntryAction t+ <> "\n\n"+ <> nuxeoLogEntryLog t+ ) main :: IO()-main = nuxeocli =<< execParser opts+main = do+ nuxeocli =<< execParser opts where opts = info (args <**> helper) (fullDesc
nuxeo.cabal view
@@ -2,16 +2,16 @@ -- -- see: https://github.com/sol/hpack ----- hash: 7b38063f3f56ba357f013f162de10b1a9863401f14d65a0c9118af59eb7b2f85+-- hash: cf3e6fd641583c528a2a5475ffe131d7fcc51c3422ff94c20479a26d67b9054d name: nuxeo-version: 0.3.0.2+version: 0.3.0.3 description: Nuxeo tools category: System homepage: https://github.com/apeyroux/nuxeo#readme bug-reports: https://github.com/apeyroux/nuxeo/issues author: Alexandre Peyroux-maintainer: alex@xn--wxa.email+maintainer: alex@px.io license: BSD3 license-file: LICENSE build-type: Simple@@ -23,6 +23,7 @@ library exposed-modules:+ Nuxeo.ElasticSearch Nuxeo.Log other-modules: Paths_nuxeo@@ -30,13 +31,17 @@ src ghc-options: -Wall build-depends:- attoparsec+ aeson+ , attoparsec , base >=4.2 && <5 , bytestring , conduit , conduit-extra+ , http-conduit+ , http-types , text , time+ , url default-language: Haskell2010 executable nuxeo@@ -45,7 +50,7 @@ Paths_nuxeo hs-source-dirs: app- ghc-options: -Wall+ ghc-options: -Wall -threaded -rtsopts build-depends: base >=4.2 && <5 , nuxeo
+ src/Nuxeo/ElasticSearch.hs view
@@ -0,0 +1,36 @@+{-# LANGUAGE OverloadedStrings #-}++module Nuxeo.ElasticSearch (+ reindex+ ) where++import Data.Aeson (object, (.=))+import qualified Data.ByteString.Char8 as C8+import Network.HTTP.Simple+import Network.URL++-- | POST+-- @+-- {"params":{},"context":{}}+-- @+-- to __"/nuxeo/site/automation/Elasticsearch.Index"__+reindex :: String -> String -> String -> IO (Either String String)+reindex+ instanceLogin+ instancePassword+ instanceUrl =+ -- check if instanceUrl is formated+ case importURL esUrl of+ Just _ -> do+ initReq <- parseRequest req+ let request = setRequestBasicAuth (C8.pack instanceLogin) (C8.pack instancePassword) $ setRequestBodyJSON requestObject initReq+ response <- httpLBS request+ if getResponseStatusCode response /= 204 + then pure $ Left $ "Request error: " <> (show $ getResponseStatusCode response)+ else pure $ Right "Reindexing taken in account"+ Nothing -> pure $ Left "Request error: bad url"+ where+ esUrlPath = "/nuxeo/site/automation/Elasticsearch.Index"+ esUrl = instanceUrl <> esUrlPath+ req = "POST " <> esUrl+ requestObject = object ["params" .= object [], "context" .= object []]