From ded42e07a885686d0c0adc1a746c04079c447778 Mon Sep 17 00:00:00 2001 From: Ramakrishnan Muthukrishnan <ram@leastauthority.com> Date: Thu, 31 Oct 2019 14:56:25 +0530 Subject: [PATCH] add a commandline parameter to take in the stripe API key --- src/PaymentServer/Main.hs | 11 +++++++++-- src/PaymentServer/Server.hs | 13 ++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/PaymentServer/Main.hs b/src/PaymentServer/Main.hs index eb988b7..e337919 100644 --- a/src/PaymentServer/Main.hs +++ b/src/PaymentServer/Main.hs @@ -11,6 +11,8 @@ import Text.Printf ) import Data.Maybe ( maybeToList +import Data.ByteString + ( ByteString ) import Data.Text ( Text @@ -90,6 +92,7 @@ data ServerConfig = ServerConfig , database :: Database , databasePath :: Maybe Text , endpoint :: Endpoint + , stripeKey :: ByteString } deriving (Show, Eq) @@ -159,7 +162,9 @@ sample = ServerConfig <> help "Path to on-disk database (sqlite3 only)" <> showDefault ) ) <*> (http <|> https) - + <*> option str + ( long "stripe-key" + <> help "Stripe API key" ) opts :: ParserInfo ServerConfig opts = info (sample <**> helper) @@ -221,6 +226,8 @@ getApp config = exitFailure Right getDB -> do db <- getDB - let app = paymentServerApp issuer db + let port = 8081 + let key = stripeKey config + let app = paymentServerApp key issuer db logger <- mkRequestLogger (def { outputFormat = Detailed True}) return $ logger app diff --git a/src/PaymentServer/Server.hs b/src/PaymentServer/Server.hs index d8898e0..bfef18b 100644 --- a/src/PaymentServer/Server.hs +++ b/src/PaymentServer/Server.hs @@ -8,6 +8,9 @@ module PaymentServer.Server ( paymentServerApp ) where +import Data.ByteString + ( ByteString + ) import Servant ( Proxy(Proxy) , Server @@ -37,9 +40,9 @@ type PaymentServerAPI :<|> "v1" :> "redeem" :> RedemptionAPI -- | Create a server which uses the given database. -paymentServer :: VoucherDatabase d => Issuer -> d -> Server PaymentServerAPI -paymentServer issuer database = - stripeServer database "test" +paymentServer :: VoucherDatabase d => ByteString -> Issuer -> d -> Server PaymentServerAPI +paymentServer key issuer database = + stripeServer database key :<|> redemptionServer issuer database paymentServerAPI :: Proxy PaymentServerAPI @@ -47,5 +50,5 @@ paymentServerAPI = Proxy -- | Create a Servant Application which serves the payment server API using -- the given database. -paymentServerApp :: VoucherDatabase d => Issuer -> d -> Application -paymentServerApp issuer = serve paymentServerAPI . paymentServer issuer +paymentServerApp :: VoucherDatabase d => ByteString -> Issuer -> d -> Application +paymentServerApp key issuer = serve paymentServerAPI . paymentServer key issuer -- GitLab