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
78341a3a
Commit
78341a3a
authored
Aug 18, 2016
by
Luna Duclos
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add error parameter to storage.SiteExists()
parent
fdc62d01
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
57 additions
and
17 deletions
+57
-17
caddytls/client.go
caddytls/client.go
+6
-1
caddytls/config.go
caddytls/config.go
+6
-1
caddytls/config_test.go
caddytls/config_test.go
+1
-1
caddytls/filestorage.go
caddytls/filestorage.go
+8
-5
caddytls/storage.go
caddytls/storage.go
+1
-1
caddytls/storagetest/memorystorage.go
caddytls/storagetest/memorystorage.go
+2
-2
caddytls/storagetest/storagetest.go
caddytls/storagetest/storagetest.go
+20
-3
caddytls/tls_test.go
caddytls/tls_test.go
+13
-3
No files found.
caddytls/client.go
View file @
78341a3a
...
...
@@ -287,7 +287,12 @@ func (c *ACMEClient) Revoke(name string) error {
return
err
}
if
!
storage
.
SiteExists
(
name
)
{
siteExists
,
err
:=
storage
.
SiteExists
(
name
)
if
err
!=
nil
{
return
err
}
if
!
siteExists
{
return
errors
.
New
(
"no certificate and key for "
+
name
)
}
...
...
caddytls/config.go
View file @
78341a3a
...
...
@@ -138,7 +138,12 @@ func (c *Config) obtainCertName(name string, allowPrompts bool) error {
return
err
}
if
!
c
.
Managed
||
!
HostQualifies
(
name
)
||
storage
.
SiteExists
(
name
)
{
siteExists
,
err
:=
storage
.
SiteExists
(
name
)
if
err
!=
nil
{
return
err
}
if
!
c
.
Managed
||
!
HostQualifies
(
name
)
||
siteExists
{
return
nil
}
...
...
caddytls/config_test.go
View file @
78341a3a
...
...
@@ -115,7 +115,7 @@ func TestStorageForCustomNil(t *testing.T) {
type
fakeStorage
string
func
(
s
fakeStorage
)
SiteExists
(
domain
string
)
bool
{
func
(
s
fakeStorage
)
SiteExists
(
domain
string
)
(
bool
,
error
)
{
panic
(
"no impl"
)
}
...
...
caddytls/filestorage.go
View file @
78341a3a
...
...
@@ -121,16 +121,19 @@ func (s FileStorage) readFile(file string) ([]byte, error) {
// SiteExists implements Storage.SiteExists by checking for the presence of
// cert and key files.
func
(
s
FileStorage
)
SiteExists
(
domain
string
)
bool
{
func
(
s
FileStorage
)
SiteExists
(
domain
string
)
(
bool
,
error
)
{
_
,
err
:=
os
.
Stat
(
s
.
siteCertFile
(
domain
))
if
err
!=
nil
{
return
false
if
os
.
IsNotExist
(
err
)
{
return
false
,
nil
}
else
if
err
!=
nil
{
return
false
,
err
}
_
,
err
=
os
.
Stat
(
s
.
siteKeyFile
(
domain
))
if
err
!=
nil
{
return
false
return
false
,
err
}
return
true
return
true
,
nil
}
// LoadSite implements Storage.LoadSite by loading it from disk. If it is not
...
...
caddytls/storage.go
View file @
78341a3a
...
...
@@ -39,7 +39,7 @@ type Storage interface {
// SiteExists returns true if this site exists in storage.
// Site data is considered present when StoreSite has been called
// successfully (without DeleteSite having been called, of course).
SiteExists
(
domain
string
)
bool
SiteExists
(
domain
string
)
(
bool
,
error
)
// LoadSite obtains the site data from storage for the given domain and
// returns it. If data for the domain does not exist, the
...
...
caddytls/storagetest/memorystorage.go
View file @
78341a3a
...
...
@@ -49,9 +49,9 @@ func NewInMemoryStorage() *InMemoryStorage {
}
// SiteExists implements caddytls.Storage.SiteExists in memory.
func
(
s
*
InMemoryStorage
)
SiteExists
(
domain
string
)
bool
{
func
(
s
*
InMemoryStorage
)
SiteExists
(
domain
string
)
(
bool
,
error
)
{
_
,
siteExists
:=
s
.
Sites
[
domain
]
return
siteExists
return
siteExists
,
nil
}
// Clear completely clears all values associated with this storage.
...
...
caddytls/storagetest/storagetest.go
View file @
78341a3a
...
...
@@ -113,7 +113,12 @@ func (s *StorageTest) TestSiteExists() error {
defer
s
.
runPostTest
()
// Should not exist at first
if
s
.
SiteExists
(
"example.com"
)
{
siteExists
,
err
:=
s
.
SiteExists
(
"example.com"
)
if
err
!=
nil
{
return
err
}
if
siteExists
{
return
errors
.
New
(
"Site should not exist"
)
}
...
...
@@ -121,7 +126,13 @@ func (s *StorageTest) TestSiteExists() error {
if
err
:=
s
.
StoreSite
(
"example.com"
,
simpleSiteData
);
err
!=
nil
{
return
err
}
if
!
s
.
SiteExists
(
"example.com"
)
{
siteExists
,
err
=
s
.
SiteExists
(
"example.com"
)
if
err
!=
nil
{
return
err
}
if
!
siteExists
{
return
errors
.
New
(
"Expected site to exist"
)
}
...
...
@@ -129,7 +140,13 @@ func (s *StorageTest) TestSiteExists() error {
if
err
:=
s
.
DeleteSite
(
"example.com"
);
err
!=
nil
{
return
err
}
if
s
.
SiteExists
(
"example.com"
)
{
siteExists
,
err
=
s
.
SiteExists
(
"example.com"
)
if
err
!=
nil
{
return
err
}
if
siteExists
{
return
errors
.
New
(
"Site should not exist after delete"
)
}
return
nil
...
...
caddytls/tls_test.go
View file @
78341a3a
...
...
@@ -135,11 +135,16 @@ func TestExistingCertAndKey(t *testing.T) {
domain
:=
"example.com"
if
storage
.
SiteExists
(
domain
)
{
siteExists
,
err
:=
storage
.
SiteExists
(
domain
)
if
err
!=
nil
{
t
.
Fatalf
(
"Could not determine whether site exists: %v"
,
err
)
}
if
siteExists
{
t
.
Errorf
(
"Did NOT expect %v to have existing cert or key, but it did"
,
domain
)
}
err
:
=
saveCertResource
(
storage
,
acme
.
CertificateResource
{
err
=
saveCertResource
(
storage
,
acme
.
CertificateResource
{
Domain
:
domain
,
PrivateKey
:
[]
byte
(
"key"
),
Certificate
:
[]
byte
(
"cert"
),
...
...
@@ -148,7 +153,12 @@ func TestExistingCertAndKey(t *testing.T) {
t
.
Fatalf
(
"Expected no error, got: %v"
,
err
)
}
if
!
storage
.
SiteExists
(
domain
)
{
siteExists
,
err
=
storage
.
SiteExists
(
domain
)
if
err
!=
nil
{
t
.
Fatalf
(
"Could not determine whether site exists: %v"
,
err
)
}
if
!
siteExists
{
t
.
Errorf
(
"Expected %v to have existing cert and key, but it did NOT"
,
domain
)
}
}
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