summaryrefslogtreecommitdiff
path: root/server/Serverconfig.hs
diff options
context:
space:
mode:
authorstuebinm2022-02-01 00:30:13 +0100
committerstuebinm2022-03-19 19:25:50 +0100
commit9e3783d04284f25571a744755a82afbd7e2c6534 (patch)
treefdf08a6f6dee476c0189afb8cb7cf39b7e127244 /server/Serverconfig.hs
parent1530a4646b5bb7ab2930d1433eda87d5f0936125 (diff)
basic server setup (using servant)
adds a very basic http server that can be sent links to repositories & will download & lint them, then answer the request with the lints. Should probably do this in a non-blocking way …
Diffstat (limited to '')
-rw-r--r--server/Serverconfig.hs45
1 files changed, 45 insertions, 0 deletions
diff --git a/server/Serverconfig.hs b/server/Serverconfig.hs
new file mode 100644
index 0000000..d919567
--- /dev/null
+++ b/server/Serverconfig.hs
@@ -0,0 +1,45 @@
+{-# LANGUAGE DataKinds #-}
+{-# LANGUAGE DeriveAnyClass #-}
+{-# LANGUAGE DeriveGeneric #-}
+{-# LANGUAGE KindSignatures #-}
+{-# LANGUAGE RankNTypes #-}
+{-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE TypeApplications #-}
+{-# LANGUAGE TypeFamilies #-}
+{-# LANGUAGE TypeOperators #-}
+
+module Serverconfig (loadConfig, Config(..), RemoteRef(..)) where
+
+import Data.Aeson (FromJSON, eitherDecode)
+import qualified Data.ByteString.Lazy as LB
+import Data.Text (Text)
+import GHC.Generics (Generic)
+import LintConfig (LintConfig')
+
+-- | a reference in a remote git repository
+data RemoteRef = RemoteRef
+ { repourl :: Text
+ , reporef :: Text
+ } deriving (Generic, FromJSON)
+
+type family ConfigRes (b :: Bool) a where
+ ConfigRes True a = a
+ ConfigRes False a = FilePath
+
+-- | the server's configuration
+data Config l = Config
+ { tmpdir :: FilePath
+ -- ^ dir to clone git things in
+ , port :: Int
+ -- ^ port to bind to
+ , entrypoint :: FilePath
+ , lintconfig :: ConfigRes l LintConfig'
+ }
+
+loadConfig :: Config False -> IO (Config True)
+loadConfig config = do
+ loaded <- LB.readFile (lintconfig config) >>= \res ->
+ case eitherDecode res :: Either String LintConfig' of
+ Left err -> error $ "config file invalid: " <> err
+ Right file -> pure file
+ pure $ config { lintconfig = loaded }