2020-08-11 14:35:54 +00:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import "encoding/xml"
|
|
|
|
|
2021-05-13 19:25:32 +00:00
|
|
|
// ListBucketsResponse - format for list buckets response.
|
2020-08-11 14:35:54 +00:00
|
|
|
type ListBucketsResponse struct {
|
|
|
|
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ ListAllMyBucketsResult" json:"-"`
|
|
|
|
|
|
|
|
Owner Owner
|
|
|
|
|
|
|
|
// Container for one or more buckets.
|
|
|
|
Buckets struct {
|
|
|
|
Buckets []Bucket `xml:"Bucket"`
|
|
|
|
} // Buckets are nested
|
|
|
|
}
|
|
|
|
|
2020-08-22 02:49:00 +00:00
|
|
|
// ListObjectsV2Response - format for list objects response.
|
|
|
|
type ListObjectsV2Response struct {
|
|
|
|
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ ListBucketResult" json:"-"`
|
|
|
|
|
|
|
|
Name string
|
|
|
|
Prefix string
|
|
|
|
StartAfter string `xml:"StartAfter,omitempty"`
|
|
|
|
// When response is truncated (the IsTruncated element value in the response
|
|
|
|
// is true), you can use the key name in this field as marker in the subsequent
|
|
|
|
// request to get next set of objects. Server lists objects in alphabetical
|
|
|
|
// order Note: This element is returned only if you have delimiter request parameter
|
|
|
|
// specified. If response does not include the NextMaker and it is truncated,
|
|
|
|
// you can use the value of the last Key in the response as the marker in the
|
|
|
|
// subsequent request to get the next set of object keys.
|
|
|
|
ContinuationToken string `xml:"ContinuationToken,omitempty"`
|
|
|
|
NextContinuationToken string `xml:"NextContinuationToken,omitempty"`
|
|
|
|
|
|
|
|
KeyCount int
|
|
|
|
MaxKeys int
|
|
|
|
Delimiter string
|
|
|
|
// A flag that indicates whether or not ListObjects returned all of the results
|
|
|
|
// that satisfied the search criteria.
|
|
|
|
IsTruncated bool
|
|
|
|
|
|
|
|
Contents []Object
|
|
|
|
CommonPrefixes []CommonPrefix
|
|
|
|
|
|
|
|
// Encoding type used to encode object keys in the response.
|
|
|
|
EncodingType string `xml:"EncodingType,omitempty"`
|
|
|
|
}
|
|
|
|
|
2021-05-13 19:25:32 +00:00
|
|
|
// Bucket container for bucket metadata.
|
2020-08-11 14:35:54 +00:00
|
|
|
type Bucket struct {
|
|
|
|
Name string
|
|
|
|
CreationDate string // time string of format "2006-01-02T15:04:05.000Z"
|
|
|
|
}
|
|
|
|
|
2021-05-13 19:25:32 +00:00
|
|
|
// Owner - bucket owner/principal.
|
2020-08-11 14:35:54 +00:00
|
|
|
type Owner struct {
|
|
|
|
ID string
|
|
|
|
DisplayName string
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListObjectsResponse - format for list objects response.
|
|
|
|
type ListObjectsResponse struct {
|
|
|
|
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ ListBucketResult" json:"-"`
|
|
|
|
|
|
|
|
Name string
|
|
|
|
Prefix string
|
|
|
|
Marker string
|
|
|
|
|
|
|
|
// When response is truncated (the IsTruncated element value in the response
|
|
|
|
// is true), you can use the key name in this field as marker in the subsequent
|
|
|
|
// request to get next set of objects. Server lists objects in alphabetical
|
|
|
|
// order Note: This element is returned only if you have delimiter request parameter
|
|
|
|
// specified. If response does not include the NextMaker and it is truncated,
|
|
|
|
// you can use the value of the last Key in the response as the marker in the
|
|
|
|
// subsequent request to get the next set of object keys.
|
|
|
|
NextMarker string `xml:"NextMarker,omitempty"`
|
|
|
|
|
|
|
|
MaxKeys int
|
|
|
|
Delimiter string
|
|
|
|
// A flag that indicates whether or not ListObjects returned all of the results
|
|
|
|
// that satisfied the search criteria.
|
|
|
|
IsTruncated bool
|
|
|
|
|
|
|
|
Contents []Object
|
|
|
|
CommonPrefixes []CommonPrefix
|
|
|
|
|
|
|
|
// Encoding type used to encode object keys in the response.
|
|
|
|
EncodingType string `xml:"EncodingType,omitempty"`
|
|
|
|
}
|
|
|
|
|
2021-05-13 19:25:32 +00:00
|
|
|
// CommonPrefix container for prefix response in ListObjectsResponse.
|
2020-08-11 14:35:54 +00:00
|
|
|
type CommonPrefix struct {
|
|
|
|
Prefix string
|
|
|
|
}
|
|
|
|
|
2021-05-13 19:25:32 +00:00
|
|
|
// Object container for object metadata.
|
2020-08-11 14:35:54 +00:00
|
|
|
type Object struct {
|
|
|
|
Key string
|
|
|
|
LastModified string // time string of format "2006-01-02T15:04:05.000Z"
|
2021-01-14 17:39:48 +00:00
|
|
|
ETag string `xml:"ETag,omitempty"`
|
2020-08-11 14:35:54 +00:00
|
|
|
Size int64
|
|
|
|
|
|
|
|
// Owner of the object.
|
|
|
|
Owner Owner
|
|
|
|
|
|
|
|
// The class of storage used to store the object.
|
2021-01-14 17:39:48 +00:00
|
|
|
StorageClass string `xml:"StorageClass,omitempty"`
|
2020-08-11 14:35:54 +00:00
|
|
|
}
|
|
|
|
|
2021-07-05 19:18:58 +00:00
|
|
|
// ObjectVersionResponse container for object version in the response of ListBucketObjectVersionsHandler.
|
|
|
|
type ObjectVersionResponse struct {
|
|
|
|
ETag string `xml:"ETag"`
|
|
|
|
IsLatest bool `xml:"IsLatest"`
|
|
|
|
Key string `xml:"Key"`
|
|
|
|
LastModified string `xml:"LastModified"`
|
|
|
|
Owner Owner `xml:"Owner"`
|
|
|
|
Size int64 `xml:"Size"`
|
|
|
|
StorageClass string `xml:"StorageClass,omitempty"` // is empty!!
|
|
|
|
VersionID string `xml:"VersionId"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteMarkerEntry container for deleted object's version in the response of ListBucketObjectVersionsHandler.
|
|
|
|
type DeleteMarkerEntry struct {
|
|
|
|
IsLatest bool `xml:"IsLatest"`
|
|
|
|
Key string `xml:"Key"`
|
|
|
|
LastModified string `xml:"LastModified"`
|
|
|
|
Owner Owner `xml:"Owner"`
|
|
|
|
VersionID string `xml:"VersionId"`
|
|
|
|
}
|
|
|
|
|
2020-08-11 14:35:54 +00:00
|
|
|
// StringMap is a map[string]string.
|
|
|
|
type StringMap map[string]string
|
2020-08-19 11:53:17 +00:00
|
|
|
|
|
|
|
// LocationResponse - format for location response.
|
|
|
|
type LocationResponse struct {
|
|
|
|
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ LocationConstraint" json:"-"`
|
|
|
|
Location string `xml:",chardata"`
|
|
|
|
}
|
2020-08-19 23:34:47 +00:00
|
|
|
|
2021-05-13 19:25:32 +00:00
|
|
|
// CopyObjectResponse container returns ETag and LastModified of the successfully copied object.
|
2020-08-19 23:35:51 +00:00
|
|
|
type CopyObjectResponse struct {
|
|
|
|
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ CopyObjectResult" json:"-"`
|
|
|
|
LastModified string // time string of format "2006-01-02T15:04:05.000Z"
|
|
|
|
ETag string // md5sum of the copied object.
|
|
|
|
}
|
|
|
|
|
2021-07-05 19:18:58 +00:00
|
|
|
// ListObjectsVersionsResponse is a response of ListBucketObjectVersionsHandler.
|
|
|
|
type ListObjectsVersionsResponse struct {
|
|
|
|
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ ListVersionsResult" json:"-"`
|
|
|
|
EncodingType string `xml:"EncodingType,omitempty"`
|
|
|
|
Name string `xml:"Name"`
|
|
|
|
IsTruncated bool `xml:"IsTruncated"`
|
|
|
|
KeyMarker string `xml:"KeyMarker"`
|
|
|
|
NextKeyMarker string `xml:"NextKeyMarker,omitempty"`
|
|
|
|
NextVersionIDMarker string `xml:"NextVersionIdMarker,omitempty"`
|
|
|
|
VersionIDMarker string `xml:"VersionIdMarker"`
|
|
|
|
DeleteMarker []DeleteMarkerEntry `xml:"DeleteMarker"`
|
|
|
|
Version []ObjectVersionResponse `xml:"Version"`
|
|
|
|
CommonPrefixes []CommonPrefix `xml:"CommonPrefixes"`
|
|
|
|
}
|
|
|
|
|
2020-08-19 23:34:47 +00:00
|
|
|
// MarshalXML - StringMap marshals into XML.
|
|
|
|
func (s StringMap) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
|
|
|
tokens := []xml.Token{start}
|
|
|
|
|
|
|
|
for key, value := range s {
|
|
|
|
t := xml.StartElement{}
|
|
|
|
t.Name = xml.Name{
|
|
|
|
Space: "",
|
|
|
|
Local: key,
|
|
|
|
}
|
|
|
|
tokens = append(tokens, t, xml.CharData(value), xml.EndElement{Name: t.Name})
|
|
|
|
}
|
|
|
|
|
|
|
|
tokens = append(tokens, xml.EndElement{
|
|
|
|
Name: start.Name,
|
|
|
|
})
|
|
|
|
|
|
|
|
for _, t := range tokens {
|
|
|
|
if err := e.EncodeToken(t); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// flush to ensure tokens are written
|
|
|
|
return e.Flush()
|
|
|
|
}
|