Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
walint
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
Container 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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
hub
walint
Commits
cc52022f
Commit
cc52022f
authored
3 years ago
by
stuebinm
Browse files
Options
Downloads
Patches
Plain Diff
server: post map updates to exneuland's API
parent
8272b6f1
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
config.toml
+1
-0
1 addition, 0 deletions
config.toml
package.yaml
+3
-1
3 additions, 1 deletion
package.yaml
server/Main.hs
+44
-11
44 additions, 11 deletions
server/Main.hs
server/Server.hs
+21
-8
21 additions, 8 deletions
server/Server.hs
walint.cabal
+2
-0
2 additions, 0 deletions
walint.cabal
with
71 additions
and
20 deletions
config.toml
+
1
−
0
View file @
cc52022f
...
@@ -7,6 +7,7 @@ tmpdir = "/tmp"
...
@@ -7,6 +7,7 @@ tmpdir = "/tmp"
# linting interval in seconds
# linting interval in seconds
interval
=
30
interval
=
30
exneuland
=
"http://localhost:4000"
[[org]]
[[org]]
slug
=
"divoc"
slug
=
"divoc"
...
...
This diff is collapsed.
Click to expand it.
package.yaml
+
3
−
1
View file @
cc52022f
...
@@ -66,11 +66,13 @@ executables:
...
@@ -66,11 +66,13 @@ executables:
-
warp
-
warp
-
wai
-
wai
-
wai-extra
-
wai-extra
-
lucid
-
servant
-
servant
-
servant-server
-
servant-server
-
lucid
-
servant-client
-
servant-lucid
-
servant-lucid
-
http-types
-
http-types
-
http-client
-
process
-
process
-
extra
-
extra
-
microlens-platform
-
microlens-platform
...
...
This diff is collapsed.
Click to expand it.
server/Main.hs
+
44
−
11
View file @
cc52022f
...
@@ -10,7 +10,14 @@
...
@@ -10,7 +10,14 @@
-- | simple server offering linting "as a service"
-- | simple server offering linting "as a service"
module
Main
where
module
Main
where
import
Universum
import
Universum
(
Container
(
length
),
IO
,
MVar
,
Monad
((
>>=
)),
Num
((
*
)),
Proxy
(
Proxy
),
Text
,
atomically
,
forM_
,
forever
,
map
,
newMVar
,
print
,
putTextLn
,
readMVar
,
view
,
void
,
(
$
),
(
.
))
import
Control.Concurrent
(
threadDelay
)
import
Control.Concurrent
(
threadDelay
)
import
Control.Concurrent.Async
(
async
,
link
,
waitEither_
)
import
Control.Concurrent.Async
(
async
,
link
,
waitEither_
)
...
@@ -22,6 +29,8 @@ import Handlers (AdminOverview (AdminOverv
...
@@ -22,6 +29,8 @@ import Handlers (AdminOverview (AdminOverv
MapService
(
MapService
),
MapService
(
MapService
),
stateImpl
,
statusImpl
)
stateImpl
,
statusImpl
)
import
HtmlOrphans
()
import
HtmlOrphans
()
import
Network.HTTP.Client
(
defaultManagerSettings
,
newManager
)
import
Network.Wai.Handler.Warp
(
defaultSettings
,
import
Network.Wai.Handler.Warp
(
defaultSettings
,
runSettings
,
setPort
)
runSettings
,
setPort
)
import
Network.Wai.Middleware.Gzip
(
def
)
import
Network.Wai.Middleware.Gzip
(
def
)
...
@@ -29,32 +38,42 @@ import Network.Wai.Middleware.RequestLogger (OutputFormat (..),
...
@@ -29,32 +38,42 @@ import Network.Wai.Middleware.RequestLogger (OutputFormat (..),
RequestLoggerSettings
(
..
),
RequestLoggerSettings
(
..
),
mkRequestLogger
)
mkRequestLogger
)
import
Servant
(
Application
,
Capture
,
import
Servant
(
Application
,
Capture
,
Get
,
JSON
,
Raw
,
Server
,
EmptyAPI
,
Get
,
JSON
,
serve
,
type
(
:<|>
)
(
..
),
PlainText
,
Post
,
Raw
,
ReqBody
,
Server
,
serve
,
type
(
:<|>
)
(
..
),
type
(
:>
))
type
(
:>
))
import
Servant.HTML.Lucid
(
HTML
)
import
Servant.HTML.Lucid
(
HTML
)
import
Servant.Server.StaticFiles
(
serveDirectoryWebApp
)
import
Servant.Server.StaticFiles
(
serveDirectoryWebApp
)
import
Server
(
JobStatus
,
Org
(
..
),
import
Server
(
JobStatus
,
Org
(
..
),
ServerState
,
Sha1
,
ServerState
,
Sha1
,
emptyState
,
interval
,
emptyState
,
exneuland
,
loadConfig
,
orgs
,
port
,
interval
,
loadConfig
,
unState
,
verbose
)
orgs
,
port
,
unState
,
verbose
)
import
Worker
(
Job
(
Job
),
linterThread
)
import
Worker
(
Job
(
Job
),
linterThread
)
import
Servant.Client
(
BaseUrl
(
BaseUrl
),
ClientM
,
Scheme
(
Http
),
client
,
mkClientEnv
,
runClientM
)
-- | that thing we need to replace the hub
type
family
PolyEndpoint
method
format
payload
where
type
MapServiceAPI
=
"api"
:>
"maps"
:>
"list"
:>
Get
'
[
JSON
]
MapService
PolyEndpoint
Get
format
payload
=
Get
format
payload
PolyEndpoint
Post
format
payload
=
ReqBody
format
payload
:>
Post
'
[
PlainText
]
Text
type
MapServiceAPI
method
=
"api"
:>
"maps"
:>
"list"
:>
PolyEndpoint
method
'
[
JSON
]
MapService
-- | abstract api
-- | abstract api
type
API
format
=
type
API
format
=
-- "submit" :> ReqBody '[JSON] RemoteRef :> Post '[format] UUID
"status"
:>
Capture
"org"
Text
:>
Capture
"jobid"
Sha1
:>
Get
'
[
format
]
JobStatus
"status"
:>
Capture
"org"
Text
:>
Capture
"jobid"
Sha1
:>
Get
'
[
format
]
JobStatus
-- :<|> "relint" :> Capture "jobid" UUID :> Get '[format] NoContent
:<|>
"admin"
:>
"overview"
:>
Get
'
[
format
]
AdminOverview
:<|>
"admin"
:>
"overview"
:>
Get
'
[
format
]
AdminOverview
-- | actual set of routes: api for json & html + static pages from disk
-- | actual set of routes: api for json & html + static pages from disk
type
Routes
=
"api"
:>
API
JSON
type
Routes
=
"api"
:>
API
JSON
:<|>
MapServiceAPI
:<|>
MapServiceAPI
Get
:<|>
API
HTML
-- websites mirror the API exactly
:<|>
API
HTML
-- websites mirror the API exactly
:<|>
Raw
:<|>
Raw
...
@@ -73,6 +92,9 @@ server state = jsonAPI @JSON state
...
@@ -73,6 +92,9 @@ server state = jsonAPI @JSON state
app
::
MVar
ServerState
->
Application
app
::
MVar
ServerState
->
Application
app
=
serve
(
Proxy
@
Routes
)
.
server
app
=
serve
(
Proxy
@
Routes
)
.
server
postNewMaps
::
MapService
->
ClientM
Text
postNewMaps
=
client
(
Proxy
@
(
MapServiceAPI
Post
))
main
::
IO
()
main
::
IO
()
main
=
do
main
=
do
config
<-
loadConfig
"./config.toml"
config
<-
loadConfig
"./config.toml"
...
@@ -96,10 +118,21 @@ main = do
...
@@ -96,10 +118,21 @@ main = do
-- microseconds for some reason
-- microseconds for some reason
threadDelay
(
view
interval
config
*
1000000
)
threadDelay
(
view
interval
config
*
1000000
)
-- TODO: what about tls / https?
manager'
<-
newManager
defaultManagerSettings
updater
<-
async
$
forever
$
do
done
<-
readMVar
state
res
<-
runClientM
(
postNewMaps
(
MapService
done
))
(
mkClientEnv
manager'
(
view
exneuland
config
))
print
res
threadDelay
(
view
interval
config
*
1000000
)
-- spawns threads for each job in the queue
-- spawns threads for each job in the queue
linter
<-
async
$
void
$
linterThread
config
queue
state
linter
<-
async
$
void
$
linterThread
config
queue
state
link
linter
link
linter
link
poker
link
poker
link
updater
let
warpsettings
=
let
warpsettings
=
setPort
(
view
port
config
)
setPort
(
view
port
config
)
...
...
This diff is collapsed.
Click to expand it.
server/Server.hs
+
21
−
8
View file @
cc52022f
...
@@ -19,7 +19,7 @@
...
@@ -19,7 +19,7 @@
module
Server
(
loadConfig
module
Server
(
loadConfig
,
Org
(
..
)
,
Org
(
..
)
,
Sha1
,
Sha1
,
Config
,
tmpdir
,
port
,
verbose
,
orgs
,
interval
,
Config
,
tmpdir
,
port
,
verbose
,
orgs
,
interval
,
exneuland
,
RemoteRef
(
..
)
,
RemoteRef
(
..
)
,
ServerState
,
emptyState
,
unState
,
ServerState
,
emptyState
,
unState
,
JobStatus
(
..
)
,
JobStatus
(
..
)
...
@@ -29,6 +29,7 @@ module Server ( loadConfig
...
@@ -29,6 +29,7 @@ module Server ( loadConfig
import
Universum
import
Universum
import
CheckDir
(
DirResult
)
import
CheckDir
(
DirResult
)
import
Control.Arrow
((
>>>
))
import
Control.Concurrent
(
modifyMVar_
,
withMVar
)
import
Control.Concurrent
(
modifyMVar_
,
withMVar
)
import
Crypto.Hash.SHA1
(
hash
)
import
Crypto.Hash.SHA1
(
hash
)
import
Data.Aeson
(
FromJSON
,
ToJSON
,
ToJSONKey
(
..
),
import
Data.Aeson
(
FromJSON
,
ToJSON
,
ToJSONKey
(
..
),
...
@@ -40,9 +41,14 @@ import qualified Data.Map as M
...
@@ -40,9 +41,14 @@ import qualified Data.Map as M
import
Lens.Micro.Platform
(
at
,
ix
,
makeLenses
,
traverseOf
)
import
Lens.Micro.Platform
(
at
,
ix
,
makeLenses
,
traverseOf
)
import
LintConfig
(
LintConfig
'
)
import
LintConfig
(
LintConfig
'
)
import
Servant
(
FromHttpApiData
)
import
Servant
(
FromHttpApiData
)
import
Toml
(
TomlCodec
,
prettyTomlDecodeErrors
,
import
Servant.Client
(
BaseUrl
,
(
.=
))
parseBaseUrl
)
import
Toml
(
BiMap
(
BiMap
),
TomlBiMap
,
TomlBiMapError
(
ArbitraryError
),
TomlCodec
,
prettyTomlDecodeErrors
,
(
.=
))
import
qualified
Toml
as
T
import
qualified
Toml
as
T
import
Data.Either.Extra
(
mapLeft
)
-- | a reference in a remote git repository
-- | a reference in a remote git repository
data
RemoteRef
=
RemoteRef
data
RemoteRef
=
RemoteRef
...
@@ -109,6 +115,7 @@ data Config (loaded :: Bool) = Config
...
@@ -109,6 +115,7 @@ data Config (loaded :: Bool) = Config
,
_verbose
::
Bool
,
_verbose
::
Bool
,
_interval
::
Int
,
_interval
::
Int
-- ^ port to bind to
-- ^ port to bind to
,
_exneuland
::
BaseUrl
,
_orgs
::
[
Org
loaded
]
,
_orgs
::
[
Org
loaded
]
}
deriving
Generic
}
deriving
Generic
...
@@ -130,6 +137,11 @@ orgCodec = Org
...
@@ -130,6 +137,11 @@ orgCodec = Org
<*>
T
.
text
"url"
.=
orgUrl
<*>
T
.
text
"url"
.=
orgUrl
<*>
T
.
text
"webdir"
.=
orgWebdir
<*>
T
.
text
"webdir"
.=
orgWebdir
-- why exactly does everything in tomland need to be invertable
urlBimap
::
TomlBiMap
BaseUrl
String
urlBimap
=
BiMap
(
Right
.
show
)
(
mapLeft
(
ArbitraryError
.
show
)
.
parseBaseUrl
)
configCodec
::
TomlCodec
(
Config
False
)
configCodec
::
TomlCodec
(
Config
False
)
configCodec
=
Config
configCodec
=
Config
...
@@ -137,6 +149,7 @@ configCodec = Config
...
@@ -137,6 +149,7 @@ configCodec = Config
<*>
T
.
int
"port"
.=
_port
<*>
T
.
int
"port"
.=
_port
<*>
T
.
bool
"verbose"
.=
_verbose
<*>
T
.
bool
"verbose"
.=
_verbose
<*>
T
.
int
"interval"
.=
_interval
<*>
T
.
int
"interval"
.=
_interval
<*>
T
.
match
(
urlBimap
>>>
T
.
_String
)
"exneuland"
.=
_exneuland
<*>
T
.
list
orgCodec
"org"
.=
_orgs
<*>
T
.
list
orgCodec
"org"
.=
_orgs
-- | a job status (of a specific uuid)
-- | a job status (of a specific uuid)
...
...
This diff is collapsed.
Click to expand it.
walint.cabal
+
2
−
0
View file @
cc52022f
...
@@ -105,12 +105,14 @@ executable walint-server
...
@@ -105,12 +105,14 @@ executable walint-server
, extra
, extra
, filepath
, filepath
, fmt
, fmt
, http-client
, http-types
, http-types
, lucid
, lucid
, microlens-platform
, microlens-platform
, mtl
, mtl
, process
, process
, servant
, servant
, servant-client
, servant-lucid
, servant-lucid
, servant-server
, servant-server
, stm
, stm
...
...
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