Browse Source

Add env var support

tags/v1.0.0
Chris Smith 5 years ago
parent
commit
00b6ed3c5c
4 changed files with 36 additions and 14 deletions
  1. 22
    14
      README.adoc
  2. 4
    0
      go.mod
  3. 8
    0
      go.sum
  4. 2
    0
      main.go

+ 22
- 14
README.adoc View File

@@ -17,39 +17,47 @@ The simplest way to use this is via docker:
17 17
 You should place this service behind an TLS-terminating proxy, and ensure it
18 18
 is requested over a secure connection.
19 19
 
20
-== Command line flags
20
+== Parameters
21
+
22
+The application can be configured either using command line arguments
23
+or environmental variables (shown in square brackets, below).
24
+_from_, _to_, _smtp-host_, _smtp-user_, and _smtp-pass_ are required;
25
+other options have vaguely sensible fallbacks.
21 26
 
22 27
 ----
23 28
   -crsf-key string
24
-        CRSF key to use
29
+    	CRSF key to use [CONTACT_CRSF_KEY]
25 30
   -from string
26
-        address to send e-mail from
31
+    	address to send e-mail from [CONTACT_FROM]
27 32
   -port int
28
-        port to listen on for connections (default 8080)
33
+    	port to listen on for connections [CONTACT_PORT] (default 8080)
29 34
   -smtp-host string
30
-        SMTP server to connect to
35
+    	SMTP server to connect to [CONTACT_SMTP_HOST]
31 36
   -smtp-pass string
32
-        password to supply to the SMTP server
37
+    	password to supply to the SMTP server [CONTACT_SMTP_PASS]
33 38
   -smtp-port int
34
-        port to use when connecting to the SMTP server (default 25)
39
+    	port to use when connecting to the SMTP server [CONTACT_SMTP_PORT] (default 25)
35 40
   -smtp-user string
36
-        username to supply to the SMTP server
41
+    	username to supply to the SMTP server [CONTACT_SMTP_USER]
37 42
   -subject string
38
-        e-mail subject (default "Contact form submission")
43
+    	e-mail subject [CONTACT_SUBJECT] (default "Contact form submission")
39 44
   -to string
40
-        address to send e-mail to
45
+    	address to send e-mail to [CONTACT_TO]
41 46
 ----
42 47
 
43
-_from_, _to_, _smtp-host_, _smtp-user_, and _smtp-pass_ are required; other options have vaguely sensible fallbacks.
48
+You can use any SMTP server; however I recommend using a dedicated service
49
+such as https://www.mailgun.com/[mailgun] or
50
+https://aws.amazon.com/ses/[AWS SES], both of which you can access over SMTP.
44 51
 
45 52
 == Templates
46 53
 
47 54
 The form itself is loaded from `form.html` in the working directory; success and failure pages from `success.html`
48 55
 and `failure.html` respectively. Each is loaded as a https://golang.org/pkg/html/template/[go html.template] and
49
-can use the templating syntax described there.
56
+can use the templating syntax described there. The form must contain the `{{ .csrfField }}` template field, which
57
+will automatically insert the CSRF token for the request.
50 58
 
51
-The form must contain the `{{ .csrfField }}` template field, which will automatically insert the CSRF token for
52
-the request.
59
+When running from the docker image, templates are stored in `/templates`; you can
60
+replace this with a volume to supply custom templates.
53 61
 
54 62
 == Credits
55 63
 

+ 4
- 0
go.mod View File

@@ -5,4 +5,8 @@ go 1.12
5 5
 require (
6 6
 	github.com/gorilla/csrf v1.5.1 // indirect
7 7
 	github.com/gorilla/mux v1.7.1 // indirect
8
+	github.com/inconshreveable/mousetrap v1.0.0 // indirect
9
+	github.com/jamiealquiza/envy v1.1.0 // indirect
10
+	github.com/spf13/cobra v0.0.3 // indirect
11
+	github.com/spf13/pflag v1.0.3 // indirect
8 12
 )

+ 8
- 0
go.sum View File

@@ -5,5 +5,13 @@ github.com/gorilla/mux v1.7.1 h1:Dw4jY2nghMMRsh1ol8dv1axHkDwMQK2DHerMNJsIpJU=
5 5
 github.com/gorilla/mux v1.7.1/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
6 6
 github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
7 7
 github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
8
+github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
9
+github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
10
+github.com/jamiealquiza/envy v1.1.0 h1:Nwh4wqTZ28gDA8zB+wFkhnUpz3CEcO12zotjeqqRoKE=
11
+github.com/jamiealquiza/envy v1.1.0/go.mod h1:MP36BriGCLwEHhi1OU8E9569JNZrjWfCvzG7RsPnHus=
8 12
 github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
9 13
 github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
14
+github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8=
15
+github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
16
+github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
17
+github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=

+ 2
- 0
main.go View File

@@ -5,6 +5,7 @@ import (
5 5
 	"fmt"
6 6
 	"github.com/gorilla/csrf"
7 7
 	"github.com/gorilla/mux"
8
+	"github.com/jamiealquiza/envy"
8 9
 	"html/template"
9 10
 	"log"
10 11
 	"math/rand"
@@ -105,6 +106,7 @@ func main() {
105 106
 	smtpPassword = flag.String("smtp-pass", "", "password to supply to the SMTP server")
106 107
 	csrfKey = flag.String("crsf-key", "", "CRSF key to use")
107 108
 	port = flag.Int("port", 8080, "port to listen on for connections")
109
+	envy.Parse("CONTACT")
108 110
 	flag.Parse()
109 111
 
110 112
 	checkFlag(*fromAddress, "from address")

Loading…
Cancel
Save