mirror of https://github.com/docker/docs.git
Merge pull request #10 from docker/server_version_rename
renaming server/version to server/storage
This commit is contained in:
commit
33c1738e56
|
@ -19,7 +19,7 @@ import (
|
||||||
|
|
||||||
"github.com/docker/notary/config"
|
"github.com/docker/notary/config"
|
||||||
"github.com/docker/notary/server"
|
"github.com/docker/notary/server"
|
||||||
"github.com/docker/notary/server/version"
|
"github.com/docker/notary/server/storage"
|
||||||
"github.com/docker/notary/signer"
|
"github.com/docker/notary/signer"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ func main() {
|
||||||
logrus.Fatal("Error starting DB driver: ", err.Error())
|
logrus.Fatal("Error starting DB driver: ", err.Error())
|
||||||
return // not strictly needed but let's be explicit
|
return // not strictly needed but let's be explicit
|
||||||
}
|
}
|
||||||
ctx = context.WithValue(ctx, "versionStore", version.NewVersionDB(db))
|
ctx = context.WithValue(ctx, "versionStore", storage.NewMySQLStorage(db))
|
||||||
for {
|
for {
|
||||||
logrus.Info("[Notary Server] Starting Server")
|
logrus.Info("[Notary Server] Starting Server")
|
||||||
childCtx, cancel := context.WithCancel(ctx)
|
childCtx, cancel := context.WithCancel(ctx)
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
"github.com/docker/notary/errors"
|
"github.com/docker/notary/errors"
|
||||||
"github.com/docker/notary/server/version"
|
"github.com/docker/notary/server/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MainHandler is the default handler for the server
|
// MainHandler is the default handler for the server
|
||||||
|
@ -44,7 +44,7 @@ func UpdateHandler(ctx context.Context, w http.ResponseWriter, r *http.Request)
|
||||||
Err: fmt.Errorf("Version store is nil"),
|
Err: fmt.Errorf("Version store is nil"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
store, ok := s.(*version.VersionDB)
|
store, ok := s.(*storage.MySQLStorage)
|
||||||
if !ok {
|
if !ok {
|
||||||
return &errors.HTTPError{
|
return &errors.HTTPError{
|
||||||
HTTPStatus: http.StatusInternalServerError,
|
HTTPStatus: http.StatusInternalServerError,
|
||||||
|
@ -87,7 +87,7 @@ func UpdateHandler(ctx context.Context, w http.ResponseWriter, r *http.Request)
|
||||||
// GetHandler accepts urls in the form /<imagename>/<tuf file>.json
|
// GetHandler accepts urls in the form /<imagename>/<tuf file>.json
|
||||||
func GetHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) *errors.HTTPError {
|
func GetHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) *errors.HTTPError {
|
||||||
s := ctx.Value("versionStore")
|
s := ctx.Value("versionStore")
|
||||||
store, ok := s.(*version.VersionDB)
|
store, ok := s.(*storage.MySQLStorage)
|
||||||
if !ok {
|
if !ok {
|
||||||
return &errors.HTTPError{
|
return &errors.HTTPError{
|
||||||
HTTPStatus: http.StatusInternalServerError,
|
HTTPStatus: http.StatusInternalServerError,
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
// version implementes a versioned store for TUF metadata
|
package storage
|
||||||
package version
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// VersionDB implements a versioned store using a relational database.
|
// MySQLStorage implements a versioned store using a relational database.
|
||||||
// The database table must look like:
|
// The database table must look like:
|
||||||
// CREATE TABLE `tuf_files` (
|
// CREATE TABLE `tuf_files` (
|
||||||
// `id` INT AUTO_INCREMENT,
|
// `id` INT AUTO_INCREMENT,
|
||||||
|
@ -17,19 +16,19 @@ import (
|
||||||
// PRIMARY KEY (`id`)
|
// PRIMARY KEY (`id`)
|
||||||
// UNIQUE INDEX (`qdn`, `role`, `version`)
|
// UNIQUE INDEX (`qdn`, `role`, `version`)
|
||||||
// ) DEFAULT CHARSET=utf8;
|
// ) DEFAULT CHARSET=utf8;
|
||||||
type VersionDB struct {
|
type MySQLStorage struct {
|
||||||
sql.DB
|
sql.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewVersionDB(db *sql.DB) *VersionDB {
|
func NewMySQLStorage(db *sql.DB) *MySQLStorage {
|
||||||
return &VersionDB{
|
return &MySQLStorage{
|
||||||
DB: *db,
|
DB: *db,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update multiple TUF records in a single transaction.
|
// Update multiple TUF records in a single transaction.
|
||||||
// Always insert a new row. The unique constraint will ensure there is only ever
|
// Always insert a new row. The unique constraint will ensure there is only ever
|
||||||
func (vdb *VersionDB) UpdateCurrent(qdn, role string, version int, data []byte) error {
|
func (vdb *MySQLStorage) UpdateCurrent(qdn, role string, version int, data []byte) error {
|
||||||
checkStmt := "SELECT count(*) FROM `tuf_files` WHERE `qdn`=? AND `role`=? AND `version`>=?;"
|
checkStmt := "SELECT count(*) FROM `tuf_files` WHERE `qdn`=? AND `role`=? AND `version`>=?;"
|
||||||
insertStmt := "INSERT INTO `tuf_files` (`qdn`, `role`, `version`, `data`) VALUES (?,?,?,?) ;"
|
insertStmt := "INSERT INTO `tuf_files` (`qdn`, `role`, `version`, `data`) VALUES (?,?,?,?) ;"
|
||||||
|
|
||||||
|
@ -55,7 +54,7 @@ func (vdb *VersionDB) UpdateCurrent(qdn, role string, version int, data []byte)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a specific TUF record
|
// Get a specific TUF record
|
||||||
func (vdb *VersionDB) GetCurrent(qdn, tufRole string) (data []byte, err error) {
|
func (vdb *MySQLStorage) GetCurrent(qdn, tufRole string) (data []byte, err error) {
|
||||||
stmt := "SELECT `data` FROM `tuf_files` WHERE `qdn`=? AND `role`=? ORDER BY `version` DESC LIMIT 1;"
|
stmt := "SELECT `data` FROM `tuf_files` WHERE `qdn`=? AND `role`=? ORDER BY `version` DESC LIMIT 1;"
|
||||||
rows, err := vdb.Query(stmt, qdn, tufRole) // this should be a QueryRow()
|
rows, err := vdb.Query(stmt, qdn, tufRole) // this should be a QueryRow()
|
||||||
if err != nil {
|
if err != nil {
|
Loading…
Reference in New Issue