graphql-engine/server/src-lib/Data/Environment.hs
Antoine Leblanc dd1192ca2c server: cleanup of language extensions [gardening]
GitOrigin-RevId: d862c724715cb8a4c2f37d2e0e525d12c46b18eb
2021-04-16 06:55:56 +00:00

38 lines
991 B
Haskell

module Data.Environment
( Environment()
, getEnvironment
, mkEnvironment
, emptyEnvironment
, maybeEnvironment
, lookupEnv
, Data.Environment.toList
) where
import Data.Aeson
import Hasura.Prelude
import qualified Data.Map as M
import qualified System.Environment
newtype Environment = Environment (M.Map String String) deriving (Eq, Show, Generic)
instance FromJSON Environment
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