-
Notifications
You must be signed in to change notification settings - Fork 0
/
drone-convert-dhall.hs
35 lines (28 loc) · 1.36 KB
/
drone-convert-dhall.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.ByteString (ByteString)
import Data.Text (Text, unpack)
import Data.Text.Encoding (decodeUtf8, encodeUtf8)
import Dhall.Yaml (Options (documents), defaultOptions, dhallToYaml)
import DroneDhall.Models (Config (Config), config, config_path, data', repo)
import Lens.Micro.Platform ((^.))
import Network.Wai.Middleware.RequestLogger (logStdoutDev)
import System.FilePath (takeExtension)
import Web.Scotty (ActionM, json, jsonData, liftAndCatchIO, middleware, post, scotty)
dhallOptions :: Options
dhallOptions = defaultOptions { documents = True }
processPipilineConfig :: String -> Text -> IO ByteString
processPipilineConfig ".dhall" config = dhallToYaml dhallOptions Nothing config
processPipilineConfig _ config = return $ encodeUtf8 config
main :: IO ()
main = do
scotty 3000 $ do
middleware logStdoutDev
post "/" $ do
req <- jsonData
let resp = Config . decodeUtf8 <$> processPipilineConfig (extension req) (configSource req)
result <- liftAndCatchIO resp
json result
where
extension req = takeExtension $ unpack $ req^.repo.config_path
configSource req = req^.config.data'