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
160
Issues
160
List
Board
Labels
Milestones
Merge Requests
14
Merge Requests
14
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
3b3f5109
Verified
Commit
3b3f5109
authored
Sep 04, 2024
by
Przemyslaw Kaminski
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[CLI] INI to TOML works now
parent
19f4848f
Pipeline
#6581
failed with stages
in 11 minutes and 38 seconds
Changes
15
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
551 additions
and
59 deletions
+551
-59
Ini.hs
bin/gargantext-cli/CLI/Ini.hs
+121
-0
Init.hs
bin/gargantext-cli/CLI/Init.hs
+0
-1
Invitations.hs
bin/gargantext-cli/CLI/Invitations.hs
+0
-2
Parsers.hs
bin/gargantext-cli/CLI/Parsers.hs
+0
-1
Types.hs
bin/gargantext-cli/CLI/Types.hs
+5
-1
Upgrade.hs
bin/gargantext-cli/CLI/Upgrade.hs
+0
-1
Main.hs
bin/gargantext-cli/Main.hs
+4
-0
gargantext.cabal
gargantext.cabal
+7
-0
Config.hs
src/Gargantext/Core/Config.hs
+29
-44
Ini.hs
src/Gargantext/Core/Config/Ini/Ini.hs
+147
-0
Mail.hs
src/Gargantext/Core/Config/Ini/Mail.hs
+87
-0
NLP.hs
src/Gargantext/Core/Config/Ini/NLP.hs
+62
-0
Mail.hs
src/Gargantext/Core/Config/Mail.hs
+11
-1
NLP.hs
src/Gargantext/Core/Config/NLP.hs
+7
-1
Types.hs
src/Gargantext/Core/Config/Types.hs
+71
-7
No files found.
bin/gargantext-cli/CLI/Ini.hs
0 → 100644
View file @
3b3f5109
{-|
Module : Ini.hs
Description : Gargantext Ini file
Copyright : (c) CNRS, 2024-Present
License : AGPL + CECILL v3
Maintainer : team@gargantext.org
Stability : experimental
Portability : POSIX
Import a corpus binary.
-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE Strict #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeApplications #-}
module
CLI.Ini
where
import
CLI.Types
import
Data.Text
qualified
as
T
import
Database.PostgreSQL.Simple
qualified
as
PGS
import
Gargantext.Core.Config
qualified
as
Config
import
Gargantext.Core.Config.Ini.Ini
qualified
as
Ini
import
Gargantext.Core.Config.Ini.Mail
qualified
as
IniMail
import
Gargantext.Core.Config.Ini.NLP
qualified
as
IniNLP
import
Gargantext.Core.Config.Types
qualified
as
CTypes
import
Gargantext.Prelude
import
Options.Applicative
import
Servant.Client.Core
(
parseBaseUrl
)
import
Toml
qualified
iniCLI
::
IniArgs
->
IO
()
iniCLI
(
IniArgs
iniPath
)
=
do
-- putStrLn $ "ini path: " <> iniPath
ini
<-
Ini
.
readConfig
iniPath
iniMail
<-
IniMail
.
readConfig
iniPath
iniNLP
<-
IniNLP
.
readConfig
iniPath
-- putStrLn (show ini :: Text)
connInfo
<-
Ini
.
readDBConfig
iniPath
let
c
=
convertConfigs
ini
iniMail
iniNLP
connInfo
-- putStrLn (show c :: Text)
putStrLn
(
show
(
Toml
.
encode
c
)
::
Text
)
iniCmd
::
HasCallStack
=>
Mod
CommandFields
CLI
iniCmd
=
command
"ini"
(
info
(
helper
<*>
fmap
CLISub
ini_p
)
(
progDesc
"Parse .ini file and output a corresponding .toml file."
))
ini_p
::
Parser
CLICmd
ini_p
=
fmap
CCMD_ini
$
IniArgs
<$>
strOption
(
long
"ini-path"
<>
help
"Path to ini file"
)
convertConfigs
::
Ini
.
GargConfig
->
IniMail
.
MailConfig
->
IniNLP
.
NLPConfig
->
PGS
.
ConnectInfo
->
Config
.
GargConfig
convertConfigs
ini
@
(
Ini
.
GargConfig
{
..
})
iniMail
nlpConfig
connInfo
=
Config
.
GargConfig
{
_gc_backend_name
,
_gc_url
,
_gc_url_backend_api
,
_gc_masteruser
,
_gc_secretkey
,
_gc_datafilepath
,
_gc_frame_write_url
,
_gc_frame_calc_url
,
_gc_frame_visio_url
,
_gc_frame_searx_url
,
_gc_frame_istex_url
,
_gc_max_docs_parsers
,
_gc_max_docs_scrapers
,
_gc_js_job_timeout
,
_gc_js_id_timeout
,
_gc_pubmed_api_key
,
_gc_epo_api_url
,
_gc_mail_config
=
iniMail
,
_gc_nlp_config
=
nlpConfig
,
_gc_frontend_config
=
mkFrontendConfig
ini
,
_gc_database_config
=
connInfo
,
_gc_notifications_config
=
defaultNotificationsConfig
}
mkFrontendConfig
::
Ini
.
GargConfig
->
CTypes
.
FrontendConfig
mkFrontendConfig
(
Ini
.
GargConfig
{
..
})
=
CTypes
.
FrontendConfig
{
_fc_url
=
_gc_url
,
_fc_backend_name
=
_gc_backend_name
,
_fc_url_backend_api
=
_gc_url_backend_api
,
_fc_jwt_settings
=
"TODO"
,
_fc_cors
,
_fc_microservices
}
where
_fc_cors
=
CTypes
.
CORSSettings
{
_corsAllowedOrigins
=
[
toCORSOrigin
"https://demo.gargantext.org"
,
toCORSOrigin
"https://formation.gargantext.org"
,
toCORSOrigin
"https://academia.sub.gargantext.org"
,
toCORSOrigin
"https://cnrs.gargantext.org"
,
toCORSOrigin
"https://imt.sub.gargantext.org"
,
toCORSOrigin
"https://helloword.gargantext.org"
,
toCORSOrigin
"https://complexsystems.gargantext.org"
,
toCORSOrigin
"https://europa.gargantext.org"
,
toCORSOrigin
"https://earth.sub.gargantext.org"
,
toCORSOrigin
"https://health.sub.gargantext.org"
,
toCORSOrigin
"https://msh.sub.gargantext.org"
,
toCORSOrigin
"https://dev.sub.gargantext.org"
,
toCORSOrigin
"http://localhost:8008"
,
toCORSOrigin
"http://localhost:8108"
,
toCORSOrigin
"http://localhost:3000"
]
,
_corsAllowedHosts
=
[]
,
_corsUseOriginsForHosts
=
True
}
_fc_microservices
=
CTypes
.
MicroServicesSettings
{
_msProxyPort
=
8009
,
_msProxyEnabled
=
False
}
toCORSOrigin
::
Text
->
CTypes
.
CORSOrigin
toCORSOrigin
url
=
case
parseBaseUrl
(
T
.
unpack
url
)
of
Nothing
->
panicTrace
$
"Cannot parse base url for: "
<>
url
Just
b
->
CTypes
.
CORSOrigin
b
defaultNotificationsConfig
::
CTypes
.
NotificationsConfig
defaultNotificationsConfig
=
CTypes
.
NotificationsConfig
{
_nc_central_exchange_bind
=
"tcp://*:5560"
,
_nc_central_exchange_connect
=
"tcp://localhost:5560"
,
_nc_dispatcher_bind
=
"tcp://*:5561"
,
_nc_dispatcher_connect
=
"tcp://localhost:5561"
}
bin/gargantext-cli/CLI/Init.hs
View file @
3b3f5109
...
...
@@ -18,7 +18,6 @@ module CLI.Init where
import
CLI.Parsers
import
CLI.Types
import
Data.List.NonEmpty
qualified
as
NE
import
Gargantext.API.Admin.Settings
import
Gargantext.API.Admin.Types
import
Gargantext.API.Dev
(
withDevEnv
,
runCmdDev
)
import
Gargantext.API.Errors.Types
...
...
bin/gargantext-cli/CLI/Invitations.hs
View file @
3b3f5109
...
...
@@ -16,7 +16,6 @@ module CLI.Invitations where
import
CLI.Parsers
import
CLI.Types
import
Gargantext.API.Admin.Settings
import
Gargantext.API.Admin.Types
import
Gargantext.API.Dev
(
withDevEnv
,
runCmdDev
)
import
Gargantext.API.Errors.Types
...
...
@@ -24,7 +23,6 @@ import Gargantext.API.Node () -- instances only
import
Gargantext.API.Node.Share
qualified
as
Share
import
Gargantext.API.Node.Share.Types
qualified
as
Share
import
Gargantext.Core.AsyncUpdates.CentralExchange.Types
qualified
as
CET
import
Gargantext.Core.Config.Utils
(
readConfig
)
import
Gargantext.Core.NLP
(
HasNLPServer
)
import
Gargantext.Core.Types
import
Gargantext.Core.Types.Individu
(
User
(
..
))
...
...
bin/gargantext-cli/CLI/Parsers.hs
View file @
3b3f5109
...
...
@@ -4,7 +4,6 @@
module
CLI.Parsers
where
import
Prelude
import
Gargantext.API.Admin.Settings
import
Gargantext.Core.Config.Types
(
SettingsFile
(
..
))
import
Options.Applicative
...
...
bin/gargantext-cli/CLI/Types.hs
View file @
3b3f5109
...
...
@@ -3,7 +3,6 @@ module CLI.Types where
import
Data.String
import
Data.Text
(
Text
)
import
Gargantext.API.Admin.Settings
import
Gargantext.Core.Config.Types
(
SettingsFile
(
..
))
import
Gargantext.Core.Types
(
NodeId
)
import
Gargantext.Core.Types.Query
...
...
@@ -46,6 +45,10 @@ data ImportArgs = ImportArgs
,
imp_corpus_path
::
!
FilePath
}
deriving
(
Show
,
Eq
)
data
IniArgs
=
IniArgs
{
ini_path
::
!
FilePath
}
deriving
(
Show
,
Eq
)
data
InitArgs
=
InitArgs
{
init_settings
::
!
SettingsFile
}
deriving
(
Show
,
Eq
)
...
...
@@ -81,6 +84,7 @@ data CLICmd
|
CCMD_obfuscate_db
!
ObfuscateDBArgs
|
CCMD_admin
!
AdminArgs
|
CCMD_import
!
ImportArgs
|
CCMD_ini
!
IniArgs
|
CCMD_init
!
InitArgs
|
CCMD_invitations
!
InvitationsArgs
|
CCMD_phylo
!
PhyloArgs
...
...
bin/gargantext-cli/CLI/Upgrade.hs
View file @
3b3f5109
...
...
@@ -19,7 +19,6 @@ module CLI.Upgrade where
import
CLI.Types
import
CLI.Parsers
import
Data.List
qualified
as
List
(
cycle
,
concat
,
take
,
unlines
)
import
Gargantext.API.Admin.Settings
import
Gargantext.API.Dev
(
withDevEnv
)
import
Gargantext.API.Node
()
-- instances only
import
Gargantext.Core.Config
(
GargConfig
(
..
))
...
...
bin/gargantext-cli/Main.hs
View file @
3b3f5109
...
...
@@ -26,6 +26,7 @@ import Options.Applicative
import
CLI.Admin
(
adminCLI
,
adminCmd
)
import
CLI.FileDiff
(
fileDiffCLI
,
fileDiffCmd
)
import
CLI.Import
(
importCLI
,
importCmd
)
import
CLI.Ini
(
iniCLI
,
iniCmd
)
import
CLI.Init
(
initCLI
,
initCmd
)
import
CLI.Invitations
(
invitationsCLI
,
invitationsCmd
)
import
CLI.Phylo
(
phyloCLI
,
phyloCmd
)
...
...
@@ -45,6 +46,8 @@ runCLI = \case
->
adminCLI
args
CLISub
(
CCMD_import
args
)
->
importCLI
args
CLISub
(
CCMD_ini
args
)
->
iniCLI
args
CLISub
(
CCMD_init
args
)
->
initCLI
args
CLISub
(
CCMD_invitations
args
)
...
...
@@ -75,6 +78,7 @@ allOptions = subparser (
obfuscateDBCmd
<>
adminCmd
<>
importCmd
<>
iniCmd
<>
initCmd
<>
invitationsCmd
<>
phyloCmd
<>
...
...
gargantext.cabal
View file @
3b3f5109
...
...
@@ -174,6 +174,9 @@ library
Gargantext.Core.AsyncUpdates.Dispatcher.WebSocket
Gargantext.Core.AsyncUpdates.Nanomsg
Gargantext.Core.Config
Gargantext.Core.Config.Ini.Ini
Gargantext.Core.Config.Ini.Mail
Gargantext.Core.Config.Ini.NLP
Gargantext.Core.Config.Mail
Gargantext.Core.Config.NLP
Gargantext.Core.Config.Types
...
...
@@ -730,6 +733,7 @@ executable gargantext-cli
CLI.FileDiff
CLI.FilterTermsAndCooc
CLI.Import
CLI.Ini
CLI.Init
CLI.Invitations
CLI.ObfuscateDB
...
...
@@ -765,15 +769,18 @@ executable gargantext-cli
, protolude ^>= 0.3.3
, servant
, servant-auth
, servant-client-core >= 0.18.3 && < 0.20
, servant-routes < 0.2
, servant-websockets >= 2.0.0 && < 2.1
, shelly
, split ^>= 0.2.3.4
, text ^>= 1.2.4.1
, time ^>= 1.9.3
, toml-parser >= 2.0.1.0 && < 3
, tree-diff
, unordered-containers ^>= 0.2.16.0
, vector ^>= 0.7.3
ghc-options: -Wall -Wincomplete-uni-patterns -Wincomplete-record-updates -Wmissing-signatures -Wunused-binds -Wunused-imports -Werror -freduction-depth=300 -fprint-potential-instances
executable gargantext-server
import:
...
...
src/Gargantext/Core/Config.hs
View file @
3b3f5109
...
...
@@ -129,50 +129,35 @@ instance FromValue GargConfig where
,
_gc_database_config
=
unTOMLConnectInfo
db_config
,
_gc_nlp_config
,
_gc_notifications_config
}
-- configCodec :: Toml.TomlCodec GargConfig
-- configCodec = GargConfig
-- <$> Toml.text "frontend.backend_name" .= _gc_backend_name
-- <*> (stripRight '/' <$> Toml.text "frontend.url") .= _gc_url
-- <*> (stripRight '/' <$> Toml.text "frontend.url_backend_api") .= _gc_url_backend_api
-- <*> Toml.text "secrets.master_user" .= _gc_masteruser
-- <*> Toml.text "secrets.secret_key" .= _gc_secretkey
-- <*> Toml.string "paths.data_filepath" .= _gc_datafilepath
-- <*> (stripRight '/' <$> Toml.text "external.frames.write_url") .= _gc_frame_write_url
-- <*> (stripRight '/' <$> Toml.text "external.frames.calc_url") .= _gc_frame_calc_url
-- <*> (stripRight '/' <$> Toml.text "external.frames.visio_url") .= _gc_frame_visio_url
-- <*> (stripRight '/' <$> Toml.text "external.frames.searx_url") .= _gc_frame_searx_url
-- <*> (stripRight '/' <$> Toml.text "external.frames.istex_url") .= _gc_frame_istex_url
-- <*> Toml.integer "jobs.max_docs_parsers" .= _gc_max_docs_parsers
-- <*> Toml.integer "jobs.max_docs_scrapers" .= _gc_max_docs_scrapers
-- <*> Toml.integer "jobs.js_job_timeout" .= _gc_js_job_timeout
-- <*> Toml.integer "jobs.js_id_timeout" .= _gc_js_id_timeout
-- <*> Toml.text "apis.pubmed.api_key" .= _gc_pubmed_api_key
-- <*> Toml.text "apis.epo.api_url" .= _gc_epo_api_url
-- pure $ GargConfig
-- { _gc_backend_name = cs $ val' "BACKEND_NAME"
-- , _gc_url = stripRight '/' $ val' "URL"
-- , _gc_url_backend_api = stripRight '/' $ val' "URL_BACKEND_API"
-- , _gc_masteruser = val' "MASTER_USER"
-- , _gc_secretkey = val' "SECRET_KEY"
-- , _gc_datafilepath = cs $ val' "DATA_FILEPATH"
-- , _gc_repofilepath = cs $ val' "REPO_FILEPATH"
-- , _gc_frame_write_url = stripRight '/' $ val' "FRAME_WRITE_URL"
-- , _gc_frame_calc_url = stripRight '/' $ val' "FRAME_CALC_URL"
-- , _gc_frame_visio_url = stripRight '/' $ val' "FRAME_VISIO_URL"
-- , _gc_frame_searx_url = stripRight '/' $ val' "FRAME_SEARX_URL"
-- , _gc_frame_istex_url = stripRight '/' $ val' "FRAME_ISTEX_URL"
-- , _gc_max_docs_parsers = read $ cs $ val' "MAX_DOCS_PARSERS"
-- , _gc_max_docs_scrapers = read $ cs $ val' "MAX_DOCS_SCRAPERS"
-- , _gc_pubmed_api_key = val' "PUBMED_API_KEY"
-- , _gc_js_job_timeout = read $ cs $ val' "JS_JOB_TIMEOUT"
-- , _gc_js_id_timeout = read $ cs $ val' "JS_ID_TIMEOUT"
-- , _gc_epo_api_url = cs $ val' "EPO_API_URL"
-- }
instance
ToValue
GargConfig
where
toValue
=
defaultTableToValue
instance
ToTable
GargConfig
where
toTable
(
GargConfig
{
..
})
=
table
[
"frontend"
.=
_gc_frontend_config
,
"secrets"
.=
secrets
,
"paths"
.=
table
[
"data_filepath"
.=
_gc_datafilepath
]
,
"apis"
.=
apis
,
"external"
.=
table
[
"frames"
.=
frames
]
,
"jobs"
.=
jobs
,
"database"
.=
TOMLConnectInfo
_gc_database_config
,
"mail"
.=
_gc_mail_config
,
"notifications"
.=
_gc_notifications_config
,
"nlp"
.=
_gc_nlp_config
]
where
secrets
=
SecretsConfig
{
_s_master_user
=
_gc_masteruser
,
_s_secret_key
=
_gc_secretkey
}
apis
=
APIsConfig
{
_ac_pubmed_api_key
=
_gc_pubmed_api_key
,
_ac_epo_api_url
=
_gc_epo_api_url
}
frames
=
FramesConfig
{
_f_write_url
=
_gc_frame_write_url
,
_f_calc_url
=
_gc_frame_calc_url
,
_f_visio_url
=
_gc_frame_visio_url
,
_f_searx_url
=
_gc_frame_searx_url
,
_f_istex_url
=
_gc_frame_istex_url
}
jobs
=
JobsConfig
{
_jc_max_docs_parsers
=
_gc_max_docs_parsers
,
_jc_max_docs_scrapers
=
_gc_max_docs_scrapers
,
_jc_js_job_timeout
=
_gc_js_job_timeout
,
_jc_js_id_timeout
=
_gc_js_id_timeout
}
mkProxyUrl
::
GargConfig
->
MicroServicesSettings
->
BaseUrl
...
...
src/Gargantext/Core/Config/Ini/Ini.hs
0 → 100644
View file @
3b3f5109
{-|
Module : Gargantext.Core.Config.Ini.Ini
Description : Textmining Collaborative Platform
Copyright : (c) CNRS, 2017-Present
License : AGPL + CECILL v3
Maintainer : team@gargantext.org
Stability : experimental
Portability : POSIX
Configuration for the gargantext server
-}
{-# LANGUAGE TemplateHaskell #-}
module
Gargantext.Core.Config.Ini.Ini
(
-- * Types
GargConfig
(
..
)
-- * Lenses
,
gc_backend_name
,
gc_datafilepath
,
gc_epo_api_url
,
gc_frame_calc_url
,
gc_frame_istex_url
,
gc_frame_searx_url
,
gc_frame_visio_url
,
gc_frame_write_url
,
gc_js_id_timeout
,
gc_js_job_timeout
,
gc_masteruser
,
gc_max_docs_parsers
,
gc_max_docs_scrapers
,
gc_pubmed_api_key
,
gc_repofilepath
,
gc_secretkey
,
gc_url
,
gc_url_backend_api
-- * Utility functions
,
readIniFile'
,
readConfig
,
val
,
readDBConfig
)
where
import
Data.Ini
(
readIniFile
,
lookupValue
,
Ini
)
import
Data.Text
as
T
import
Database.PostgreSQL.Simple
qualified
as
PGS
import
Prelude
(
read
)
import
Gargantext.Prelude
-- | strip a given character from end of string
stripRight
::
Char
->
T
.
Text
->
T
.
Text
stripRight
c
s
=
if
T
.
last
s
==
c
then
stripRight
c
(
T
.
take
(
T
.
length
s
-
1
)
s
)
else
s
data
GargConfig
=
GargConfig
{
_gc_backend_name
::
!
T
.
Text
,
_gc_url
::
!
T
.
Text
,
_gc_url_backend_api
::
!
T
.
Text
,
_gc_masteruser
::
!
T
.
Text
,
_gc_secretkey
::
!
T
.
Text
,
_gc_datafilepath
::
!
FilePath
,
_gc_repofilepath
::
!
FilePath
,
_gc_frame_write_url
::
!
T
.
Text
,
_gc_frame_calc_url
::
!
T
.
Text
,
_gc_frame_visio_url
::
!
T
.
Text
,
_gc_frame_searx_url
::
!
T
.
Text
,
_gc_frame_istex_url
::
!
T
.
Text
,
_gc_max_docs_parsers
::
!
Integer
,
_gc_max_docs_scrapers
::
!
Integer
,
_gc_pubmed_api_key
::
!
T
.
Text
,
_gc_js_job_timeout
::
!
Integer
,
_gc_js_id_timeout
::
!
Integer
,
_gc_epo_api_url
::
!
T
.
Text
}
deriving
(
Generic
,
Show
)
makeLenses
''
G
argConfig
readIniFile'
::
FilePath
->
IO
Ini
readIniFile'
fp
=
do
ini
<-
readIniFile
fp
case
ini
of
Left
e
->
panicTrace
$
T
.
pack
$
"ini file not found "
<>
show
e
Right
ini'
->
pure
ini'
val
::
Ini
->
Text
->
Text
->
Text
val
ini
section
key
=
do
case
(
lookupValue
section
key
ini
)
of
Left
e
->
panicTrace
$
"ERROR: add "
<>
key
<>
" in section
\"
"
<>
section
<>
"
\"
to your gargantext.ini. "
<>
show
e
Right
p'
->
p'
readConfig
::
FilePath
->
IO
GargConfig
readConfig
fp
=
do
ini
<-
readIniFile'
fp
let
val'
=
val
ini
"gargantext"
pure
$
GargConfig
{
_gc_backend_name
=
cs
$
val'
"BACKEND_NAME"
,
_gc_url
=
stripRight
'/'
$
val'
"URL"
,
_gc_url_backend_api
=
stripRight
'/'
$
val'
"URL_BACKEND_API"
,
_gc_masteruser
=
val'
"MASTER_USER"
,
_gc_secretkey
=
val'
"SECRET_KEY"
,
_gc_datafilepath
=
cs
$
val'
"DATA_FILEPATH"
,
_gc_repofilepath
=
cs
$
val'
"REPO_FILEPATH"
,
_gc_frame_write_url
=
stripRight
'/'
$
val'
"FRAME_WRITE_URL"
,
_gc_frame_calc_url
=
stripRight
'/'
$
val'
"FRAME_CALC_URL"
,
_gc_frame_visio_url
=
stripRight
'/'
$
val'
"FRAME_VISIO_URL"
,
_gc_frame_searx_url
=
stripRight
'/'
$
val'
"FRAME_SEARX_URL"
,
_gc_frame_istex_url
=
stripRight
'/'
$
val'
"FRAME_ISTEX_URL"
,
_gc_max_docs_parsers
=
read
$
cs
$
val'
"MAX_DOCS_PARSERS"
,
_gc_max_docs_scrapers
=
read
$
cs
$
val'
"MAX_DOCS_SCRAPERS"
,
_gc_pubmed_api_key
=
val'
"PUBMED_API_KEY"
,
_gc_js_job_timeout
=
read
$
cs
$
val'
"JS_JOB_TIMEOUT"
,
_gc_js_id_timeout
=
read
$
cs
$
val'
"JS_ID_TIMEOUT"
,
_gc_epo_api_url
=
cs
$
val'
"EPO_API_URL"
}
readDBConfig
::
FilePath
->
IO
PGS
.
ConnectInfo
readDBConfig
fp
=
do
ini
<-
readIniFile'
fp
let
val'
=
val
ini
"database"
let
dbPortRaw
=
val'
"DB_PORT"
let
dbPort
=
case
(
readMaybe
dbPortRaw
::
Maybe
Word16
)
of
Nothing
->
panicTrace
$
"DB_PORT incorrect: "
<>
dbPortRaw
Just
d
->
d
pure
$
PGS
.
ConnectInfo
{
PGS
.
connectHost
=
cs
$
val'
"DB_HOST"
,
PGS
.
connectPort
=
dbPort
,
PGS
.
connectUser
=
cs
$
val'
"DB_USER"
,
PGS
.
connectPassword
=
cs
$
val'
"DB_PASS"
,
PGS
.
connectDatabase
=
cs
$
val'
"DB_NAME"
}
src/Gargantext/Core/Config/Ini/Mail.hs
0 → 100644
View file @
3b3f5109
{-|
Module : Gargantext.Core.Config.Ini.Mail
Description :
Copyright : (c) CNRS, 2017-Present
License : AGPL + CECILL v3
Maintainer : team@gargantext.org
Stability : experimental
Portability : POSIX
-}
{-# LANGUAGE TemplateHaskell #-}
module
Gargantext.Core.Config.Ini.Mail
(
-- * Types
GargMail
(
..
)
,
LoginType
(
..
)
,
MailConfig
(
..
)
-- * Utility functions
,
gargMail
,
readConfig
-- * Lenses
,
mc_mail_from
,
mc_mail_host
,
mc_mail_login_type
,
mc_mail_password
,
mc_mail_port
,
mc_mail_user
)
where
import
Data.Maybe
import
Data.Text
(
unpack
)
import
Gargantext.Core.Config.Ini.Ini
(
readIniFile'
,
val
)
import
Gargantext.Core.Config.Mail
(
LoginType
(
..
),
MailConfig
(
..
))
import
Gargantext.Prelude
import
Network.Mail.Mime
(
plainPart
)
import
Network.Mail.SMTP
hiding
(
htmlPart
,
STARTTLS
)
import
Prelude
(
read
)
type
Email
=
Text
type
Name
=
Text
readConfig
::
FilePath
->
IO
MailConfig
readConfig
fp
=
do
ini
<-
readIniFile'
fp
let
val'
=
val
ini
"mail"
pure
$
MailConfig
{
_mc_mail_host
=
cs
$
val'
"MAIL_HOST"
,
_mc_mail_port
=
read
$
cs
$
val'
"MAIL_PORT"
,
_mc_mail_user
=
cs
$
val'
"MAIL_USER"
,
_mc_mail_from
=
cs
$
val'
"MAIL_FROM"
,
_mc_mail_password
=
cs
$
val'
"MAIL_PASSWORD"
,
_mc_mail_login_type
=
read
$
cs
$
val'
"MAIL_LOGIN_TYPE"
}
data
GargMail
=
GargMail
{
gm_to
::
Email
,
gm_name
::
Maybe
Name
,
gm_subject
::
Text
,
gm_body
::
Text
}
-- | TODO add parameters to gargantext.ini
gargMail
::
MailConfig
->
GargMail
->
IO
()
gargMail
(
MailConfig
{
..
})
(
GargMail
{
..
})
=
do
let
host
=
unpack
_mc_mail_host
user
=
unpack
_mc_mail_user
password
=
unpack
_mc_mail_password
case
_mc_mail_login_type
of
NoAuth
->
sendMail
host
mail
Normal
->
sendMailWithLogin'
host
_mc_mail_port
user
password
mail
SSL
->
sendMailWithLoginTLS'
host
_mc_mail_port
user
password
mail
TLS
->
sendMailWithLoginTLS'
host
_mc_mail_port
user
password
mail
STARTTLS
->
sendMailWithLoginSTARTTLS'
host
_mc_mail_port
user
password
mail
where
mail
=
simpleMail
sender
receiver
cc
bcc
gm_subject
[
plainPart
$
cs
gm_body
]
sender
=
Address
(
Just
"GarganText Email"
)
_mc_mail_from
receiver
=
[
Address
gm_name
gm_to
]
cc
=
[]
bcc
=
[]
makeLenses
''
M
ailConfig
src/Gargantext/Core/Config/Ini/NLP.hs
0 → 100644
View file @
3b3f5109
{-|
Module : Gargantext.Core.Config.Ini.NLP
Description :
Copyright : (c) CNRS, 2017-Present
License : AGPL + CECILL v3
Maintainer : team@gargantext.org
Stability : experimental
Portability : POSIX
-}
{-# LANGUAGE TemplateHaskell #-}
module
Gargantext.Core.Config.Ini.NLP
(
-- * Types
NLPConfig
(
..
)
-- * Utility functions
,
readConfig
-- * Lenses
,
nlp_default
,
nlp_languages
)
where
import
Data.Ini
qualified
as
Ini
import
Data.Map.Strict
qualified
as
Map
import
Data.Maybe
import
Data.Text
qualified
as
T
import
Gargantext.Core.Config.Ini.Ini
(
readIniFile'
,
val
)
import
Gargantext.Core.Config.NLP
(
NLPConfig
(
..
))
import
Gargantext.Prelude
import
Gargantext.Prelude.Utils
(
listToMaybeAll
)
import
Network.URI
(
parseURI
)
iniSection
::
Text
iniSection
=
"nlp"
readConfig
::
FilePath
->
IO
NLPConfig
readConfig
fp
=
do
ini
<-
readIniFile'
fp
let
val'
=
val
ini
iniSection
let
lang_default_text
=
"EN"
-- Change this value by one of your choice: "All", "FR", or "EN"
let
m_nlp_default
=
parseURI
$
cs
$
val'
lang_default_text
let
m_nlp_keys
=
filter
(
\
k
->
k
`
notElem
`
[
lang_default_text
])
$
fromRight
[]
$
Ini
.
keys
iniSection
ini
let
m_nlp_other
=
listToMaybeAll
$
(
\
k
->
(,)
k
<$>
(
parseURI
$
cs
$
val'
k
))
<$>
m_nlp_keys
let
mRet
=
NLPConfig
<$>
m_nlp_default
<*>
(
Map
.
fromList
<$>
m_nlp_other
)
case
mRet
of
Nothing
->
panicTrace
$
T
.
concat
[
"Cannot read config file: _nlp_default = "
,
T
.
pack
$
show
m_nlp_default
,
", _nlp_other = "
,
T
.
pack
$
show
m_nlp_other
]
Just
ret
->
pure
ret
makeLenses
''
N
LPConfig
src/Gargantext/Core/Config/Mail.hs
View file @
3b3f5109
...
...
@@ -58,6 +58,8 @@ instance FromValue LoginType where
"STARTTLS"
->
return
STARTTLS
_
->
fail
(
"Cannot parse login type from "
<>
T
.
unpack
t
)
fromValue
_
=
fail
(
"Expected text for login type"
)
instance
ToValue
LoginType
where
toValue
v
=
toValue
(
show
v
::
Text
)
data
MailConfig
=
MailConfig
{
_mc_mail_host
::
!
T
.
Text
,
_mc_mail_port
::
!
PortNumber
...
...
@@ -67,7 +69,6 @@ data MailConfig = MailConfig { _mc_mail_host :: !T.Text
,
_mc_mail_from
::
!
T
.
Text
}
deriving
(
Generic
,
Show
)
instance
FromValue
MailConfig
where
fromValue
=
parseTableFromValue
$
do
_mc_mail_host
<-
reqKey
"host"
...
...
@@ -77,6 +78,15 @@ instance FromValue MailConfig where
_mc_mail_login_type
<-
reqKey
"login_type"
_mc_mail_from
<-
reqKey
"from"
return
$
MailConfig
{
_mc_mail_port
=
fromIntegral
port
,
..
}
instance
ToValue
MailConfig
where
toValue
=
defaultTableToValue
instance
ToTable
MailConfig
where
toTable
(
MailConfig
{
..
})
=
table
[
"port"
.=
(
fromIntegral
_mc_mail_port
::
Int
)
,
"host"
.=
_mc_mail_host
,
"user"
.=
_mc_mail_user
,
"password"
.=
_mc_mail_password
,
"from"
.=
_mc_mail_from
,
"login_type"
.=
_mc_mail_login_type
]
-- readConfig :: SettingsFile -> IO MailConfig
-- readConfig (SettingsFile fp) = do
...
...
src/Gargantext/Core/Config/NLP.hs
View file @
3b3f5109
...
...
@@ -38,7 +38,8 @@ instance FromValue URI where
Nothing
->
fail
(
"Cannot parse URI "
<>
T
.
unpack
t
)
Just
uri
->
return
uri
fromValue
_
=
fail
(
"Expected text for URI"
)
instance
ToValue
URI
where
toValue
v
=
toValue
(
show
v
::
Text
)
data
NLPConfig
=
NLPConfig
{
_nlp_default
::
URI
,
_nlp_languages
::
Map
.
Map
T
.
Text
URI
}
...
...
@@ -51,6 +52,11 @@ instance FromValue NLPConfig where
MkTable
t
<-
parseTableFromValue
getTable
v
_nlp_languages
<-
mapM
fromValue
(
snd
<$>
t
)
return
$
NLPConfig
{
..
}
instance
ToValue
NLPConfig
where
toValue
=
defaultTableToValue
instance
ToTable
NLPConfig
where
toTable
(
NLPConfig
{
..
})
=
table
[
k
.=
v
|
(
k
,
v
)
<-
Map
.
toList
_nlp_languages
]
-- readConfig :: SettingsFile -> IO NLPConfig
...
...
src/Gargantext/Core/Config/Types.hs
View file @
3b3f5109
...
...
@@ -37,7 +37,7 @@ import Control.Monad.Fail (fail)
import
Data.Text
qualified
as
T
import
Database.PostgreSQL.Simple
qualified
as
PGS
import
Gargantext.Prelude
import
Servant.Client.Core
(
BaseUrl
,
parseBaseUrl
)
import
Servant.Client.Core
(
BaseUrl
,
parseBaseUrl
,
showBaseUrl
)
import
Toml
import
Toml.Schema
...
...
@@ -57,7 +57,8 @@ instance FromValue CORSOrigin where
Nothing
->
fail
$
"Cannot parse base url for: "
<>
T
.
unpack
t
Just
b
->
return
$
CORSOrigin
b
fromValue
_
=
fail
"Incorrect key type, expected Text"
instance
ToValue
CORSOrigin
where
toValue
(
CORSOrigin
o
)
=
toValue
(
showBaseUrl
o
)
data
CORSSettings
=
CORSSettings
{
...
...
@@ -75,6 +76,11 @@ instance FromValue CORSSettings where
let
_corsAllowedHosts
=
mempty
_corsUseOriginsForHosts
<-
reqKey
"use-origins-for-hosts"
return
$
CORSSettings
{
..
}
instance
ToValue
CORSSettings
where
toValue
=
defaultTableToValue
instance
ToTable
CORSSettings
where
toTable
(
CORSSettings
{
..
})
=
table
[
"allowed-origins"
.=
_corsAllowedOrigins
,
"use-origins-for-hosts"
.=
_corsUseOriginsForHosts
]
makeLenses
''
C
ORSSettings
...
...
@@ -85,12 +91,19 @@ data MicroServicesSettings =
_msProxyPort
::
!
Int
,
_msProxyEnabled
::
!
Bool
}
deriving
(
Show
,
Eq
)
instance
FromValue
MicroServicesSettings
where
fromValue
=
parseTableFromValue
$
reqKeyOf
"proxy"
$
parseTableFromValue
$
do
_msProxyPort
<-
reqKey
"port"
_msProxyEnabled
<-
reqKey
"enabled"
return
$
MicroServicesSettings
{
..
}
instance
ToValue
MicroServicesSettings
where
toValue
=
defaultTableToValue
instance
ToTable
MicroServicesSettings
where
toTable
(
MicroServicesSettings
{
..
})
=
table
[
"proxy"
.=
table
[
"port"
.=
_msProxyPort
,
"enabled"
.=
_msProxyEnabled
]
]
makeLenses
''
M
icroServicesSettings
...
...
@@ -110,6 +123,15 @@ instance FromValue TOMLConnectInfo where
,
PGS
.
connectUser
=
user
,
PGS
.
connectPassword
=
password
,
PGS
.
connectDatabase
=
db
}
instance
ToValue
TOMLConnectInfo
where
toValue
=
defaultTableToValue
instance
ToTable
TOMLConnectInfo
where
toTable
(
TOMLConnectInfo
(
PGS
.
ConnectInfo
{
..
}))
=
table
[
"host"
.=
connectHost
,
"port"
.=
connectPort
,
"user"
.=
connectUser
,
"pass"
.=
connectPassword
,
"name"
.=
connectDatabase
]
data
FramesConfig
=
...
...
@@ -120,7 +142,6 @@ data FramesConfig =
,
_f_istex_url
::
Text
}
deriving
(
Generic
,
Show
)
instance
FromValue
FramesConfig
where
fromValue
=
parseTableFromValue
$
do
_f_write_url
<-
reqKey
"write_url"
...
...
@@ -129,6 +150,14 @@ instance FromValue FramesConfig where
_f_searx_url
<-
reqKey
"searx_url"
_f_istex_url
<-
reqKey
"istex_url"
return
$
FramesConfig
{
..
}
instance
ToValue
FramesConfig
where
toValue
=
defaultTableToValue
instance
ToTable
FramesConfig
where
toTable
(
FramesConfig
{
..
})
=
table
[
"write_url"
.=
_f_write_url
,
"calc_url"
.=
_f_calc_url
,
"visio_url"
.=
_f_visio_url
,
"searx_url"
.=
_f_searx_url
,
"istex_url"
.=
_f_istex_url
]
data
FrontendConfig
=
...
...
@@ -140,7 +169,6 @@ data FrontendConfig =
,
_fc_microservices
::
!
MicroServicesSettings
}
deriving
(
Generic
,
Show
)
instance
FromValue
FrontendConfig
where
fromValue
=
parseTableFromValue
$
do
_fc_url
<-
reqKey
"url"
...
...
@@ -150,6 +178,15 @@ instance FromValue FrontendConfig where
_fc_cors
<-
reqKey
"cors"
_fc_microservices
<-
reqKey
"microservices"
return
$
FrontendConfig
{
..
}
instance
ToValue
FrontendConfig
where
toValue
=
defaultTableToValue
instance
ToTable
FrontendConfig
where
toTable
(
FrontendConfig
{
..
})
=
table
[
"url"
.=
_fc_url
,
"backend_name"
.=
_fc_backend_name
,
"url_backend_api"
.=
_fc_url_backend_api
,
"jwt_settings"
.=
_fc_jwt_settings
,
"cors"
.=
_fc_cors
,
"microservices"
.=
_fc_microservices
]
data
SecretsConfig
=
...
...
@@ -157,12 +194,16 @@ data SecretsConfig =
,
_s_secret_key
::
!
Text
}
deriving
(
Generic
,
Show
)
instance
FromValue
SecretsConfig
where
fromValue
=
parseTableFromValue
$
do
_s_master_user
<-
reqKey
"master_user"
_s_secret_key
<-
reqKey
"secret_key"
return
$
SecretsConfig
{
..
}
instance
ToValue
SecretsConfig
where
toValue
=
defaultTableToValue
instance
ToTable
SecretsConfig
where
toTable
(
SecretsConfig
{
..
})
=
table
[
"master_user"
.=
_s_master_user
,
"secret_key"
.=
_s_secret_key
]
data
JobsConfig
=
...
...
@@ -177,6 +218,13 @@ instance FromValue JobsConfig where
_jc_js_job_timeout
<-
reqKey
"js_job_timeout"
_jc_js_id_timeout
<-
reqKey
"js_id_timeout"
return
$
JobsConfig
{
..
}
instance
ToValue
JobsConfig
where
toValue
=
defaultTableToValue
instance
ToTable
JobsConfig
where
toTable
(
JobsConfig
{
..
})
=
table
[
"max_docs_parsers"
.=
_jc_max_docs_parsers
,
"max_docs_scrapers"
.=
_jc_max_docs_scrapers
,
"js_job_timeout"
.=
_jc_js_job_timeout
,
"js_id_timeout"
.=
_jc_js_id_timeout
]
data
APIsConfig
=
...
...
@@ -187,7 +235,12 @@ instance FromValue APIsConfig where
_ac_pubmed_api_key
<-
reqKeyOf
"pubmed"
$
parseTableFromValue
$
reqKey
"api_key"
_ac_epo_api_url
<-
reqKeyOf
"epo"
$
parseTableFromValue
$
reqKey
"api_url"
return
$
APIsConfig
{
..
}
instance
ToValue
APIsConfig
where
toValue
=
defaultTableToValue
instance
ToTable
APIsConfig
where
toTable
(
APIsConfig
{
..
})
=
table
[
"pubmed"
.=
table
[
"api_key"
.=
_ac_pubmed_api_key
]
,
"epo"
.=
table
[
"api_url"
.=
_ac_epo_api_url
]
]
data
NotificationsConfig
=
...
...
@@ -209,3 +262,14 @@ instance FromValue NotificationsConfig where
c
<-
reqKey
"connect"
pure
(
b
,
c
)
return
$
NotificationsConfig
{
..
}
instance
ToValue
NotificationsConfig
where
toValue
=
defaultTableToValue
instance
ToTable
NotificationsConfig
where
toTable
(
NotificationsConfig
{
..
})
=
table
[
"central-exchange"
.=
table
[
"bind"
.=
_nc_central_exchange_bind
,
"connect"
.=
_nc_central_exchange_connect
]
,
"dispatcher"
.=
table
[
"bind"
.=
_nc_dispatcher_bind
,
"connect"
.=
_nc_dispatcher_connect
]
]
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