packages feed

nuxeo 0.3.0.3 → 0.3.1

raw patch · 4 files changed

+87/−50 lines, 4 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Nuxeo.Types: Instance :: Text -> Text -> Text -> Instance
+ Nuxeo.Types: [instanceLogin] :: Instance -> Text
+ Nuxeo.Types: [instancePassword] :: Instance -> Text
+ Nuxeo.Types: [instanceUrl] :: Instance -> Text
+ Nuxeo.Types: data Instance
+ Nuxeo.Types: instance GHC.Read.Read Nuxeo.Types.Instance
+ Nuxeo.Types: instance GHC.Show.Show Nuxeo.Types.Instance
- Nuxeo.ElasticSearch: reindex :: String -> String -> String -> IO (Either String String)
+ Nuxeo.ElasticSearch: reindex :: Instance -> IO (Either Text Text)

Files

app/Main.hs view
@@ -1,45 +1,73 @@+{-# LANGUAGE ApplicativeDo #-} {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RecordWildCards #-}  module Main where -import qualified Data.Text as Text+import qualified Data.Text as T import qualified Data.Text.IO as TIO import           Nuxeo.ElasticSearch import           Nuxeo.Log+import           Nuxeo.Types import           Options.Applicative -data NuxeoCli = NuxeoCli { cliLogFile :: String-                         , cliLogin :: String-                         , cliPassword :: String-                         , cliUrl :: String } -args :: Parser NuxeoCli-args = NuxeoCli-       <$> 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")+data NuxeoOpts = NuxeoOpts {+  instanceLogin :: T.Text+  , instancePassword :: T.Text+  , reindexUrl :: T.Text+  , showErrLogFile :: T.Text } deriving Show ++parseOpts :: Parser NuxeoOpts+parseOpts = helper <*> do+  reindexUrl <- parseReindexUrl+  showErrLogFile <- parseShowErrLogFile+  instanceLogin <- parseInstanceLogin+  instancePassword <- parseInstancePassword+  return (NuxeoOpts {..})+  where+    parseReindexUrl = strOption (long "reindex" <> help "URL of the instance to be reindexed" <> value "")+    parseShowErrLogFile = strOption (long "log" <> help "Log file" <> value "")+    parseInstanceLogin = strOption (long "login" <> short 'u' <> help "Instance login"  <> value "")+    parseInstancePassword = strOption (long "password" <> short 'p' <> help "Instance password"  <> value "")+++parserInfo :: ParserInfo NuxeoOpts+parserInfo = info parseOpts+  (progDesc "Nuxeo CLI"+   <>  header "nuxeo - nuxeo cli tools")++-- | Exemple reindex instance+reindexInstance :: Instance -> IO ()+reindexInstance i = do+  reindexAction <- reindex i+  case reindexAction of+    Left r -> TIO.putStrLn r+    Right r -> TIO.putStrLn r++ -- | Exemple to extract errors from Nuxeo log-nuxeocli :: NuxeoCli -> IO()-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-                                                           )+showErr :: T.Text -> IO()+showErr logFile = (filter (\l -> nuxeoLogEntryType l == Error) <$> parseNuxeoLog (T.unpack logFile))+                                >>= mapM_ (\t -> TIO.putStrLn $+                                                 T.replicate 10 "=" <> "\n"+                                                 <> T.replicate 5 " " <> (T.pack $ show $ nuxeoLogEntryDthr t)+                                                 <> "\n" <> T.replicate 10 "=" <> "\n"+                                                 <> (T.pack $ show $ nuxeoLogEntryType t)+                                                 <> " - "+                                                 <> nuxeoLogEntryAction t+                                                 <> "\n\n"+                                                 <> nuxeoLogEntryLog t+                                          ) -main :: IO()++main :: IO () main = do-  nuxeocli =<< execParser opts-  where-    opts = info (args <**> helper)-      (fullDesc-        <> progDesc "Nuxeo CLI"-        <> header "nuxeo - nuxeo cli tools"-      )++  NuxeoOpts {..} <- execParser parserInfo++  if (instanceLogin /= ""+      && instancePassword /= ""+      && reindexUrl /= "") then reindexInstance (Instance reindexUrl instanceLogin instancePassword) else pure ()+  if showErrLogFile /= "" then showErr showErrLogFile else pure ()
nuxeo.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: cf3e6fd641583c528a2a5475ffe131d7fcc51c3422ff94c20479a26d67b9054d+-- hash: af58711cda0cd6cfb99bec58266edbca4d13e7105cdeeb315116d5760891a58d  name:           nuxeo-version:        0.3.0.3+version:        0.3.1 description:    Nuxeo tools category:       System homepage:       https://github.com/apeyroux/nuxeo#readme@@ -25,6 +25,7 @@   exposed-modules:       Nuxeo.ElasticSearch       Nuxeo.Log+      Nuxeo.Types   other-modules:       Paths_nuxeo   hs-source-dirs:
src/Nuxeo/ElasticSearch.hs view
@@ -4,33 +4,28 @@   reindex   ) where -import           Data.Aeson (object, (.=))-import qualified Data.ByteString.Char8 as C8-import           Network.HTTP.Simple-import           Network.URL+import Data.Aeson (object, (.=))+import Data.Text as Text+import Data.Text.Encoding+import Network.HTTP.Simple+import Network.URL+import Nuxeo.Types --- | POST--- @--- {"params":{},"context":{}}--- @--- to __"/nuxeo/site/automation/Elasticsearch.Index"__-reindex :: String -> String -> String -> IO (Either String String)-reindex-  instanceLogin-  instancePassword-  instanceUrl =+-- | POST @{"params":{},"context":{}}@ to @\/nuxeo\/site\/automation\/Elasticsearch.Index@+reindex :: Instance -> IO (Either Text Text)+reindex i =   -- 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+      let request = setRequestBasicAuth (encodeUtf8 $ instanceLogin i) (encodeUtf8 $ instancePassword i) $ setRequestBodyJSON requestObject initReq       response <- httpLBS request       if getResponseStatusCode response /= 204 -        then pure $ Left $ "Request error: " <> (show $ getResponseStatusCode response)+        then pure $ Left $ "Request error: " <> (Text.pack $ 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+    esUrl = (Text.unpack $ instanceUrl i) <> esUrlPath     req = "POST " <> esUrl     requestObject = object ["params" .= object [], "context"  .= object []]
+ src/Nuxeo/Types.hs view
@@ -0,0 +1,13 @@+{-# LANGUAGE OverloadedStrings #-}++module Nuxeo.Types (+  Instance (..)+  ) where++import Data.Text ++data Instance = Instance {+  instanceUrl :: Text+  , instanceLogin :: Text+  , instancePassword :: Text+  } deriving (Read, Show)