Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
a7566350
Commit
a7566350
authored
Oct 17, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Little more refactoring in letsencrypt
parent
96ae288c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
21 deletions
+30
-21
config/letsencrypt/letsencrypt.go
config/letsencrypt/letsencrypt.go
+30
-21
No files found.
config/letsencrypt/letsencrypt.go
View file @
a7566350
...
...
@@ -55,27 +55,7 @@ func Activate(configs []server.Config) ([]server.Config, error) {
}
// it all comes down to this: filling in the file path of a valid certificate automatically
for
_
,
cfg
:=
range
serverConfigs
{
cfg
.
TLS
.
Certificate
=
storage
.
SiteCertFile
(
cfg
.
Host
)
cfg
.
TLS
.
Key
=
storage
.
SiteKeyFile
(
cfg
.
Host
)
cfg
.
TLS
.
Enabled
=
true
cfg
.
Port
=
"https"
// Is there a plaintext HTTP config for the same host? If not, make
// one and have it redirect all requests to this HTTPS host.
var
plaintextHostFound
bool
for
_
,
otherCfg
:=
range
configs
{
if
cfg
.
Host
==
otherCfg
.
Host
&&
otherCfg
.
Port
==
"http"
{
plaintextHostFound
=
true
break
}
}
if
!
plaintextHostFound
{
// Make one that redirects to HTTPS for all requests
configs
=
append
(
configs
,
redirPlaintextHost
(
*
cfg
))
}
}
configs
=
autoConfigure
(
configs
,
serverConfigs
)
}
return
configs
,
nil
...
...
@@ -188,6 +168,35 @@ func saveCertsAndKeys(certificates []acme.CertificateResource) error {
return
nil
}
// autoConfigure enables TLS on all the configs in serverConfigs
// and appends, if necessary, new configs to allConfigs that redirect
// plaintext HTTP to their HTTPS counterparts.
func
autoConfigure
(
allConfigs
[]
server
.
Config
,
serverConfigs
[]
*
server
.
Config
)
[]
server
.
Config
{
for
_
,
cfg
:=
range
serverConfigs
{
cfg
.
TLS
.
Certificate
=
storage
.
SiteCertFile
(
cfg
.
Host
)
cfg
.
TLS
.
Key
=
storage
.
SiteKeyFile
(
cfg
.
Host
)
cfg
.
TLS
.
Enabled
=
true
cfg
.
Port
=
"https"
// Is there a plaintext HTTP config for the same host? If not, make
// one and have it redirect all requests to this HTTPS host.
var
plaintextHostFound
bool
for
_
,
otherCfg
:=
range
allConfigs
{
if
cfg
.
Host
==
otherCfg
.
Host
&&
otherCfg
.
Port
==
"http"
{
plaintextHostFound
=
true
break
}
}
if
!
plaintextHostFound
{
// Make one that redirects to HTTPS for all requests
allConfigs
=
append
(
allConfigs
,
redirPlaintextHost
(
*
cfg
))
}
}
return
allConfigs
}
// redirPlaintextHost returns a new plaintext HTTP configuration for
// a virtualHost that simply redirects to cfg, which is assumed to
// be the HTTPS configuration. The returned configuration is set
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment