Rename and cleanup the dbMap wraper interface

This commit is contained in:
Roland Shoemaker 2015-10-16 15:17:51 -07:00
parent 980d87aa14
commit 02cd06ad0b
2 changed files with 6 additions and 8 deletions

View File

@ -55,19 +55,18 @@ serialNumber field, since we will always query on it.
*/ */
type DBSource struct { type DBSource struct {
dbMap dbMapInterface dbMap dbSelector
caKeyHash []byte caKeyHash []byte
log *blog.AuditLogger log *blog.AuditLogger
} }
type dbMapInterface interface { type dbSelector interface {
SelectOne(holder interface{}, query string, args ...interface{}) error SelectOne(holder interface{}, query string, args ...interface{}) error
Insert(list ...interface{}) error
} }
// NewSourceFromDatabase produces a DBSource representing the binding of a // NewSourceFromDatabase produces a DBSource representing the binding of a
// given DB schema to a CA key. // given DB schema to a CA key.
func NewSourceFromDatabase(dbMap dbMapInterface, caKeyHash []byte, log *blog.AuditLogger) (src *DBSource, err error) { func NewSourceFromDatabase(dbMap dbSelector, caKeyHash []byte, log *blog.AuditLogger) (src *DBSource, err error) {
src = &DBSource{dbMap: dbMap, caKeyHash: caKeyHash, log: log} src = &DBSource{dbMap: dbMap, caKeyHash: caKeyHash, log: log}
return return
} }
@ -121,7 +120,7 @@ func (src *DBSource) Response(req *ocsp.Request) ([]byte, bool) {
return response, true return response, true
} }
func makeDBSource(dbMap dbMapInterface, issuerCert string, log *blog.AuditLogger) (*DBSource, error) { func makeDBSource(dbMap dbSelector, issuerCert string, log *blog.AuditLogger) (*DBSource, error) {
// Load the CA's key so we can store its SubjectKey in the DB // Load the CA's key so we can store its SubjectKey in the DB
caCertDER, err := cmd.LoadCert(issuerCert) caCertDER, err := cmd.LoadCert(issuerCert)
if err != nil { if err != nil {

View File

@ -12,7 +12,6 @@ import (
cfocsp "github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/cloudflare/cfssl/ocsp" cfocsp "github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/cloudflare/cfssl/ocsp"
"github.com/letsencrypt/boulder/Godeps/_workspace/src/golang.org/x/crypto/ocsp" "github.com/letsencrypt/boulder/Godeps/_workspace/src/golang.org/x/crypto/ocsp"
"github.com/letsencrypt/boulder/cmd"
"github.com/letsencrypt/boulder/mocks" "github.com/letsencrypt/boulder/mocks"
"github.com/letsencrypt/boulder/sa" "github.com/letsencrypt/boulder/sa"
@ -67,7 +66,7 @@ func TestHandler(t *testing.T) {
func TestDBHandler(t *testing.T) { func TestDBHandler(t *testing.T) {
dbMap, err := sa.NewDbMap("mysql+tcp://boulder@localhost:3306/boulder_sa_test") dbMap, err := sa.NewDbMap("mysql+tcp://boulder@localhost:3306/boulder_sa_test")
cmd.FailOnError(err, "Could not connect to database") test.AssertNotError(t, err, "Could not connect to database")
src, err := makeDBSource(dbMap, "./testdata/test-ca.der.pem", blog.GetAuditLogger()) src, err := makeDBSource(dbMap, "./testdata/test-ca.der.pem", blog.GetAuditLogger())
if err != nil { if err != nil {
t.Fatalf("makeDBSource: %s", err) t.Fatalf("makeDBSource: %s", err)
@ -83,7 +82,7 @@ func TestDBHandler(t *testing.T) {
OCSPLastUpdated: time.Now(), OCSPLastUpdated: time.Now(),
OCSPResponse: resp, OCSPResponse: resp,
} }
err = src.dbMap.Insert(status) err = dbMap.Insert(status)
if err != nil { if err != nil {
t.Fatalf("unable to insert response: %s", err) t.Fatalf("unable to insert response: %s", err)
} }