graphql-engine/server/src-lib/Data/Environment.hs
Solomon e4064c9a90 Allows for mock env vars in test-webhook-transform endpoint
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3097
Co-authored-by: Lyndon Maydwell <92299+sordina@users.noreply.github.com>
GitOrigin-RevId: f0cd00b8f972a1b96213bd098ea09d72b3aba723
2021-12-09 07:59:46 +00:00

43 lines
1.1 KiB
Haskell

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 :: 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