-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
502 additions
and
257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{-# LANGUAGE TemplateHaskell #-} | ||
module Zureg.AWS | ||
( Config | ||
, smartEnv | ||
) where | ||
|
||
import Amazonka | ||
import Amazonka.Auth | ||
import qualified Amazonka.Data as Amazonka | ||
import qualified Data.Aeson as A | ||
import qualified Data.Aeson.TH.Extended as A | ||
import qualified Data.Text as T | ||
import qualified Data.Text.Encoding as T | ||
import System.Environment (lookupEnv) | ||
import qualified System.IO as IO | ||
|
||
data Config = Config | ||
{ configRegion :: !T.Text | ||
, configAccessKey :: !T.Text | ||
, configSecretKey :: !T.Text | ||
} deriving (Show) | ||
|
||
-- | AWS region is not retrieved correctly from environment variables, and | ||
-- neither from the AWS profile. | ||
smartEnv :: Config -> IO Env | ||
smartEnv conf = do | ||
logger' <- newLogger Info IO.stderr | ||
region' <- either fail pure $ Amazonka.fromText (configRegion conf) | ||
env <- newEnvNoAuth | ||
pure $ fromKeys | ||
(AccessKey $ T.encodeUtf8 $ configAccessKey conf) | ||
(SecretKey $ T.encodeUtf8 $ configSecretKey conf) | ||
env | ||
{ logger = logger' | ||
, region = region' | ||
} | ||
|
||
$(A.deriveJSON A.options ''Config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{-# LANGUAGE TemplateHaskell #-} | ||
module Zureg.Config | ||
( Config (..) | ||
, load | ||
) where | ||
|
||
import qualified Data.Aeson as A | ||
import qualified Data.Aeson.TH.Extended as A | ||
import qualified Data.Text as T | ||
import qualified Zureg.AWS as AWS | ||
import qualified Zureg.Captcha.HCaptcha as HCaptcha | ||
import qualified Zureg.Database as Database | ||
import qualified Zureg.Hackathon.Interface as Hackathon | ||
import qualified Zureg.Hackathon.ZuriHac2020.Discord as Discord | ||
|
||
data Config = Config | ||
{ configHackathon :: !Hackathon.Hackathon | ||
, configDatabase :: !Database.Config | ||
, configDiscord :: !Discord.Config | ||
, configCaptcha :: !(Maybe HCaptcha.Config) | ||
, configAws :: !AWS.Config | ||
, configScannerSecret :: !T.Text | ||
} deriving (Show) | ||
|
||
$(A.deriveFromJSON A.options ''Config) | ||
|
||
load :: IO Config | ||
load = either fail pure =<< A.eitherDecodeFileStrict "config.json" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | ||
{-# LANGUAGE RecordWildCards #-} | ||
module Zureg.Database.Internal | ||
( Config (..) | ||
, Handle (..) | ||
, withHandle | ||
, Transaction (..) | ||
, withTransaction | ||
) where | ||
|
||
import Control.Exception (bracket) | ||
import qualified Data.Aeson as A | ||
import qualified Data.ByteString.Char8 as BS8 | ||
import qualified Data.Text as T | ||
import qualified Data.Text.Encoding as T | ||
import qualified Database.PostgreSQL.Simple as Pg | ||
|
||
newtype Config = Config | ||
{ cConnectionString :: T.Text | ||
} deriving (A.FromJSON, Show) | ||
|
||
data Handle = Handle | ||
{ hConfig :: !Config | ||
} | ||
|
||
withHandle :: Config -> (Handle -> IO a) -> IO a | ||
withHandle hConfig f = do | ||
f Handle {..} | ||
|
||
newtype Transaction = Transaction Pg.Connection | ||
|
||
withTransaction :: Handle -> (Transaction -> IO a) -> IO a | ||
withTransaction Handle {..} = bracket | ||
(fmap Transaction $ Pg.connectPostgreSQL $ | ||
T.encodeUtf8 $ cConnectionString hConfig) | ||
(\(Transaction conn) -> Pg.close conn) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.