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

@@ -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