Add download version object on download api (#423)

This commit is contained in:
Cesar N
2020-11-19 15:04:13 -08:00
committed by GitHub
parent 37ff8bb60d
commit a20c6dc907
8 changed files with 87 additions and 22 deletions

View File

@@ -546,6 +546,12 @@ func init() {
"name": "prefix",
"in": "query",
"required": true
},
{
"type": "string",
"name": "version_id",
"in": "query",
"required": true
}
],
"responses": {
@@ -5406,6 +5412,12 @@ func init() {
"name": "prefix",
"in": "query",
"required": true
},
{
"type": "string",
"name": "version_id",
"in": "query",
"required": true
}
],
"responses": {

View File

@@ -58,6 +58,11 @@ type DownloadObjectParams struct {
In: query
*/
Prefix string
/*
Required: true
In: query
*/
VersionID string
}
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
@@ -81,6 +86,11 @@ func (o *DownloadObjectParams) BindRequest(r *http.Request, route *middleware.Ma
res = append(res, err)
}
qVersionID, qhkVersionID, _ := qs.GetOK("version_id")
if err := o.bindVersionID(qVersionID, qhkVersionID, route.Formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
@@ -122,3 +132,24 @@ func (o *DownloadObjectParams) bindPrefix(rawData []string, hasKey bool, formats
return nil
}
// bindVersionID binds and validates parameter VersionID from query.
func (o *DownloadObjectParams) bindVersionID(rawData []string, hasKey bool, formats strfmt.Registry) error {
if !hasKey {
return errors.Required("version_id", "query", rawData)
}
var raw string
if len(rawData) > 0 {
raw = rawData[len(rawData)-1]
}
// Required: true
// AllowEmptyValue: false
if err := validate.RequiredString("version_id", "query", raw); err != nil {
return err
}
o.VersionID = raw
return nil
}

View File

@@ -33,7 +33,8 @@ import (
type DownloadObjectURL struct {
BucketName string
Prefix string
Prefix string
VersionID string
_basePath string
// avoid unkeyed usage
@@ -81,6 +82,11 @@ func (o *DownloadObjectURL) Build() (*url.URL, error) {
qs.Set("prefix", prefixQ)
}
versionIDQ := o.VersionID
if versionIDQ != "" {
qs.Set("version_id", versionIDQ)
}
_result.RawQuery = qs.Encode()
return &_result, nil

View File

@@ -221,18 +221,17 @@ func getDownloadObjectResponse(session *models.Principal, params user_api.Downlo
// create a mc S3Client interface implementation
// defining the client to be used
mcClient := mcClient{client: s3Client}
object, err := downloadObject(ctx, mcClient)
object, err := downloadObject(ctx, mcClient, params.VersionID)
if err != nil {
return nil, prepareError(err)
}
return object, nil
}
func downloadObject(ctx context.Context, client MCClient) (io.ReadCloser, error) {
// TODO: handle version
func downloadObject(ctx context.Context, client MCClient, versionID string) (io.ReadCloser, error) {
// TODO: handle encripted files
var reader io.ReadCloser
reader, pErr := client.get(ctx, mc.GetOptions{})
reader, pErr := client.get(ctx, mc.GetOptions{VersionID: versionID})
if pErr != nil {
return nil, pErr.Cause
}
@@ -285,7 +284,7 @@ func deleteMultipleObjects(ctx context.Context, client MCClient, recursive bool)
isRemoveBucket := false
isIncomplete := false
isBypass := false
listOpts := mc.ListOptions{IsRecursive: recursive, IsIncomplete: isIncomplete, ShowDir: mc.DirNone}
listOpts := mc.ListOptions{Recursive: recursive, Incomplete: isIncomplete, ShowDir: mc.DirNone}
// TODO: support older Versions
contentCh := make(chan *mc.ClientContent, 1)