mirror of https://github.com/docker/docs.git
Merge pull request #98 from docker/timestamp_errors
fixing timestamp errors on list
This commit is contained in:
commit
9b604d0a6c
|
|
@ -11,5 +11,9 @@
|
|||
},
|
||||
"logging": {
|
||||
"level": 5
|
||||
},
|
||||
"storage": {
|
||||
"backend": "mysql",
|
||||
"db_url": "root:@tcp(localhost:3306)/dockercondemo"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue