Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
154
Issues
154
List
Board
Labels
Milestones
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
haskell-gargantext
Commits
0902bab3
Verified
Commit
0902bab3
authored
Sep 18, 2024
by
Przemyslaw Kaminski
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[config] some Settings moved directly to GargConfig
Eventually, Settings will be removed
parent
5c443218
Pipeline
#6659
passed with stages
in 74 minutes and 18 seconds
Changes
13
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
83 additions
and
92 deletions
+83
-92
Ini.hs
bin/gargantext-cli/CLI/Ini.hs
+2
-1
API.hs
src/Gargantext/API.hs
+10
-9
EnvTypes.hs
src/Gargantext/API/Admin/EnvTypes.hs
+1
-0
Settings.hs
src/Gargantext/API/Admin/Settings.hs
+8
-12
Types.hs
src/Gargantext/API/Admin/Types.hs
+1
-17
Dev.hs
src/Gargantext/API/Dev.hs
+1
-1
ShareURL.hs
src/Gargantext/API/Node/ShareURL.hs
+4
-7
Config.hs
src/Gargantext/Core/Config.hs
+3
-3
Types.hs
src/Gargantext/Core/Config/Types.hs
+22
-0
Node.hs
src/Gargantext/Database/Action/Node.hs
+11
-13
ReverseProxy.hs
src/Gargantext/MicroServices/ReverseProxy.hs
+16
-19
Setup.hs
test/Test/API/Setup.hs
+3
-9
Setup.hs
test/Test/Database/Setup.hs
+1
-1
No files found.
bin/gargantext-cli/CLI/Ini.hs
View file @
0902bab3
...
...
@@ -83,7 +83,8 @@ mkFrontendConfig (Ini.GargConfig { .. }) =
,
_fc_url_backend_api
=
_gc_url_backend_api
,
_fc_jwt_settings
=
"TODO"
,
_fc_cors
,
_fc_microservices
}
,
_fc_microservices
,
_fc_appPort
=
3000
}
where
_fc_cors
=
CTypes
.
CORSSettings
{
_corsAllowedOrigins
=
[
toCORSOrigin
"https://demo.gargantext.org"
...
...
src/Gargantext/API.hs
View file @
0902bab3
...
...
@@ -30,12 +30,12 @@ Pouillard (who mainly made it).
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module
Gargantext.API
where
import
Control.Concurrent
import
Control.Concurrent.Async
qualified
as
Async
import
Control.Lens
hiding
(
Level
)
import
Data.Cache
qualified
as
InMemory
import
Data.List
(
lookup
)
import
Data.Set
qualified
as
Set
...
...
@@ -44,18 +44,18 @@ import Data.Text.Encoding qualified as TE
import
Data.Text.IO
(
putStrLn
)
import
Data.Validity
import
Gargantext.API.Admin.Auth.Types
(
AuthContext
)
import
Gargantext.API.Admin.EnvTypes
(
Env
,
Mode
(
..
),
_
env_config
)
import
Gargantext.API.Admin.EnvTypes
(
Env
,
Mode
(
..
),
env_config
)
import
Gargantext.API.Admin.Settings
(
newEnv
)
import
Gargantext.API.Admin.Types
(
FireWall
(
..
),
MicroServicesProxyStatus
(
..
),
PortNumber
,
cookieSettings
,
jwtSettings
,
settings
,
corsSettings
,
microServicesProxyStatu
s
)
import
Gargantext.API.Admin.Types
(
FireWall
(
..
),
cookieSettings
,
jwtSettings
,
setting
s
)
import
Gargantext.API.Middleware
(
logStdoutDevSanitised
)
import
Gargantext.API.Routes.Named
(
API
)
import
Gargantext.API.Routes.Named.EKG
import
Gargantext.API.Server.Named
(
server
)
import
Gargantext.Core.Config
(
_gc_notifications
_config
)
import
Gargantext.Core.Config.Types
(
CORSOrigin
(
..
),
CORSSettings
,
NotificationsConfig
(
..
),
SettingsFile
(
..
),
corsAllowedOrigin
s
)
import
Gargantext.Core.Config
(
gc_notifications_config
,
gc_frontend
_config
)
import
Gargantext.Core.Config.Types
(
CORSOrigin
(
..
),
CORSSettings
,
MicroServicesProxyStatus
(
..
),
NotificationsConfig
(
..
),
PortNumber
,
SettingsFile
(
..
),
corsAllowedOrigins
,
fc_cors
,
microServicesProxyStatu
s
)
import
Gargantext.Database.Prelude
qualified
as
DB
import
Gargantext.MicroServices.ReverseProxy
(
microServicesProxyApp
)
import
Gargantext.Prelude
hiding
(
putStrLn
)
import
Gargantext.Prelude
hiding
(
putStrLn
,
to
)
import
Gargantext.System.Logging
import
Network.HTTP.Types
hiding
(
Query
)
import
Network.Wai
...
...
@@ -73,11 +73,12 @@ import System.Cron.Schedule qualified as Cron
startGargantext
::
Mode
->
PortNumber
->
SettingsFile
->
IO
()
startGargantext
mode
port
sf
@
(
SettingsFile
settingsFile
)
=
withLoggerHoisted
mode
$
\
logger
->
do
env
<-
newEnv
logger
port
sf
let
proxyStatus
=
microServicesProxyStatus
(
env
^.
settings
)
let
fc
=
env
^.
env_config
.
gc_frontend_config
let
proxyStatus
=
microServicesProxyStatus
fc
runDbCheck
env
portRouteInfo
(
_gc_notifications_config
$
_env_config
env
)
port
proxyStatus
portRouteInfo
(
env
^.
env_config
.
gc_notifications_config
)
port
proxyStatus
app
<-
makeApp
env
mid
<-
makeGargMiddleware
(
env
^.
settings
.
corsSetting
s
)
mode
mid
<-
makeGargMiddleware
(
fc
^.
fc_cor
s
)
mode
periodicActions
<-
schedulePeriodicActions
env
let
runServer
=
run
port
(
mid
app
)
`
finally
`
stopGargantext
periodicActions
...
...
src/Gargantext/API/Admin/EnvTypes.hs
View file @
0902bab3
...
...
@@ -10,6 +10,7 @@ module Gargantext.API.Admin.EnvTypes (
,
Mode
(
..
)
,
modeToLoggingLevels
,
mkJobHandle
,
env_config
,
env_logger
,
env_manager
,
env_settings
...
...
src/Gargantext/API/Admin/Settings.hs
View file @
0902bab3
...
...
@@ -32,8 +32,8 @@ import Gargantext.API.Errors.Types
import
Gargantext.API.Prelude
import
Gargantext.Core.AsyncUpdates.CentralExchange
qualified
as
CE
import
Gargantext.Core.AsyncUpdates.Dispatcher
qualified
as
D
import
Gargantext.Core.Config
(
GargConfig
(
..
),
gc_jobs
)
import
Gargantext.Core.Config.Types
(
SettingsFile
(
..
),
_fc_cors
,
_fc_microservices
,
jc_js_job_timeout
,
jc_js_id_timeout
)
import
Gargantext.Core.Config
(
GargConfig
(
..
),
gc_jobs
,
gc_frontend_config
)
import
Gargantext.Core.Config.Types
(
PortNumber
,
SettingsFile
(
..
),
fc_appPort
,
jc_js_job_timeout
,
jc_js_id_timeout
)
import
Gargantext.Core.Config.Utils
(
readConfig
)
import
Gargantext.Core.NLP
(
nlpServerMap
)
import
Gargantext.Core.NodeStory
...
...
@@ -59,20 +59,16 @@ newtype JwkFile = JwkFile { _JwkFile :: FilePath }
newtype
IniFile
=
IniFile
{
_IniFile
::
FilePath
}
deriving
(
Show
,
Eq
,
IsString
)
devSettings
::
JwkFile
->
SettingsFile
->
IO
Settings
devSettings
(
JwkFile
jwkFile
)
settingsFile
=
do
devSettings
::
JwkFile
->
IO
Settings
devSettings
(
JwkFile
jwkFile
)
=
do
jwkExists
<-
doesFileExist
jwkFile
when
(
not
jwkExists
)
$
writeKey
jwkFile
jwk
<-
readKey
jwkFile
-- GargTomlSettings{..} <- loadGargTomlSettings settingsFile
gc
@
(
GargConfig
{})
<-
readConfig
settingsFile
pure
$
Settings
{
-- _corsSettings = _gargCorsSettings
_corsSettings
=
_fc_cors
$
_gc_frontend_config
gc
-- , _microservicesSettings = _gargMicroServicesSettings
,
_microservicesSettings
=
_fc_microservices
$
_gc_frontend_config
gc
,
_appPort
=
3000
,
_logLevelLimit
=
LevelDebug
_logLevelLimit
=
LevelDebug
-- , _dbServer = "localhost"
,
_sendLoginEmails
=
LogEmailToConsole
,
_scrapydUrl
=
fromMaybe
(
panicTrace
"Invalid scrapy URL"
)
$
parseBaseUrl
"http://localhost:6800"
...
...
@@ -187,11 +183,11 @@ devJwkFile = JwkFile "dev.jwk"
newEnv
::
Logger
(
GargM
Env
BackendInternalError
)
->
PortNumber
->
SettingsFile
->
IO
Env
newEnv
logger
port
settingsFile
@
(
SettingsFile
sf
)
=
do
!
manager_env
<-
newTlsManager
!
settings'
<-
devSettings
devJwkFile
settingsFile
<&>
appPort
.~
port
-- TODO read from 'file'
when
(
port
/=
settings'
^.
appPort
)
$
!
settings'
<-
devSettings
devJwkFile
!
config_env
<-
readConfig
settingsFile
<&>
(
gc_frontend_config
.
fc_appPort
)
.~
port
-- TODO read from 'file'
when
(
port
/=
config_env
^.
gc_frontend_config
.
fc_appPort
)
$
panicTrace
"TODO: conflicting settings of port"
!
config_env
<-
readConfig
settingsFile
prios
<-
withLogger
()
$
\
ioLogger
->
Jobs
.
readPrios
ioLogger
(
sf
<>
".jobs"
)
let
prios'
=
Jobs
.
applyPrios
prios
Jobs
.
defaultPrios
putStrLn
(
"Overrides: "
<>
show
prios
::
Text
)
...
...
src/Gargantext/API/Admin/Types.hs
View file @
0902bab3
...
...
@@ -5,13 +5,11 @@ module Gargantext.API.Admin.Types where
import
Control.Lens
import
Control.Monad.Logger
(
LogLevel
)
import
GHC.Enum
import
Gargantext.Core.Config.Types
import
Gargantext.Prelude
import
Servant.Auth.Server
(
JWTSettings
,
CookieSettings
(
..
))
import
Servant.Client
(
BaseUrl
)
type
PortNumber
=
Int
data
SendEmailType
=
SendEmailViaAws
|
LogEmailToConsole
...
...
@@ -19,10 +17,7 @@ data SendEmailType = SendEmailViaAws
deriving
(
Show
,
Read
,
Enum
,
Bounded
,
Generic
)
data
Settings
=
Settings
{
_corsSettings
::
!
CORSSettings
-- CORS settings
,
_microservicesSettings
::
!
MicroServicesSettings
,
_appPort
::
!
PortNumber
,
_logLevelLimit
::
!
LogLevel
-- log level from the monad-logger package
{
_logLevelLimit
::
!
LogLevel
-- log level from the monad-logger package
-- , _dbServer :: Text
-- ^ this is not used yet
,
_jwtSettings
::
!
JWTSettings
...
...
@@ -33,17 +28,6 @@ data Settings = Settings
makeLenses
''
S
ettings
data
MicroServicesProxyStatus
=
PXY_enabled
PortNumber
|
PXY_disabled
deriving
(
Show
,
Eq
)
microServicesProxyStatus
::
Settings
->
MicroServicesProxyStatus
microServicesProxyStatus
stgs
=
if
stgs
^.
microservicesSettings
.
msProxyEnabled
then
PXY_enabled
(
stgs
^.
microservicesSettings
.
msProxyPort
)
else
PXY_disabled
class
HasSettings
env
where
settings
::
Getter
env
Settings
...
...
src/Gargantext/API/Dev.hs
View file @
0902bab3
...
...
@@ -42,7 +42,7 @@ withDevEnv settingsFile k = withLoggerHoisted Dev $ \logger -> do
--nodeStory_env <- fromDBNodeStoryEnv (_gc_repofilepath cfg)
pool
<-
newPool
(
_gc_database_config
cfg
)
nodeStory_env
<-
fromDBNodeStoryEnv
pool
setts
<-
devSettings
devJwkFile
settingsFile
setts
<-
devSettings
devJwkFile
pure
$
DevEnv
{
_dev_env_pool
=
pool
,
_dev_env_logger
=
logger
...
...
src/Gargantext/API/Node/ShareURL.hs
View file @
0902bab3
...
...
@@ -7,11 +7,10 @@ module Gargantext.API.Node.ShareURL where
import
Control.Lens
import
Data.Text
qualified
as
T
import
Data.Validity
qualified
as
V
import
Gargantext.API.Admin.Types
(
appPort
,
settings
,
Settings
)
import
Gargantext.API.Prelude
import
Gargantext.API.Routes.Named.Share
qualified
as
Named
import
Gargantext.Core.Config
(
GargConfig
,
gc_frontend_config
)
import
Gargantext.Core.Config.Types
(
fc_url
)
import
Gargantext.Core.Config.Types
(
fc_
appPort
,
fc_
url
)
import
Gargantext.Core.Types
(
NodeType
,
NodeId
,
unNodeId
,
_ValidationError
)
import
Gargantext.Database.Prelude
(
HasConfig
(
hasConfig
),
CmdCommon
)
import
Gargantext.Prelude
...
...
@@ -29,19 +28,17 @@ getUrl :: (IsGargServer env err m, CmdCommon env)
getUrl
nt
id
=
do
-- TODO add check that the node is able to be shared (in a shared folder)
gc
<-
view
hasConfig
urlPort
<-
view
settings
case
get_url
nt
id
gc
urlPort
of
case
get_url
nt
id
gc
of
Left
err
->
throwError
$
_ValidationError
#
(
V
.
check
False
err
)
Right
shareLink
->
pure
shareLink
get_url
::
Maybe
NodeType
->
Maybe
NodeId
->
GargConfig
->
Settings
->
Either
String
Named
.
ShareLink
get_url
nt
id
gc
stgs
=
do
get_url
nt
id
gc
=
do
let
urlHost
=
T
.
unpack
$
gc
^.
gc_frontend_config
.
fc_url
let
urlPort
=
stgs
^.
appPort
let
urlPort
=
gc
^.
gc_frontend_config
.
fc_
appPort
t
<-
maybe
(
Left
"Invalid node Type"
)
Right
nt
i
<-
maybe
(
Left
"Invalid node ID"
)
Right
id
...
...
src/Gargantext/Core/Config.hs
View file @
0902bab3
...
...
@@ -103,8 +103,8 @@ instance ToTable GargConfig where
]
mkProxyUrl
::
GargConfig
->
MicroServicesSettings
->
BaseUrl
mkProxyUrl
GargConfig
{
..
}
MicroServicesSettings
{
..
}
=
mkProxyUrl
::
GargConfig
->
BaseUrl
mkProxyUrl
GargConfig
{
..
}
=
case
parseBaseUrl
(
T
.
unpack
$
_fc_url
_gc_frontend_config
)
of
Nothing
->
BaseUrl
Http
"localhost"
80
""
Just
bh
->
bh
{
baseUrlPort
=
_msProxyPort
}
Just
bh
->
bh
{
baseUrlPort
=
_msProxyPort
$
_fc_microservices
_gc_frontend_config
}
src/Gargantext/Core/Config/Types.hs
View file @
0902bab3
...
...
@@ -25,6 +25,7 @@ module Gargantext.Core.Config.Types
,
f_visio_url
,
f_searx_url
,
f_istex_url
,
PortNumber
,
FrontendConfig
(
..
)
,
fc_url
,
fc_backend_name
...
...
@@ -32,6 +33,9 @@ module Gargantext.Core.Config.Types
,
fc_jwt_settings
,
fc_cors
,
fc_microservices
,
fc_appPort
,
MicroServicesProxyStatus
(
..
)
,
microServicesProxyStatus
,
JobsConfig
(
..
)
,
jc_max_docs_parsers
,
jc_max_docs_scrapers
...
...
@@ -179,6 +183,10 @@ instance ToTable FramesConfig where
makeLenses
''
F
ramesConfig
type
PortNumber
=
Int
-- TODO jwtSettings = defaultJWTSettings
data
FrontendConfig
=
FrontendConfig
{
_fc_url
::
!
Text
,
_fc_backend_name
::
!
Text
...
...
@@ -186,6 +194,7 @@ data FrontendConfig =
,
_fc_jwt_settings
::
!
Text
,
_fc_cors
::
!
CORSSettings
,
_fc_microservices
::
!
MicroServicesSettings
,
_fc_appPort
::
!
PortNumber
}
deriving
(
Generic
,
Show
)
instance
FromValue
FrontendConfig
where
...
...
@@ -196,6 +205,7 @@ instance FromValue FrontendConfig where
_fc_jwt_settings
<-
reqKey
"jwt_settings"
_fc_cors
<-
reqKey
"cors"
_fc_microservices
<-
reqKey
"microservices"
let
_fc_appPort
=
3000
return
$
FrontendConfig
{
..
}
instance
ToValue
FrontendConfig
where
toValue
=
defaultTableToValue
...
...
@@ -209,6 +219,18 @@ instance ToTable FrontendConfig where
makeLenses
''
F
rontendConfig
data
MicroServicesProxyStatus
=
PXY_enabled
PortNumber
|
PXY_disabled
deriving
(
Show
,
Eq
)
microServicesProxyStatus
::
FrontendConfig
->
MicroServicesProxyStatus
microServicesProxyStatus
fc
=
if
fc
^.
fc_microservices
.
msProxyEnabled
then
PXY_enabled
(
fc
^.
fc_microservices
.
msProxyPort
)
else
PXY_disabled
data
SecretsConfig
=
SecretsConfig
{
_s_master_user
::
!
Text
...
...
src/Gargantext/Database/Action/Node.hs
View file @
0902bab3
...
...
@@ -19,10 +19,9 @@ module Gargantext.Database.Action.Node
import
Control.Lens
(
view
)
import
Data.Text
qualified
as
T
import
Gargantext.API.Admin.Types
(
settings
,
_microservicesSettings
,
HasSettings
)
import
Gargantext.Core
import
Gargantext.Core.Config
(
GargConfig
(
..
),
mkProxyUrl
)
import
Gargantext.Core.Config.Types
(
FramesConfig
(
..
),
MicroServicesSettings
(
..
),
SecretsConfig
(
..
))
import
Gargantext.Core.Config
(
GargConfig
(
..
),
gc_frames
,
gc_frontend_config
,
mkProxyUrl
)
import
Gargantext.Core.Config.Types
(
FramesConfig
(
..
),
f_write_url
,
fc_microservices
,
MicroServicesSettings
(
..
),
SecretsConfig
(
..
))
import
Gargantext.Core.Types
(
Name
)
import
Gargantext.Database.Admin.Types.Hyperdata
import
Gargantext.Database.Admin.Types.Hyperdata.Default
...
...
@@ -37,7 +36,7 @@ import Servant.Client.Core.BaseUrl
------------------------------------------------------------------------
-- | TODO mk all others nodes
mkNodeWithParent
::
(
HasNodeError
err
,
HasDBid
NodeType
,
HasSettings
env
)
mkNodeWithParent
::
(
HasNodeError
err
,
HasDBid
NodeType
)
=>
NodeType
->
Maybe
ParentId
->
UserId
...
...
@@ -71,7 +70,7 @@ mkNodeWithParent nt (Just pId) uId name = (:[]) <$> insertNode nt (Just name) N
-- | Sugar to create a node, get its NodeId and update its Hyperdata after
mkNodeWithParent_ConfigureHyperdata
::
(
HasNodeError
err
,
HasDBid
NodeType
,
HasSettings
env
)
mkNodeWithParent_ConfigureHyperdata
::
(
HasNodeError
err
,
HasDBid
NodeType
)
=>
NodeType
->
Maybe
ParentId
->
UserId
...
...
@@ -95,15 +94,15 @@ mkNodeWithParent_ConfigureHyperdata _ _ _ _ = nodeError NotImplYet
-- | Creates the base URL for the notes microservices proxy, or defaults
-- to the notes microservice if the proxy has been disabled from the settings.
internalNotesProxy
::
GargConfig
->
MicroServicesSettings
->
T
.
Text
internalNotesProxy
cfg
msSettings
|
_msProxyEnabled
msSettings
=
T
.
pack
$
showBaseUrl
proxyUrl
<>
"/notes"
|
otherwise
=
_f_write_url
$
_gc_frames
cfg
internalNotesProxy
::
GargConfig
->
T
.
Text
internalNotesProxy
cfg
|
_msProxyEnabled
(
cfg
^.
gc_frontend_config
.
fc_microservices
)
=
T
.
pack
$
showBaseUrl
proxyUrl
<>
"/notes"
|
otherwise
=
cfg
^.
gc_frames
.
f_write_url
where
proxyUrl
=
mkProxyUrl
cfg
msSettings
proxyUrl
=
mkProxyUrl
cfg
-- | Function not exposed
mkNodeWithParent_ConfigureHyperdata'
::
(
HasNodeError
err
,
HasDBid
NodeType
,
HasSettings
env
)
mkNodeWithParent_ConfigureHyperdata'
::
(
HasNodeError
err
,
HasDBid
NodeType
)
=>
NodeType
->
Maybe
ParentId
->
UserId
...
...
@@ -117,9 +116,8 @@ mkNodeWithParent_ConfigureHyperdata' nt (Just i) uId name = do
_
->
nodeError
NeedsConfiguration
cfg
<-
view
hasConfig
stt
<-
view
settings
u
<-
case
nt
of
Notes
->
pure
$
internalNotesProxy
cfg
(
_microservicesSettings
stt
)
Notes
->
pure
$
internalNotesProxy
cfg
Calc
->
pure
$
_f_calc_url
$
_gc_frames
cfg
NodeFrameVisio
->
pure
$
_f_visio_url
$
_gc_frames
cfg
_
->
nodeError
NeedsConfiguration
...
...
src/Gargantext/MicroServices/ReverseProxy.hs
View file @
0902bab3
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ViewPatterns #-}
...
...
@@ -17,8 +16,6 @@ module Gargantext.MicroServices.ReverseProxy (
,
FrameId
(
..
)
)
where
import
Prelude
import
Conduit
import
Data.ByteString
qualified
as
B
import
Data.ByteString.Builder
...
...
@@ -158,7 +155,7 @@ type ProxyCache = InMemory.Cache FrameId NodeId
microServicesProxyApp
::
ProxyCache
->
Env
->
Application
microServicesProxyApp
cache
env
=
genericServeTWithContext
id
(
server
cache
env
)
cfg
microServicesProxyApp
cache
env
=
genericServeTWithContext
id
entity
(
server
cache
env
)
cfg
where
cfg
::
Context
AuthContext
cfg
=
env
^.
settings
.
jwtSettings
...
...
@@ -212,10 +209,10 @@ notesProxyImplementation :: ProxyCache -> Env -> NotesProxy AsServer
notesProxyImplementation
cache
env
=
NotesProxy
{
slideEp
=
\
frameId
->
slideProxyServer
env
frameId
,
publishEp
=
\
frameId
->
publishProxyServer
cache
env
frameId
,
configFile
=
defaultForwardServerWithSettings
sty
id
env
(
configFileSettings
env
sty
)
,
configFile
=
defaultForwardServerWithSettings
sty
id
entity
env
(
configFileSettings
env
sty
)
,
notesSocket
=
socketIOProxyImplementation
sty
env
,
meEndpoint
=
proxyPassServer
sty
env
,
notesEp
=
\
frameId
mbNodeId
->
notesForwardServer
cache
frameId
mbNodeId
sty
id
env
,
notesEp
=
\
frameId
mbNodeId
->
notesForwardServer
cache
frameId
mbNodeId
sty
id
entity
env
,
notesStaticAssets
=
proxyPassServer
sty
env
}
where
...
...
@@ -224,7 +221,7 @@ notesProxyImplementation cache env = NotesProxy {
socketIOProxyImplementation
::
ServiceType
->
Env
->
SocketIOProxy
AsServer
socketIOProxyImplementation
sty
env
=
SocketIOProxy
{
socketIoEp
=
\
_noteId
->
defaultForwardServer
sty
id
id
env
socketIoEp
=
\
_noteId
->
defaultForwardServer
sty
id
entity
identity
env
}
removeServiceFromPath
::
ServiceType
->
Request
->
Request
...
...
@@ -236,7 +233,7 @@ removeServiceFromPath sty = removeProxyPath (T.pack $ serviceTypeToProxyPath sty
slideProxyServer
::
Env
->
FrameId
->
ServerT
Raw
m
slideProxyServer
env
(
FrameId
frameId
)
=
defaultForwardServer
ST_notes
(
\
rq
->
rq
{
rawPathInfo
=
changePath
(
rawPathInfo
rq
)
})
id
env
defaultForwardServer
ST_notes
(
\
rq
->
rq
{
rawPathInfo
=
changePath
(
rawPathInfo
rq
)
})
id
entity
env
where
changePath
::
ByteString
->
ByteString
changePath
_
=
TE
.
encodeUtf8
$
"/p/"
<>
frameId
<>
"#/"
...
...
@@ -253,7 +250,7 @@ publishProxyServer cache env frameId = Tagged $ \req res -> do
Just
nodeId
->
do
-- Using a mock for now.
case
Share
.
get_url
(
Just
Notes
)
(
Just
nodeId
)
(
_env_config
env
)
(
_env_settings
env
)
of
case
Share
.
get_url
(
Just
Notes
)
(
Just
nodeId
)
(
_env_config
env
)
of
Left
_e
->
-- Invalid link, treat this as a normal proxy
forwardRaw
req
res
...
...
@@ -264,14 +261,14 @@ publishProxyServer cache env frameId = Tagged $ \req res -> do
where
forwardRaw
=
unTagged
(
defaultForwardServer
ST_notes
(
\
rq
->
rq
{
rawPathInfo
=
changePath
(
rawPathInfo
rq
)
})
id
env
)
unTagged
(
defaultForwardServer
ST_notes
(
\
rq
->
rq
{
rawPathInfo
=
changePath
(
rawPathInfo
rq
)
})
id
entity
env
)
changePath
::
ByteString
->
ByteString
changePath
_
=
TE
.
encodeUtf8
$
"/s/"
<>
(
_FrameId
frameId
)
-- Generic server forwarder
proxyPassServer
::
ServiceType
->
Env
->
ServerT
Raw
m
proxyPassServer
sty
env
=
defaultForwardServer
sty
id
id
env
proxyPassServer
sty
env
=
defaultForwardServer
sty
id
entity
identity
env
mkProxyDestination
::
Env
->
ProxyDestination
mkProxyDestination
env
=
fromMaybe
(
panicTrace
"Invalid URI found in the proxied Request."
)
$
do
...
...
@@ -284,8 +281,8 @@ mkProxyDestination env = fromMaybe (panicTrace "Invalid URI found in the proxied
removeFromReferer
::
T
.
Text
->
Request
->
Request
removeFromReferer
pth
originalRequest
=
originalRequest
{
requestHeaders
=
(
Prelude
.
map
tweakReferer
(
requestHeaders
originalRequest
)
)
}
originalRequest
{
requestHeaders
=
map
tweakReferer
(
requestHeaders
originalRequest
)
}
where
tweakReferer
::
Header
->
Header
tweakReferer
(
k
,
v
)
...
...
@@ -295,7 +292,7 @@ removeFromReferer pth originalRequest =
=
(
k
,
v
)
proxyUrl
::
Env
->
BaseUrl
proxyUrl
env
=
mkProxyUrl
(
env
^.
hasConfig
)
(
env
^.
env_settings
.
microservicesSettings
)
proxyUrl
env
=
mkProxyUrl
(
env
^.
hasConfig
)
notesForwardServer
::
ProxyCache
->
FrameId
...
...
@@ -307,7 +304,7 @@ notesForwardServer :: ProxyCache
notesForwardServer
cache
frameId
mbNodeId
sty
presendModifyRequest
env
=
case
mbNodeId
of
Nothing
->
defaultForwardServer
sty
presendModifyRequest
id
env
->
defaultForwardServer
sty
presendModifyRequest
id
entity
env
Just
nid
->
do
-- Persist the node id in the cache
...
...
@@ -317,7 +314,7 @@ notesForwardServer cache frameId mbNodeId sty presendModifyRequest env =
where
setFrameIdCookie
::
FrameId
->
NodeId
->
(
ResponseHeaders
->
ResponseHeaders
)
setFrameIdCookie
(
FrameId
(
T
.
unpack
->
fid
))
(
UnsafeMkNodeId
nid
)
origHeaders
=
let
sk
=
(
hSetCookie
,
fromString
$
fid
<>
"="
<>
Prelude
.
show
nid
)
=
let
sk
=
(
hSetCookie
,
fromString
$
fid
<>
"="
<>
show
nid
)
in
sk
:
origHeaders
defaultForwardServerWithSettings
::
ServiceType
...
...
@@ -326,7 +323,7 @@ defaultForwardServerWithSettings :: ServiceType
->
WaiProxySettings
->
ServerT
Raw
m
defaultForwardServerWithSettings
sty
presendModifyRequest
env
proxySettings
=
Tagged
$
waiProxyToSettings
forwardRequest
(
proxySettings
)
(
env
^.
env_manager
)
Tagged
$
waiProxyToSettings
forwardRequest
proxySettings
(
env
^.
env_manager
)
where
proxyDestination
::
ProxyDestination
...
...
@@ -360,7 +357,7 @@ defaultForwardServer sty presendModifyRequest mapRespHeaders env =
defaultForwardServerWithSettings
sty
presendModifyRequest
env
$
defaultWaiProxySettings
{
wpsProcessBody
=
\
_req
_res
->
Just
$
replaceRelativeLinks
proxyDestination
proxyPath
,
wpsModifyResponseHeaders
=
\
_req
_res
->
(
mapRespHeaders
.
tweakResponseHeaders
)
,
wpsModifyResponseHeaders
=
\
_req
_res
->
mapRespHeaders
.
tweakResponseHeaders
,
wpsRedirectCounts
=
5
}
where
...
...
@@ -382,7 +379,7 @@ noCache hdrs = (hCacheControl, fromString "no-cache") : filter ((/=) hCacheContr
-- | Tweak the response headers so that they will have a bit more permissive
-- 'Content-Security-Policy'.
tweakResponseHeaders
::
ResponseHeaders
->
ResponseHeaders
tweakResponseHeaders
=
Prelude
.
map
tweakHeader
tweakResponseHeaders
=
map
tweakHeader
where
tweakHeader
(
k
,
v
)
|
k
==
"Content-Security-Policy"
...
...
test/Test/API/Setup.hs
View file @
0902bab3
...
...
@@ -13,16 +13,10 @@ import Data.Streaming.Network (bindPortTCP)
import
Gargantext.API
(
makeApp
)
import
Gargantext.API.Admin.EnvTypes
(
Mode
(
Mock
),
Env
(
..
))
import
Gargantext.API.Admin.Settings
import
Gargantext.API.Admin.Types
import
Gargantext.API.Errors.Types
import
Gargantext.API.Prelude
import
Gargantext.Core.AsyncUpdates.CentralExchange
qualified
as
CE
import
Gargantext.Core.AsyncUpdates.Dispatcher
qualified
as
D
import
Gargantext.Core.AsyncUpdates.Dispatcher.Types
qualified
as
DT
import
Gargantext.Core.Config
import
Gargantext.Core.Config.Mail
qualified
as
Mail
import
Gargantext.Core.Config.NLP
qualified
as
NLP
import
Gargantext.Core.Config.Types
(
SettingsFile
(
..
),
jc_js_job_timeout
,
jc_js_id_timeout
)
import
Gargantext.Core.Config.Types
(
SettingsFile
(
..
),
jc_js_job_timeout
,
jc_js_id_timeout
,
fc_appPort
)
import
Gargantext.Core.Config.Utils
(
readConfig
)
import
Gargantext.Core.NLP
import
Gargantext.Core.NodeStory
...
...
@@ -61,9 +55,9 @@ newTestEnv :: TestEnv -> Logger (GargM Env BackendInternalError) -> Warp.Port ->
newTestEnv
testEnv
logger
port
=
do
tomlFile
@
(
SettingsFile
sf
)
<-
fakeTomlPath
!
manager_env
<-
newTlsManager
!
settings'
<-
devSettings
devJwkFile
tomlFile
<&>
appPort
.~
port
!
settings'
<-
devSettings
devJwkFile
!
config_env
<-
readConfig
tomlFile
!
config_env
<-
readConfig
tomlFile
<&>
(
gc_frontend_config
.
fc_appPort
)
.~
port
prios
<-
withLogger
()
$
\
ioLogger
->
Jobs
.
readPrios
ioLogger
(
sf
<>
".jobs"
)
let
prios'
=
Jobs
.
applyPrios
prios
Jobs
.
defaultPrios
!
self_url_env
<-
parseBaseUrl
$
"http://0.0.0.0:"
<>
show
port
...
...
test/Test/Database/Setup.hs
View file @
0902bab3
...
...
@@ -76,7 +76,7 @@ setup = do
bootstrapDB
db
pool
gargConfig
ugen
<-
emptyCounter
test_nodeStory
<-
fromDBNodeStoryEnv
pool
stgs
<-
devSettings
devJwkFile
=<<
fakeTomlPath
stgs
<-
devSettings
devJwkFile
withLoggerHoisted
Mock
$
\
logger
->
do
pure
$
TestEnv
{
test_db
=
DBHandle
pool
db
,
test_config
=
gargConfig
...
...
Przemyslaw Kaminski
@cgenie
mentioned in commit
5660aec0
·
Oct 08, 2024
mentioned in commit
5660aec0
mentioned in commit 5660aec07ec5a0a0a5468f440092c1a8f57a864e
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment