Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
Przemyslaw Kaminski
haskell-gargantext
Commits
bbefa443
Commit
bbefa443
authored
Sep 19, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[CONFIG] repo file path in gargantext.ini now
parent
51369b70
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
37 deletions
+49
-37
gargantext.ini_toModify
gargantext.ini_toModify
+8
-0
Settings.hs
src/Gargantext/API/Admin/Settings.hs
+34
-34
Config.hs
src/Gargantext/Prelude/Config.hs
+7
-3
No files found.
gargantext.ini_toModify
View file @
bbefa443
...
@@ -9,6 +9,14 @@ SECRET_KEY = PASSWORD_TO_CHANGE
...
@@ -9,6 +9,14 @@ SECRET_KEY = PASSWORD_TO_CHANGE
# Data path to local files
# Data path to local files
DATA_FILEPATH = FILEPATH_TO_CHANGE
DATA_FILEPATH = FILEPATH_TO_CHANGE
# Data path to local files
DATA_FILEPATH = FILEPATH_TO_CHANGE
# Data path to local files
REPOS_DIRPATH = FILEPATH_TO_CHANGE
# [external]
# [external]
# FRAMES (i.e. iframe sources used in various places on the frontend)
# FRAMES (i.e. iframe sources used in various places on the frontend)
FRAME_WRITE_URL = URL_TO_CHANGE
FRAME_WRITE_URL = URL_TO_CHANGE
...
...
src/Gargantext/API/Admin/Settings.hs
View file @
bbefa443
...
@@ -51,7 +51,7 @@ import System.IO.Temp (withTempFile)
...
@@ -51,7 +51,7 @@ import System.IO.Temp (withTempFile)
import
System.Log.FastLogger
import
System.Log.FastLogger
import
qualified
Data.ByteString.Lazy
as
L
import
qualified
Data.ByteString.Lazy
as
L
import
qualified
Servant.Job.Core
import
qualified
Servant.Job.Core
import
Gargantext.Prelude.Config
(
GargConfig
(
)
,
readConfig
,
defaultConfig
)
import
Gargantext.Prelude.Config
(
GargConfig
(
..
),
gc_repofilepath
,
readConfig
,
defaultConfig
)
type
PortNumber
=
Int
type
PortNumber
=
Int
...
@@ -171,30 +171,29 @@ data MockEnv = MockEnv
...
@@ -171,30 +171,29 @@ data MockEnv = MockEnv
makeLenses
''
M
ockEnv
makeLenses
''
M
ockEnv
-- | TODO add this path in Settings
-----------------------------------------------------------------------
-- | RepoDir FilePath configuration
type
RepoDirFilePath
=
FilePath
repoDir
::
FilePath
repoSnapshot
::
RepoDirFilePath
->
FilePath
repoDir
=
"repos"
repoSnapshot
repoDir
=
repoDir
<>
"/repo.cbor"
repoSnapshot
::
FilePath
repoSnapshot
=
repoDir
<>
"/repo.cbor"
-- | TODO add hard coded file in Settings
-- | TODO add hard coded file in Settings
-- This assumes we own the lock on repoSnapshot.
-- This assumes we own the lock on repoSnapshot.
repoSaverAction
::
Serialise
a
=>
a
->
IO
()
repoSaverAction
::
RepoDirFilePath
->
Serialise
a
=>
a
->
IO
()
repoSaverAction
a
=
do
repoSaverAction
repoDir
a
=
do
withTempFile
"repos"
"tmp-repo.cbor"
$
\
fp
h
->
do
withTempFile
"repos"
"tmp-repo.cbor"
$
\
fp
h
->
do
printDebug
"repoSaverAction"
fp
printDebug
"repoSaverAction"
fp
L
.
hPut
h
$
serialise
a
L
.
hPut
h
$
serialise
a
hClose
h
hClose
h
renameFile
fp
repoSnapshot
renameFile
fp
(
repoSnapshot
repoDir
)
mkRepoSaver
::
MVar
NgramsRepo
->
IO
(
IO
()
)
mkRepoSaver
::
RepoDirFilePath
->
MVar
NgramsRepo
->
IO
(
IO
()
)
mkRepoSaver
repo_var
=
mkDebounce
settings
mkRepoSaver
repo
Dir
repo
_var
=
mkDebounce
settings
where
where
settings
=
defaultDebounceSettings
settings
=
defaultDebounceSettings
{
debounceFreq
=
let
n
=
6
::
Int
in
10
^
n
-- 1 second
{
debounceFreq
=
let
n
=
6
::
Int
in
10
^
n
-- 1 second
,
debounceAction
=
withMVar
repo_var
repoSaverAction
,
debounceAction
=
withMVar
repo_var
(
repoSaverAction
repoDir
)
-- Here this not only `readMVar` but `takeMVar`.
-- Here this not only `readMVar` but `takeMVar`.
-- Namely while repoSaverAction is saving no other change
-- Namely while repoSaverAction is saving no other change
-- can be made to the MVar.
-- can be made to the MVar.
...
@@ -205,34 +204,34 @@ mkRepoSaver repo_var = mkDebounce settings
...
@@ -205,34 +204,34 @@ mkRepoSaver repo_var = mkDebounce settings
-- Add a new MVar just for saving.
-- Add a new MVar just for saving.
}
}
readRepoEnv
::
IO
RepoEnv
readRepoEnv
::
FilePath
->
IO
RepoEnv
readRepoEnv
=
do
readRepoEnv
repoDir
=
do
-- Does file exist ? :: Bool
-- Does file exist ? :: Bool
_repoDir
<-
createDirectoryIfMissing
True
repoDir
_repoDir
<-
createDirectoryIfMissing
True
repoDir
repoFile
<-
doesFileExist
repoSnapshot
repoFile
<-
doesFileExist
(
repoSnapshot
repoDir
)
-- Is file not empty ? :: Bool
-- Is file not empty ? :: Bool
repoExists
<-
if
repoFile
repoExists
<-
if
repoFile
then
(
>
0
)
<$>
getFileSize
repoSnapshot
then
(
>
0
)
<$>
getFileSize
(
repoSnapshot
repoDir
)
else
pure
False
else
pure
False
mlock
<-
tryLockFile
repoSnapshot
Exclusive
mlock
<-
tryLockFile
(
repoSnapshot
repoDir
)
Exclusive
lock
<-
maybe
(
panic
"Repo file already locked"
)
pure
mlock
lock
<-
maybe
(
panic
"Repo file already locked"
)
pure
mlock
mvar
<-
newMVar
=<<
mvar
<-
newMVar
=<<
if
repoExists
if
repoExists
then
do
then
do
-- e_repo <- eitherDecodeStrict <$> deserialise <$> L.readFile repoSnapshot
-- e_repo <- eitherDecodeStrict <$> deserialise <$> L.readFile repoSnapshot
repo
<-
deserialise
<$>
L
.
readFile
repoSnapshot
repo
<-
deserialise
<$>
L
.
readFile
(
repoSnapshot
repoDir
)
-- repo <- either fail pure e_repo
-- repo <- either fail pure e_repo
let
archive
=
repoSnapshot
<>
".v"
<>
show
(
repo
^.
r_version
)
let
archive
=
(
repoSnapshot
repoDir
)
<>
".v"
<>
show
(
repo
^.
r_version
)
copyFile
repoSnapshot
archive
copyFile
(
repoSnapshot
repoDir
)
archive
pure
repo
pure
repo
else
else
pure
initRepo
pure
initRepo
-- TODO save in DB here
-- TODO save in DB here
saver
<-
mkRepoSaver
mvar
saver
<-
mkRepoSaver
repoDir
mvar
pure
$
RepoEnv
{
_renv_var
=
mvar
,
_renv_saver
=
saver
,
_renv_lock
=
lock
}
pure
$
RepoEnv
{
_renv_var
=
mvar
,
_renv_saver
=
saver
,
_renv_lock
=
lock
}
devJwkFile
::
FilePath
devJwkFile
::
FilePath
...
@@ -245,13 +244,13 @@ newEnv port file = do
...
@@ -245,13 +244,13 @@ newEnv port file = do
when
(
port
/=
settings
^.
appPort
)
$
when
(
port
/=
settings
^.
appPort
)
$
panic
"TODO: conflicting settings of port"
panic
"TODO: conflicting settings of port"
config
<-
readConfig
file
self_url
<-
parseBaseUrl
$
"http://0.0.0.0:"
<>
show
port
self_url
<-
parseBaseUrl
$
"http://0.0.0.0:"
<>
show
port
param
<-
databaseParameters
file
dbParam
<-
databaseParameters
file
pool
<-
newPool
p
aram
pool
<-
newPool
dbP
aram
repo
<-
readRepoEnv
repo
<-
readRepoEnv
(
_gc_repofilepath
config
)
scrapers_env
<-
newJobEnv
defaultSettings
manager
scrapers_env
<-
newJobEnv
defaultSettings
manager
logger
<-
newStderrLoggerSet
defaultBufSize
logger
<-
newStderrLoggerSet
defaultBufSize
config
<-
readConfig
file
pure
$
Env
pure
$
Env
{
_env_settings
=
settings
{
_env_settings
=
settings
...
@@ -294,24 +293,25 @@ instance HasRepo DevEnv where
...
@@ -294,24 +293,25 @@ instance HasRepo DevEnv where
instance
HasSettings
DevEnv
where
instance
HasSettings
DevEnv
where
settings
=
dev_env_settings
settings
=
dev_env_settings
cleanEnv
::
HasRepo
env
=>
env
->
IO
()
cleanEnv
::
(
HasConfig
env
,
HasRepo
env
)
=>
env
->
IO
()
cleanEnv
env
=
do
cleanEnv
env
=
do
r
<-
takeMVar
(
env
^.
repoEnv
.
renv_var
)
r
<-
takeMVar
(
env
^.
repoEnv
.
renv_var
)
repoSaverAction
r
repoSaverAction
(
env
^.
hasConfig
.
gc_repofilepath
)
r
unlockFile
(
env
^.
repoEnv
.
renv_lock
)
unlockFile
(
env
^.
repoEnv
.
renv_lock
)
withDevEnv
::
FilePath
->
(
DevEnv
->
IO
a
)
->
IO
a
type
IniPath
=
FilePath
withDevEnv
::
IniPath
->
(
DevEnv
->
IO
a
)
->
IO
a
withDevEnv
iniPath
k
=
do
withDevEnv
iniPath
k
=
do
env
<-
newDevEnv
env
<-
newDevEnv
k
env
`
finally
`
cleanEnv
env
k
env
`
finally
`
cleanEnv
env
where
where
newDevEnv
=
do
newDevEnv
=
do
param
<-
databaseParameters
iniPath
config
<-
readConfig
iniPath
pool
<-
newPool
param
dbParam
<-
databaseParameters
iniPath
repo
<-
readRepoEnv
pool
<-
newPool
dbParam
setts
<-
devSettings
devJwkFile
repo
<-
readRepoEnv
(
_gc_repofilepath
config
)
config
<-
readConfig
iniPath
setts
<-
devSettings
devJwkFile
pure
$
DevEnv
pure
$
DevEnv
{
_dev_env_pool
=
pool
{
_dev_env_pool
=
pool
,
_dev_env_repo
=
repo
,
_dev_env_repo
=
repo
...
...
src/Gargantext/Prelude/Config.hs
View file @
bbefa443
...
@@ -23,9 +23,11 @@ import GHC.Generics (Generic)
...
@@ -23,9 +23,11 @@ import GHC.Generics (Generic)
import
Control.Lens
(
makeLenses
)
import
Control.Lens
(
makeLenses
)
data
GargConfig
=
GargConfig
{
_gc_masteruser
::
!
Text
data
GargConfig
=
GargConfig
{
_gc_masteruser
::
!
Text
,
_gc_secretkey
::
!
Text
,
_gc_secretkey
::
!
Text
,
_gc_datafilepath
::
!
FilePath
,
_gc_datafilepath
::
!
FilePath
,
_gc_repofilepath
::
!
FilePath
,
_gc_frame_write_url
::
!
Text
,
_gc_frame_write_url
::
!
Text
,
_gc_frame_calc_url
::
!
Text
,
_gc_frame_calc_url
::
!
Text
...
@@ -53,6 +55,7 @@ readConfig fp = do
...
@@ -53,6 +55,7 @@ readConfig fp = do
pure
$
GargConfig
(
val
"MASTER_USER"
)
pure
$
GargConfig
(
val
"MASTER_USER"
)
(
val
"SECRET_KEY"
)
(
val
"SECRET_KEY"
)
(
cs
$
val
"DATA_FILEPATH"
)
(
cs
$
val
"DATA_FILEPATH"
)
(
cs
$
val
"REPO_FILEPATH"
)
(
val
"FRAME_WRITE_URL"
)
(
val
"FRAME_WRITE_URL"
)
(
val
"FRAME_CALC_URL"
)
(
val
"FRAME_CALC_URL"
)
(
val
"FRAME_SEARX_URL"
)
(
val
"FRAME_SEARX_URL"
)
...
@@ -63,6 +66,7 @@ defaultConfig :: GargConfig
...
@@ -63,6 +66,7 @@ defaultConfig :: GargConfig
defaultConfig
=
GargConfig
"gargantua"
defaultConfig
=
GargConfig
"gargantua"
"secret"
"secret"
"data"
"data"
"repos/"
"https://frame_write.url"
"https://frame_write.url"
"https://frame_calc.url"
"https://frame_calc.url"
"https://frame_searx.url"
"https://frame_searx.url"
...
...
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