mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-23 07:22:53 +03:00
1abb1dee69
https://github.com/hasura/graphql-engine-mono/pull/1740 GitOrigin-RevId: e807952058243a97f67cd9969fa434933a08652f
43 lines
1.1 KiB
Haskell
43 lines
1.1 KiB
Haskell
module Data.Environment
|
|
( Environment()
|
|
, getEnvironment
|
|
, mkEnvironment
|
|
, emptyEnvironment
|
|
, maybeEnvironment
|
|
, lookupEnv
|
|
, redactEnv
|
|
, Data.Environment.toList
|
|
) where
|
|
|
|
import Data.Aeson
|
|
import Hasura.Prelude
|
|
|
|
import qualified Data.Map as M
|
|
import qualified System.Environment
|
|
|
|
-- | Server process environment variables
|
|
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
|
|
|
|
redactEnv :: Environment -> Environment
|
|
redactEnv (Environment e) = Environment $ fmap (const "******") e
|