mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 01:12:56 +03:00
29f2ddc289
This is an incremental PR towards https://github.com/hasura/graphql-engine/pull/5797 Co-authored-by: Anon Ray <ecthiender@users.noreply.github.com> GitOrigin-RevId: a6cb8c239b2ff840a0095e78845f682af0e588a9
40 lines
1023 B
Haskell
40 lines
1023 B
Haskell
{-# LANGUAGE DeriveGeneric #-}
|
|
|
|
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
|