Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hikaru
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
hikaru
Commits
731efa00
Verified
Commit
731efa00
authored
4 years ago
by
jan.hamal.dvorak
Browse files
Options
Downloads
Patches
Plain Diff
Extend configuration file format
Signed-off-by:
Jan Hamal Dvořák
<
mordae@anilinux.org
>
parent
cbb13e47
No related branches found
No related tags found
Loading
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/Hikaru/Config.hs
+18
-6
18 additions, 6 deletions
lib/Hikaru/Config.hs
with
18 additions
and
6 deletions
lib/Hikaru/Config.hs
+
18
−
6
View file @
731efa00
...
@@ -30,14 +30,14 @@ module Hikaru.Config
...
@@ -30,14 +30,14 @@ module Hikaru.Config
,
generateSecret
,
generateSecret
)
)
where
where
import
Relude
hiding
(
lines
)
import
Relude
hiding
(
drop
,
lines
,
isPrefixOf
,
length
)
import
qualified
Data.Map
as
Map
import
qualified
Data.Map
as
Map
import
Crypto.Random.Entropy
import
Crypto.Random.Entropy
import
Data.ByteArray.Encoding
import
Data.ByteArray.Encoding
import
Data.List
(
lines
,
span
)
import
Data.String.Conversions
import
Data.String.Conversions
import
Data.Text
hiding
(
map
)
import
System.Environment
import
System.Environment
...
@@ -68,11 +68,24 @@ where
...
@@ -68,11 +68,24 @@ where
-- let cfg = env <> def
-- let cfg = env <> def
-- @
-- @
--
--
-- Configuration file format is approximately this:
--
-- @
-- # How many seconds before forms need to be reloaded?
-- CSRF_VALIDITY = 3600
--
-- # Secret key to protect against CSRF. Don't tell anyone!
-- CSRF_SECRET = Ain9eec8aighoiri
-- @
--
configFromFile
::
(
MonadIO
m
)
=>
FilePath
->
m
Config
configFromFile
::
(
MonadIO
m
)
=>
FilePath
->
m
Config
configFromFile
path
=
Map
.
fromList
<$>
map
parse
<$>
lines
<$>
readFile
path
configFromFile
path
=
Map
.
fromList
<$>
parse
File
<$>
readFile
Text
path
where
where
parse
=
conv
.
span
(
/=
'='
)
parseFile
=
mapMaybe
parseLine
.
lines
conv
(
k
,
v
)
=
(
cs
k
,
cs
$
drop
1
v
)
parseLine
=
fmap
tidy
.
fmap
parseKV
.
reject
.
strip
parseKV
=
fmap
(
drop
1
)
.
span
(
/=
'='
)
reject
=
guarded
(
not
.
isPrefixOf
"#"
)
<=<
guarded
(
""
/=
)
tidy
(
k
,
v
)
=
(
strip
k
,
strip
v
)
-- |
-- |
...
@@ -84,7 +97,6 @@ where
...
@@ -84,7 +97,6 @@ where
configDefault
::
(
MonadIO
m
)
=>
m
Config
configDefault
::
(
MonadIO
m
)
=>
m
Config
configDefault
=
do
configDefault
=
do
secret
<-
generateSecret
16
secret
<-
generateSecret
16
return
$
Map
.
fromList
[
(
"CSRF_SECRET"
,
secret
)
return
$
Map
.
fromList
[
(
"CSRF_SECRET"
,
secret
)
,
(
"CSRF_VALIDITY"
,
"86400"
)
,
(
"CSRF_VALIDITY"
,
"86400"
)
]
]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment