-
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
34 changed files
with
646 additions
and
645 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,36 @@ | ||
{-# LANGUAGE TemplateHaskell #-} | ||
module Zureg.AWS | ||
( Config | ||
, smartEnv | ||
) where | ||
|
||
import Amazonka | ||
import Amazonka.Auth | ||
import qualified Amazonka.Data as Amazonka | ||
import qualified Data.Aeson.TH.Extended as A | ||
import qualified Data.Text as T | ||
import qualified Data.Text.Encoding as T | ||
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
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,32 @@ | ||
{-# 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 System.Directory (doesFileExist) | ||
import qualified Zureg.AWS as AWS | ||
import qualified Zureg.Captcha.HCaptcha as HCaptcha | ||
import qualified Zureg.Database as Database | ||
import qualified Zureg.Hackathon 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 = do | ||
local <- doesFileExist "zureg.json" | ||
let path = if local then "zureg.json" else "/etc/zureg.json" | ||
either fail pure =<< A.eitherDecodeFileStrict path |
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.