Commit cb654969 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[SECURITY] Prod mode preserves confidentiality of passwords now. (Use Dev for debug only).

parent 7c50b9de
...@@ -29,7 +29,7 @@ import Options.Generic ...@@ -29,7 +29,7 @@ import Options.Generic
import System.Exit (exitSuccess) import System.Exit (exitSuccess)
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.API (startGargantext) -- , startGargantextMock) import Gargantext.API (startGargantext, Mode(..)) -- , startGargantextMock)
-------------------------------------------------------- --------------------------------------------------------
-- Graph Tests -- Graph Tests
...@@ -39,13 +39,10 @@ import Gargantext.API (startGargantext) -- , startGargantextMock) ...@@ -39,13 +39,10 @@ import Gargantext.API (startGargantext) -- , startGargantextMock)
--import qualified Gargantext.Graph.Distances.Matrice as M --import qualified Gargantext.Graph.Distances.Matrice as M
-------------------------------------------------------- --------------------------------------------------------
data Mode = Dev | Mock | Prod
deriving (Show, Read, Generic)
instance ParseRecord Mode instance ParseRecord Mode
instance ParseField Mode instance ParseField Mode
instance ParseFields Mode instance ParseFields Mode
data MyOptions w = data MyOptions w =
MyOptions { run :: w ::: Mode MyOptions { run :: w ::: Mode
<?> "Possible modes: Dev | Mock | Prod" <?> "Possible modes: Dev | Mock | Prod"
...@@ -78,14 +75,12 @@ main = do ...@@ -78,14 +75,12 @@ main = do
Nothing -> 8008 Nothing -> 8008
let start = case myMode of let start = case myMode of
Prod -> startGargantext myPort' (unpack myIniFile') Mock -> panic "[ERROR] Mock mode unsupported"
_ -> startGargantext myMode myPort' (unpack myIniFile')
where where
myIniFile' = case myIniFile of myIniFile' = case myIniFile of
Nothing -> panic "[ERROR] gargantext.ini needed" Nothing -> panic "[ERROR] gargantext.ini needed"
Just i -> i Just i -> i
Dev -> panic "[ERROR] Dev mode unsupported"
Mock -> panic "[ERROR] Mock mode unsupported"
-- _ -> startGargantextMock myPort'
putStrLn $ "Starting with " <> show myMode <> " mode." putStrLn $ "Starting with " <> show myMode <> " mode."
start start
......
...@@ -59,7 +59,7 @@ import Data.Text.Encoding (encodeUtf8) ...@@ -59,7 +59,7 @@ import Data.Text.Encoding (encodeUtf8)
import Data.Validity import Data.Validity
import Data.Version (showVersion) import Data.Version (showVersion)
import GHC.Base (Applicative) import GHC.Base (Applicative)
import GHC.Generics (D1, Meta (..), Rep) import GHC.Generics (D1, Meta (..), Rep, Generic)
import GHC.TypeLits (AppendSymbol, Symbol) import GHC.TypeLits (AppendSymbol, Symbol)
import Gargantext.API.Admin.Auth (AuthContext, auth) import Gargantext.API.Admin.Auth (AuthContext, auth)
import Gargantext.API.Admin.FrontEnd (frontEndServer) import Gargantext.API.Admin.FrontEnd (frontEndServer)
...@@ -85,13 +85,17 @@ import qualified Data.Text.IO as T ...@@ -85,13 +85,17 @@ import qualified Data.Text.IO as T
import qualified Paths_gargantext as PG -- cabal magic build module import qualified Paths_gargantext as PG -- cabal magic build module
data Mode = Dev | Mock | Prod
deriving (Show, Read, Generic)
-- | startGargantext takes as parameters port number and Ini file. -- | startGargantext takes as parameters port number and Ini file.
startGargantext :: PortNumber -> FilePath -> IO () startGargantext :: Mode -> PortNumber -> FilePath -> IO ()
startGargantext port file = do startGargantext mode port file = do
env <- newEnv port file env <- newEnv port file
portRouteInfo port portRouteInfo port
app <- makeApp env app <- makeApp env
mid <- makeDevMiddleware mid <- makeDevMiddleware mode
run port (mid app) `finally` stopGargantext env run port (mid app) `finally` stopGargantext env
portRouteInfo :: PortNumber -> IO () portRouteInfo :: PortNumber -> IO ()
...@@ -183,8 +187,8 @@ makeMockApp env = do ...@@ -183,8 +187,8 @@ makeMockApp env = do
-} -}
makeDevMiddleware :: IO Middleware makeDevMiddleware :: Mode -> IO Middleware
makeDevMiddleware = do makeDevMiddleware mode = do
-- logWare <- mkRequestLogger def { destination = RequestLogger.Logger $ env^.logger } -- logWare <- mkRequestLogger def { destination = RequestLogger.Logger $ env^.logger }
--logWare <- mkRequestLogger def { destination = RequestLogger.Logger "/tmp/logs.txt" } --logWare <- mkRequestLogger def { destination = RequestLogger.Logger "/tmp/logs.txt" }
...@@ -212,7 +216,9 @@ makeDevMiddleware = do ...@@ -212,7 +216,9 @@ makeDevMiddleware = do
-- $ Warp.defaultSettings -- $ Warp.defaultSettings
--pure (warpS, logWare . checkOriginAndHost . corsMiddleware) --pure (warpS, logWare . checkOriginAndHost . corsMiddleware)
pure $ logStdoutDev . corsMiddleware case mode of
Prod -> pure $ logStdout . corsMiddleware
_ -> pure $ logStdoutDev . corsMiddleware
--------------------------------------------------------------------- ---------------------------------------------------------------------
-- | API Global -- | API Global
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment