updating use of indices and queries

Signed-off-by: David Lawrence <david.lawrence@docker.com> (github: endophage)
This commit is contained in:
David Lawrence
2016-03-24 12:33:29 -07:00
committed by Riyaz Faizullabhoy
parent 30f356f940
commit b196a803e2
5 changed files with 126 additions and 89 deletions

View File

@@ -16,6 +16,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"github.com/dancannon/gorethink"
"github.com/docker/distribution/health"
"github.com/docker/notary"
"github.com/docker/notary/cryptoservice"
@@ -23,6 +24,7 @@ import (
"github.com/docker/notary/signer"
"github.com/docker/notary/signer/api"
"github.com/docker/notary/signer/keydbstore"
"github.com/docker/notary/storage/rethinkdb"
"github.com/docker/notary/trustmanager"
"github.com/docker/notary/tuf/data"
"github.com/docker/notary/utils"
@@ -42,10 +44,11 @@ const (
)
var (
debug bool
logFormat string
configFile string
mainViper = viper.New()
debug bool
logFormat string
configFile string
mainViper = viper.New()
doBootstrap bool
)
func init() {
@@ -54,6 +57,7 @@ func init() {
flag.StringVar(&configFile, "config", "", "Path to configuration file")
flag.BoolVar(&debug, "debug", false, "show the version and exit")
flag.StringVar(&logFormat, "logf", "json", "Set the format of the logs. Only 'json' and 'logfmt' are supported at the moment.")
flag.BoolVar(&doBootstrap, "bootstrap", false, "Do any necessary setup of configured backend storage services")
// this needs to be in init so that _ALL_ logs are in the correct format
if logFormat == jsonLogFormat {
@@ -100,9 +104,9 @@ func setUpCryptoservices(configuration *viper.Viper, allowedBackends []string) (
return nil, fmt.Errorf("must provide a default alias for the key DB")
}
logrus.Debug("Default Alias: ", defaultAlias)
s, err := keydbstore.NewKeyRethinkDBStore(passphraseRetriever, defaultAlias, sess)
s := keydbstore.NewRethinkDBKeyStore(passphraseRetriever, defaultAlias, sess)
keyStore = s
hRegister("DB operational", s.CheckHealth, time.Second*60)
health.RegisterPeriodicFunc("DB operational", s.CheckHealth, time.Minute)
}
case notary.MySQLBackend, notary.SQLiteBackend:
@@ -128,10 +132,18 @@ func setUpCryptoservices(configuration *viper.Viper, allowedBackends []string) (
}
health.RegisterPeriodicFunc(
"DB operational", dbStore.HealthCheck, time.Second*60)
"DB operational", dbStore.HealthCheck, time.Minute)
keyStore = dbStore
}
if doBootstrap {
err := bootstrap(keyStore)
if err != nil {
logrus.Fatal(err.Error())
}
os.Exit(0)
}
cryptoService := cryptoservice.NewCryptoService(keyStore)
cryptoServices := make(signer.CryptoServiceIndex)
cryptoServices[data.ED25519Key] = cryptoService

View File

@@ -12,7 +12,6 @@ import (
"github.com/docker/notary/signer"
"github.com/docker/notary/signer/keydbstore"
"github.com/docker/notary/tuf/data"
"github.com/docker/notary/utils"
"github.com/jinzhu/gorm"
_ "github.com/mattn/go-sqlite3"
"github.com/spf13/viper"
@@ -106,8 +105,8 @@ func TestSetupCryptoServicesDBStoreNoDefaultAlias(t *testing.T) {
_, err = setUpCryptoservices(
configure(fmt.Sprintf(
`{"storage": {"backend": "%s", "db_url": "%s"}}`,
notary.SqliteBackend, tmpFile.Name())),
[]string{notary.SqliteBackend})
notary.SQLiteBackend, tmpFile.Name())),
[]string{notary.SQLiteBackend})
require.Error(t, err)
require.Contains(t, err.Error(), "must provide a default alias for the key DB")
}
@@ -137,8 +136,8 @@ func TestSetupCryptoServicesDBStoreSuccess(t *testing.T) {
configure(fmt.Sprintf(
`{"storage": {"backend": "%s", "db_url": "%s"},
"default_alias": "timestamp"}`,
notary.SqliteBackend, tmpFile.Name())),
[]string{notary.SqliteBackend})
notary.SQLiteBackend, tmpFile.Name())),
[]string{notary.SQLiteBackend})
require.NoError(t, err)
require.Len(t, cryptoServices, 2)
@@ -167,9 +166,9 @@ func TestSetupCryptoServicesMemoryStore(t *testing.T) {
config := configure(fmt.Sprintf(`{"storage": {"backend": "%s"}}`,
notary.MemoryBackend))
cryptoServices, err := setUpCryptoservices(config,
[]string{notary.SqliteBackend, notary.MemoryBackend})
[]string{notary.SQLiteBackend, notary.MemoryBackend})
require.NoError(t, err)
require.Len(t, cryptoServices, 2)
assert.Len(t, cryptoServices, 2)
edService, ok := cryptoServices[data.ED25519Key]
require.True(t, ok)