Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PaymentServer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Administrator
PaymentServer
Commits
5afdba98
Commit
5afdba98
authored
5 years ago
by
Jean-Paul Calderone
Browse files
Options
Downloads
Patches
Plain Diff
Switch to running on TLS
parent
028d2615
No related branches found
Branches containing commit
No related tags found
1 merge request
!27
Switch to running on TLS
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
PaymentServer.cabal
+1
-0
1 addition, 0 deletions
PaymentServer.cabal
src/PaymentServer/Main.hs
+53
-11
53 additions, 11 deletions
src/PaymentServer/Main.hs
with
54 additions
and
11 deletions
PaymentServer.cabal
+
1
−
0
View file @
5afdba98
...
@@ -31,6 +31,7 @@ library
...
@@ -31,6 +31,7 @@ library
, wai-extra
, wai-extra
, data-default
, data-default
, warp
, warp
, warp-tls
, stripe-core
, stripe-core
, text
, text
, containers
, containers
...
...
This diff is collapsed.
Click to expand it.
src/PaymentServer/Main.hs
+
53
−
11
View file @
5afdba98
...
@@ -9,6 +9,9 @@ module PaymentServer.Main
...
@@ -9,6 +9,9 @@ module PaymentServer.Main
import
Text.Printf
import
Text.Printf
(
printf
(
printf
)
)
import
Data.Maybe
(
maybeToList
)
import
Data.Text
import
Data.Text
(
Text
(
Text
)
)
...
@@ -16,7 +19,16 @@ import Data.Default
...
@@ -16,7 +19,16 @@ import Data.Default
(
def
(
def
)
)
import
Network.Wai.Handler.Warp
import
Network.Wai.Handler.Warp
(
run
(
defaultSettings
,
setPort
)
import
Network.Wai.Handler.WarpTLS
(
TLSSettings
,
runTLS
,
tlsSettingsChain
)
import
Network.Wai
(
Application
)
)
import
Network.Wai.Middleware.RequestLogger
import
Network.Wai.Middleware.RequestLogger
(
OutputFormat
(
Detailed
)
(
OutputFormat
(
Detailed
)
...
@@ -38,6 +50,7 @@ import PaymentServer.Server
...
@@ -38,6 +50,7 @@ import PaymentServer.Server
import
Options.Applicative
import
Options.Applicative
(
Parser
(
Parser
,
ParserInfo
,
ParserInfo
,
strOption
,
option
,
option
,
auto
,
auto
,
str
,
str
...
@@ -70,10 +83,14 @@ data Database =
...
@@ -70,10 +83,14 @@ data Database =
deriving
(
Show
,
Eq
,
Ord
,
Read
)
deriving
(
Show
,
Eq
,
Ord
,
Read
)
data
ServerConfig
=
ServerConfig
data
ServerConfig
=
ServerConfig
{
issuer
::
Issuer
{
issuer
::
Issuer
,
signingKey
::
Maybe
Text
,
signingKey
::
Maybe
Text
,
database
::
Database
,
database
::
Database
,
databasePath
::
Maybe
Text
,
databasePath
::
Maybe
Text
,
httpPortNumber
::
Int
,
certificatePath
::
String
,
chainPath
::
Maybe
String
,
keyPath
::
String
}
}
deriving
(
Show
,
Eq
)
deriving
(
Show
,
Eq
)
...
@@ -97,6 +114,21 @@ sample = ServerConfig
...
@@ -97,6 +114,21 @@ sample = ServerConfig
(
long
"database-path"
(
long
"database-path"
<>
help
"Path to on-disk database (sqlite3 only)"
<>
help
"Path to on-disk database (sqlite3 only)"
<>
showDefault
)
)
<>
showDefault
)
)
<*>
option
auto
(
long
"https-port"
<>
help
"Port number on which to accept HTTPS connections."
<>
showDefault
<>
value
443
)
<*>
strOption
(
long
"https-certificate-path"
<>
help
"Filesystem path to the TLS certificate to use for HTTPS."
)
<*>
optional
(
strOption
(
long
"https-certificate-chain-path"
<>
help
"Filesystem path to the TLS certificate chain to use for HTTPS."
)
)
<*>
strOption
(
long
"https-key-path"
<>
help
"Filesystem path to the TLS private key to use for HTTPS."
)
opts
::
ParserInfo
ServerConfig
opts
::
ParserInfo
ServerConfig
opts
=
info
(
sample
<**>
helper
)
opts
=
info
(
sample
<**>
helper
)
...
@@ -106,7 +138,20 @@ opts = info (sample <**> helper)
...
@@ -106,7 +138,20 @@ opts = info (sample <**> helper)
)
)
main
::
IO
()
main
::
IO
()
main
=
main
=
do
config
<-
execParser
opts
let
port
=
httpPortNumber
config
app
<-
getApp
config
tlsSettings
<-
getTlsSettings
config
putStrLn
(
printf
"Accepting HTTPS connections on %d"
port
::
String
)
runTLS
tlsSettings
(
setPort
port
defaultSettings
)
app
getTlsSettings
::
ServerConfig
->
IO
TLSSettings
getTlsSettings
ServerConfig
{
certificatePath
,
chainPath
,
keyPath
}
=
return
$
tlsSettingsChain
certificatePath
(
maybeToList
chainPath
)
keyPath
getApp
::
ServerConfig
->
IO
Application
getApp
config
=
let
let
getIssuer
ServerConfig
{
issuer
,
signingKey
}
=
getIssuer
ServerConfig
{
issuer
,
signingKey
}
=
case
(
issuer
,
signingKey
)
of
case
(
issuer
,
signingKey
)
of
...
@@ -119,20 +164,17 @@ main =
...
@@ -119,20 +164,17 @@ main =
(
SQLite3
,
Just
path
)
->
Right
(
getDBConnection
path
)
(
SQLite3
,
Just
path
)
->
Right
(
getDBConnection
path
)
_
->
Left
"invalid options"
_
->
Left
"invalid options"
in
do
in
do
config
<-
execParser
opts
case
getIssuer
config
of
case
getIssuer
config
of
Left
err
->
do
Left
err
->
do
print
err
print
err
exitFailure
exitFailure
Right
issuer
->
Right
issuer
->
case
getDatabase
config
of
case
getDatabase
config
of
Left
err
->
do
Left
err
->
do
print
err
print
err
exitFailure
exitFailure
Right
getDB
->
do
Right
getDB
->
do
db
<-
getDB
db
<-
getDB
let
port
=
8081
let
app
=
paymentServerApp
issuer
db
let
app
=
paymentServerApp
issuer
db
logger
<-
mkRequestLogger
(
def
{
outputFormat
=
Detailed
True
})
logger
<-
mkRequestLogger
(
def
{
outputFormat
=
Detailed
True
})
putStrLn
(
printf
"Listening on %d"
port
::
String
)
return
$
logger
app
run
port
$
logger
app
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment