mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-18 04:51:35 +03:00
cfd33e0dba
Some fixes as a followup to #8311. In particular, some pragmas were referring to a now-nonexistent hlint rule. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/8569 GitOrigin-RevId: 2a180427b3e93a71c47569ff10b6c8b6b407f7a2
47 lines
1.3 KiB
Haskell
47 lines
1.3 KiB
Haskell
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
|
|
|
|
module Data.Environment
|
|
( Environment (),
|
|
getEnvironment,
|
|
mkEnvironment,
|
|
emptyEnvironment,
|
|
maybeEnvironment,
|
|
lookupEnv,
|
|
redactEnv,
|
|
Data.Environment.toList,
|
|
)
|
|
where
|
|
|
|
import Data.Aeson
|
|
import Data.Map qualified as M
|
|
import Hasura.Prelude
|
|
import System.Environment qualified
|
|
|
|
-- | Server process environment variables
|
|
newtype Environment = Environment (M.Map String String) deriving (Eq, Show, Generic, ToJSON, Semigroup, Monoid)
|
|
|
|
instance FromJSON Environment
|
|
|
|
-- 'getEnvironment' is allowed to use 'System.Environment.getEnvironment'
|
|
{-# ANN getEnvironment ("HLINT: ignore avoid getEnvironment" :: String) #-}
|
|
getEnvironment :: IO Environment
|
|
getEnvironment = mkEnvironment <$> System.Environment.getEnvironment
|
|
|
|
maybeEnvironment :: Maybe Environment -> Environment
|
|
maybeEnvironment = fromMaybe emptyEnvironment
|
|
|
|
mkEnvironment :: [(String, String)] -> Environment
|
|
mkEnvironment = Environment . M.fromList
|
|
|
|
emptyEnvironment :: Environment
|
|
emptyEnvironment = Environment M.empty
|
|
|
|
lookupEnv :: Environment -> String -> Maybe String
|
|
lookupEnv (Environment es) k = M.lookup k es
|
|
|
|
toList :: Environment -> [(String, String)]
|
|
toList (Environment e) = M.toList e
|
|
|
|
redactEnv :: Environment -> Environment
|
|
redactEnv (Environment e) = Environment $ fmap (const "<ENV REDACTED>") e
|