diff options
author | Ben Sima <ben@bsima.me> | 2020-12-30 18:03:29 -0500 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2020-12-30 18:03:29 -0500 |
commit | 7ec9b3277dc6858c2acf752540526e1ee5db0ea2 (patch) | |
tree | dfc08498a4d35738ce545ca7e61621a556f065c3 /Biz | |
parent | 9da4feb106126940264dd27925ea3c19b04aac20 (diff) |
que: use EnvironmentFile instead of keyfile
Diffstat (limited to 'Biz')
-rw-r--r-- | Biz/Que/Host.hs | 15 | ||||
-rw-r--r-- | Biz/Que/Host.nix | 1 |
2 files changed, 7 insertions, 9 deletions
diff --git a/Biz/Que/Host.hs b/Biz/Que/Host.hs index 3668a29..f41c683 100644 --- a/Biz/Que/Host.hs +++ b/Biz/Que/Host.hs @@ -36,7 +36,6 @@ import Data.HashMap.Lazy (HashMap) import qualified Data.HashMap.Lazy as HashMap import qualified Data.Text.Encoding as Encoding import qualified Data.Text.Lazy as Text.Lazy -import qualified Data.Text.Lazy.IO as Text.Lazy.IO import qualified Network.HTTP.Types.Status as Http import qualified Network.Wai as Wai import qualified Network.Wai.Handler.Warp as Warp @@ -58,9 +57,9 @@ main = Exception.bracket startup shutdown <| uncurry Warp.run let runActionToIO m = runReaderT (runApp m) sync waiapp <- Scotty.scottyAppT runActionToIO <| routes c putText "*" - putText "Que.Host" + putText "que" putText <| "port: " <> (show <| quePort c) - putText <| "skey: " <> (show <| queSkey c) + putText <| "skey: " <> (Text.Lazy.toStrict <| queSkey c) return (quePort c, waiapp) shutdown :: a -> IO a shutdown = pure <. identity @@ -88,12 +87,12 @@ data Config = Config { -- | QUE_PORT quePort :: Warp.Port, -- | QUE_SKEY - queSkey :: FilePath + queSkey :: Text.Lazy.Text } deriving (Generic, Show) instance Envy.DefConfig Config where - defConfig = Config 3000 "/run/skey/que-admin" + defConfig = Config 3000 "admin-key" instance Envy.FromEnv Config @@ -109,8 +108,7 @@ routes cfg = do -- GET /_/dash Scotty.get (Scotty.literal "/_/dash") <| do authkey <- fromMaybe "" </ Scotty.header "Authorization" - adminkey <- liftIO <| lchomp </ Text.Lazy.IO.readFile (queSkey cfg) - if authkey == adminkey + if authkey == (Text.Lazy.strip <| queSkey cfg) then do d <- app <| gets ques Scotty.json d @@ -142,10 +140,9 @@ routes cfg = do -- Put a value on a que. Returns immediately. Scotty.post (Scotty.regex quepath) <| do authkey <- fromMaybe "" </ Scotty.header "Authorization" - adminkey <- liftIO <| lchomp </ Text.Lazy.IO.readFile (queSkey cfg) (ns, qp) <- extract -- Only allow my IP or localhost to publish to '_' namespace - when ("_" == ns && authkey /= adminkey) + when ("_" == ns && authkey /= (Text.Lazy.strip <| queSkey cfg)) <| Scotty.status Http.methodNotAllowed405 >> Scotty.text "not allowed: _ is a reserved namespace" >> Scotty.finish diff --git a/Biz/Que/Host.nix b/Biz/Que/Host.nix index e326483..23dab65 100644 --- a/Biz/Que/Host.nix +++ b/Biz/Que/Host.nix @@ -36,6 +36,7 @@ in ''; serviceConfig = { Environment = ["QUE_PORT=${toString cfg.port}"]; + EnvironmentFile = "/run/que/env"; KillSignal = "INT"; Type = "simple"; Restart = "on-abort"; |