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
ad20323b
Commit
ad20323b
authored
Jun 19, 2019
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor clustering setup code
parent
721c100b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
44 deletions
+30
-44
caddytls/config.go
caddytls/config.go
+4
-25
caddytls/setup.go
caddytls/setup.go
+26
-19
No files found.
caddytls/config.go
View file @
ad20323b
...
...
@@ -19,8 +19,6 @@ import (
"crypto/x509"
"fmt"
"io/ioutil"
"os"
"sync/atomic"
"time"
"github.com/go-acme/lego/challenge/tlsalpn01"
...
...
@@ -103,31 +101,14 @@ func NewConfig(inst *caddy.Instance) (*Config, error) {
certCache
,
ok
:=
inst
.
Storage
[
CertCacheInstStorageKey
]
.
(
*
certmagic
.
Cache
)
inst
.
StorageMu
.
RUnlock
()
if
!
ok
||
certCache
==
nil
{
// set up the clustering plugin, if there is one (and there should always
// be one since this tls plugin requires it) -- this should be done exactly
// once, but we can't do it during init while plugins are still registering,
// so do it as soon as we run a setup)
if
atomic
.
CompareAndSwapInt32
(
&
clusterPluginSetup
,
0
,
1
)
{
clusterPluginName
:=
os
.
Getenv
(
"CADDY_CLUSTERING"
)
if
clusterPluginName
==
""
{
clusterPluginName
=
"file"
// name of default storage plugin
}
clusterFn
,
ok
:=
clusterProviders
[
clusterPluginName
]
if
ok
{
storage
,
err
:=
clusterFn
()
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"constructing cluster plugin %s: %v"
,
clusterPluginName
,
err
)
}
certmagic
.
Default
.
Storage
=
storage
}
else
{
return
nil
,
fmt
.
Errorf
(
"unrecognized cluster plugin (was it included in the Caddy build?): %s"
,
clusterPluginName
)
}
if
err
:=
makeClusteringPlugin
();
err
!=
nil
{
return
nil
,
err
}
certCache
=
certmagic
.
NewCache
(
certmagic
.
CacheOptions
{
GetConfigForCert
:
func
(
cert
certmagic
.
Certificate
)
(
certmagic
.
Config
,
error
)
{
inst
.
StorageMu
.
Lock
()
inst
.
StorageMu
.
R
Lock
()
cfgMap
,
ok
:=
inst
.
Storage
[
configMapKey
]
.
(
map
[
string
]
*
Config
)
inst
.
StorageMu
.
Unlock
()
inst
.
StorageMu
.
R
Unlock
()
if
ok
{
for
hostname
,
cfg
:=
range
cfgMap
{
if
cfg
.
Manager
!=
nil
&&
hostname
==
cert
.
Names
[
0
]
{
...
...
@@ -135,8 +116,6 @@ func NewConfig(inst *caddy.Instance) (*Config, error) {
}
}
}
// returning Default not strictly necessary, since Default is used as template
// anyway; but this makes it clear that that's what we fall back to
return
certmagic
.
Default
,
nil
},
})
...
...
caddytls/setup.go
View file @
ad20323b
...
...
@@ -50,25 +50,8 @@ func init() {
// are specified by the user in the config file. All the automatic HTTPS
// stuff comes later outside of this function.
func
setupTLS
(
c
*
caddy
.
Controller
)
error
{
// set up the clustering plugin, if there is one (and there should always
// be one since this tls plugin requires it) -- this should be done exactly
// once, but we can't do it during init while plugins are still registering,
// so do it as soon as we run a setup)
if
atomic
.
CompareAndSwapInt32
(
&
clusterPluginSetup
,
0
,
1
)
{
clusterPluginName
:=
os
.
Getenv
(
"CADDY_CLUSTERING"
)
if
clusterPluginName
==
""
{
clusterPluginName
=
"file"
// name of default storage plugin
}
clusterFn
,
ok
:=
clusterProviders
[
clusterPluginName
]
if
ok
{
storage
,
err
:=
clusterFn
()
if
err
!=
nil
{
return
fmt
.
Errorf
(
"constructing cluster plugin %s: %v"
,
clusterPluginName
,
err
)
}
certmagic
.
Default
.
Storage
=
storage
}
else
{
return
fmt
.
Errorf
(
"unrecognized cluster plugin (was it included in the Caddy build?): %s"
,
clusterPluginName
)
}
if
err
:=
makeClusteringPlugin
();
err
!=
nil
{
return
err
}
configGetter
,
ok
:=
configGetters
[
c
.
ServerType
()]
...
...
@@ -464,6 +447,30 @@ func loadCertsInDir(cfg *Config, c *caddy.Controller, dir string) error {
})
}
func
makeClusteringPlugin
()
error
{
// set up the clustering plugin, if there is one (and there should always
// be one since this tls plugin requires it) -- this should be done exactly
// once, but we can't do it during init while plugins are still registering,
// so do it as soon as we run a setup)
if
atomic
.
CompareAndSwapInt32
(
&
clusterPluginSetup
,
0
,
1
)
{
clusterPluginName
:=
os
.
Getenv
(
"CADDY_CLUSTERING"
)
if
clusterPluginName
==
""
{
clusterPluginName
=
"file"
// name of default storage plugin
}
clusterFn
,
ok
:=
clusterProviders
[
clusterPluginName
]
if
ok
{
storage
,
err
:=
clusterFn
()
if
err
!=
nil
{
return
fmt
.
Errorf
(
"constructing cluster plugin %s: %v"
,
clusterPluginName
,
err
)
}
certmagic
.
Default
.
Storage
=
storage
}
else
{
return
fmt
.
Errorf
(
"unrecognized cluster plugin (was it included in the Caddy build?): %s"
,
clusterPluginName
)
}
}
return
nil
}
func
constructDefaultClusterPlugin
()
(
certmagic
.
Storage
,
error
)
{
return
&
certmagic
.
FileStorage
{
Path
:
caddy
.
AssetsPath
()},
nil
}
...
...
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