mirror of https://github.com/docker/docs.git
				
				
				
			renaming server/version to server/storage. version was a bad name I picked late at night
This commit is contained in:
		
							parent
							
								
									6625f1fc86
								
							
						
					
					
						commit
						73f9935ea1
					
				|  | @ -19,7 +19,7 @@ import ( | |||
| 
 | ||||
| 	"github.com/docker/notary/config" | ||||
| 	"github.com/docker/notary/server" | ||||
| 	"github.com/docker/notary/server/version" | ||||
| 	"github.com/docker/notary/server/storage" | ||||
| 	"github.com/docker/notary/signer" | ||||
| ) | ||||
| 
 | ||||
|  | @ -77,7 +77,7 @@ func main() { | |||
| 		logrus.Fatal("Error starting DB driver: ", err.Error()) | ||||
| 		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 { | ||||
| 		logrus.Info("[Notary Server] Starting Server") | ||||
| 		childCtx, cancel := context.WithCancel(ctx) | ||||
|  |  | |||
|  | @ -12,7 +12,7 @@ import ( | |||
| 	"golang.org/x/net/context" | ||||
| 
 | ||||
| 	"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
 | ||||
|  | @ -44,7 +44,7 @@ func UpdateHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) | |||
| 			Err:        fmt.Errorf("Version store is nil"), | ||||
| 		} | ||||
| 	} | ||||
| 	store, ok := s.(*version.VersionDB) | ||||
| 	store, ok := s.(*storage.MySQLStorage) | ||||
| 	if !ok { | ||||
| 		return &errors.HTTPError{ | ||||
| 			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
 | ||||
| func GetHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) *errors.HTTPError { | ||||
| 	s := ctx.Value("versionStore") | ||||
| 	store, ok := s.(*version.VersionDB) | ||||
| 	store, ok := s.(*storage.MySQLStorage) | ||||
| 	if !ok { | ||||
| 		return &errors.HTTPError{ | ||||
| 			HTTPStatus: http.StatusInternalServerError, | ||||
|  |  | |||
|  | @ -1,12 +1,11 @@ | |||
| // version implementes a versioned store for TUF metadata
 | ||||
| package version | ||||
| package storage | ||||
| 
 | ||||
| import ( | ||||
| 	"database/sql" | ||||
| 	"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:
 | ||||
| // CREATE TABLE `tuf_files` (
 | ||||
| //   `id` INT AUTO_INCREMENT,
 | ||||
|  | @ -17,19 +16,19 @@ import ( | |||
| //   PRIMARY KEY (`id`)
 | ||||
| //   UNIQUE INDEX (`qdn`, `role`, `version`)
 | ||||
| // ) DEFAULT CHARSET=utf8;
 | ||||
| type VersionDB struct { | ||||
| type MySQLStorage struct { | ||||
| 	sql.DB | ||||
| } | ||||
| 
 | ||||
| func NewVersionDB(db *sql.DB) *VersionDB { | ||||
| 	return &VersionDB{ | ||||
| func NewMySQLStorage(db *sql.DB) *MySQLStorage { | ||||
| 	return &MySQLStorage{ | ||||
| 		DB: *db, | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| // Update multiple TUF records in a single transaction.
 | ||||
| // 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`>=?;" | ||||
| 	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
 | ||||
| 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;" | ||||
| 	rows, err := vdb.Query(stmt, qdn, tufRole) // this should be a QueryRow()
 | ||||
| 	if err != nil { | ||||
		Loading…
	
		Reference in New Issue