mirror of
https://github.com/versity/versitygw.git
synced 2026-08-19 05:36:19 +00:00
test: website - initial tests
This commit is contained in:
@@ -39,7 +39,7 @@ func NewCreateBucketCommand(s3Command *S3RequestBuilder, locationConstraint stri
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error marshalling XML: %w", err)
|
||||
}
|
||||
s3Command.Config.Payload = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + string(xmlData)
|
||||
s3Command.Config.Payload = xml.Header + string(xmlData)
|
||||
}
|
||||
return command, nil
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ func NewPutBucketCORSCommand(command *S3RequestBuilder, ruleStrings []string) (*
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error marshalling XML: %w", err)
|
||||
}
|
||||
command.Config.Payload = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + string(xmlData)
|
||||
command.Config.Payload = xml.Header + string(xmlData)
|
||||
return command, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type ErrorDocument struct {
|
||||
Key string `xml:"Key,omitempty" json:"key,omitempty"`
|
||||
}
|
||||
|
||||
type IndexDocument struct {
|
||||
Suffix string `xml:"Suffix,omitempty" json:"suffix,omitempty"`
|
||||
}
|
||||
|
||||
type RedirectAllRequestsTo struct {
|
||||
HostName string `xml:"HostName,omitempty" json:"hostName,omitempty"`
|
||||
Protocol string `xml:"Protocol,omitempty" json:"protocol,omitempty"`
|
||||
}
|
||||
|
||||
type Condition struct {
|
||||
HttpErrorCodeReturnedEquals string `xml:"HttpErrorCodeReturnedEquals,omitempty" json:"httpErrorCodeReturnedEquals,omitempty"`
|
||||
KeyPrefixEquals string `xml:"KeyPrefixEquals,omitempty" json:"keyPrefixEquals,omitempty"`
|
||||
}
|
||||
|
||||
type Redirect struct {
|
||||
HostName string `xml:"HostName,omitempty" json:"hostName,omitempty"`
|
||||
HttpRedirectCode string `xml:"HttpRedirectCode,omitempty" json:"httpRedirectCode,omitempty"`
|
||||
Protocol string `xml:"Protocol,omitempty" json:"protocol,omitempty"`
|
||||
ReplaceKeyPrefixWith string `xml:"ReplaceKeyPrefixWith,omitempty" json:"replaceKeyPrefixWith,omitempty"`
|
||||
ReplaceKeyWith string `xml:"ReplaceKeyWith,omitempty" json:"replaceKeyWith,omitempty"`
|
||||
}
|
||||
|
||||
type RoutingRule struct {
|
||||
Condition *Condition `xml:"Condition,omitempty" json:"condition,omitempty"`
|
||||
Redirect *Redirect `xml:"Redirect,omitempty" json:"redirect,omitempty"`
|
||||
}
|
||||
|
||||
type RoutingRules struct {
|
||||
RoutingRule []RoutingRule `xml:"RoutingRule,omitempty" json:"routingRule,omitempty"`
|
||||
}
|
||||
|
||||
type WebsiteConfiguration struct {
|
||||
XMLName xml.Name `xml:"WebsiteConfiguration,omitempty" json:"-"`
|
||||
XMLNamespace string `xml:"xmlns,attr" json:"xmlNamespace,omitempty"`
|
||||
ErrorDocument *ErrorDocument `xml:"ErrorDocument,omitempty" json:"errorDocument,omitempty"`
|
||||
IndexDocument *IndexDocument `xml:"IndexDocument,omitempty" json:"indexDocument,omitempty"`
|
||||
RedirectAllRequestsTo *RedirectAllRequestsTo `xml:"RedirectAllRequestsTo,omitempty" json:"redirectAllRequestsTo,omitempty"`
|
||||
RoutingRules *RoutingRules `xml:"RoutingRules,omitempty" json:"routingRules,omitempty"`
|
||||
}
|
||||
|
||||
func NewPutBucketWebsiteCommand(command *S3RequestBuilder, websiteString string) (*S3RequestBuilder, error) {
|
||||
command.Config.Method = "PUT"
|
||||
command.Config.Query = "website"
|
||||
xmlData, err := convertWebsiteJsonToXml(websiteString)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error assembling website configuration: %w", err)
|
||||
}
|
||||
command.Config.Payload = xml.Header + string(xmlData)
|
||||
return command, nil
|
||||
}
|
||||
|
||||
func convertWebsiteJsonToXml(websiteString string) ([]byte, error) {
|
||||
websiteConfiguration := WebsiteConfiguration{
|
||||
XMLNamespace: "https://s3.amazonaws.com/doc/2006-03-01/",
|
||||
}
|
||||
if err := json.Unmarshal([]byte(websiteString), &websiteConfiguration); err != nil {
|
||||
return nil, fmt.Errorf("error unmarshaling website string: %w", err)
|
||||
}
|
||||
xmlData, err := xml.Marshal(websiteConfiguration)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error marshalling XML: %w", err)
|
||||
}
|
||||
return xmlData, nil
|
||||
}
|
||||
@@ -40,6 +40,6 @@ func (p *PutTaggingCommand) createTaggingPayload(fields *TaggingFields) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("error marshalling XML: %w", err)
|
||||
}
|
||||
p.Config.Payload = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + string(xmlData)
|
||||
p.Config.Payload = xml.Header + string(xmlData)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -86,6 +86,7 @@ type S3RequestConfigData struct {
|
||||
OutputFile string
|
||||
HeaderFile string
|
||||
AddressFormat string
|
||||
WebsiteConfiguration string
|
||||
}
|
||||
|
||||
type S3RequestBuilder struct {
|
||||
|
||||
Reference in New Issue
Block a user