diff --git a/cmd/notary-server/dev-config.json b/cmd/notary-server/dev-config.json index e5680ab6df..b00d95f2be 100644 --- a/cmd/notary-server/dev-config.json +++ b/cmd/notary-server/dev-config.json @@ -11,5 +11,9 @@ }, "logging": { "level": 5 + }, + "storage": { + "backend": "mysql", + "db_url": "root:@tcp(localhost:3306)/dockercondemo" } } diff --git a/notarymysql/initial.sql b/notarymysql/initial.sql index 6f6d7fa441..52c7a8c497 100644 --- a/notarymysql/initial.sql +++ b/notarymysql/initial.sql @@ -12,7 +12,7 @@ CREATE TABLE `tuf_files` ( DROP TABLE IF EXISTS `timestamp_keys`; CREATE TABLE `timestamp_keys` ( `gun` varchar(255) NOT NULL, - `cipher` int(11) NOT NULL, + `cipher` varchar(50) NOT NULL, `public` blob NOT NULL, PRIMARY KEY (`gun`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/server/handlers/default.go b/server/handlers/default.go index 75e48d6744..0452d7b198 100644 --- a/server/handlers/default.go +++ b/server/handlers/default.go @@ -142,10 +142,12 @@ func GetTimestampHandler(ctx context.Context, w http.ResponseWriter, r *http.Req out, err := timestamp.GetOrCreateTimestamp(gun, store, cryptoService) if err != nil { - if _, ok := err.(*storage.ErrNoKey); ok { + switch err.(type) { + case *storage.ErrNoKey, *storage.ErrNotFound: return errors.ErrMetadataNotFound.WithDetail(nil) + default: + return errors.ErrUnknown.WithDetail(err) } - return errors.ErrUnknown.WithDetail(err) } logrus.Debug("Writing data") diff --git a/server/storage/database.go b/server/storage/database.go index 4fa40a45ac..9748f099fb 100644 --- a/server/storage/database.go +++ b/server/storage/database.go @@ -147,6 +147,7 @@ func (db *MySQLStorage) Delete(gun string) error { // GetTimestampKey returns the timestamps Public Key data func (db *MySQLStorage) GetTimestampKey(gun string) (algorithm data.KeyAlgorithm, public []byte, err error) { + logrus.Debug("retrieving timestamp key for ", gun) stmt := "SELECT `cipher`, `public` FROM `timestamp_keys` WHERE `gun`=?;" row := db.QueryRow(stmt, gun) @@ -164,6 +165,7 @@ func (db *MySQLStorage) GetTimestampKey(gun string) (algorithm data.KeyAlgorithm // SetTimestampKey attempts to write a TimeStamp key and returns an error if it already exists func (db *MySQLStorage) SetTimestampKey(gun string, algorithm data.KeyAlgorithm, public []byte) error { stmt := "INSERT INTO `timestamp_keys` (`gun`, `cipher`, `public`) VALUES (?,?,?);" + logrus.Debug("Inserting timestamp key for ", gun) _, err := db.Exec(stmt, gun, string(algorithm), public) if err != nil { if err, ok := err.(*mysql.MySQLError); ok && err.Number == 1022 { diff --git a/server/timestamp/timestamp.go b/server/timestamp/timestamp.go index d2ceb257b6..584379ac07 100644 --- a/server/timestamp/timestamp.go +++ b/server/timestamp/timestamp.go @@ -29,6 +29,7 @@ func GetOrCreateTimestampKey(gun string, store storage.MetaStore, crypto signed. if err != nil { return nil, err } + logrus.Debug("Creating new timestamp key for ", gun, ". With algo: ", key.Algorithm()) err = store.SetTimestampKey(gun, key.Algorithm(), key.Public()) if err == nil { return key, nil @@ -57,11 +58,10 @@ func GetOrCreateTimestamp(gun string, store storage.MetaStore, cryptoService sig d, err := store.GetCurrent(gun, "timestamp") if err != nil { if _, ok := err.(*storage.ErrNotFound); !ok { - // If we received an ErrNotFound, we're going to - // generate the first timestamp, any other error - // should be returned here + logrus.Error("error retrieving timestamp: ", err.Error()) return nil, err } + logrus.Debug("No timestamp found, will proceed to create first timestamp") } ts := &data.SignedTimestamp{} if d != nil {