Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/s3 website configuration #649

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions apis/s3/v1beta1/websiteConfiguration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type RedirectAllRequestsTo struct {
// Protocol to use when redirecting requests. The default is the protocol that
// is used in the original request.
// +kubebuilder:validation:Enum=http;https
Protocol string `json:"protocol"`
Protocol string `json:"protocol,omitempty"`
}

// RoutingRule specifies the redirect behavior and when a redirect is applied.
Expand Down Expand Up @@ -114,7 +114,7 @@ type Redirect struct {

// Protocol to use when redirecting requests. The default is the protocol that
// is used in the original request.
Protocol string `json:"protocol"`
Protocol string `json:"protocol,omitempty"`

// The object key prefix to use in the redirect request. For example, to redirect
// requests for all pages with prefix docs/ (objects in the docs/ folder) to
Expand Down
3 changes: 0 additions & 3 deletions package/crds/s3.aws.crossplane.io_buckets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,6 @@ spec:
type: string
required:
- hostName
- protocol
muvaf marked this conversation as resolved.
Show resolved Hide resolved
type: object
routingRules:
description: Rules that define when a redirect is applied and the redirect behavior.
Expand Down Expand Up @@ -920,8 +919,6 @@ spec:
replaceKeyWith:
description: The specific object key to use in the redirect request. For example, redirect request to error.html. Not required if one of the siblings is present. Can be present only if ReplaceKeyPrefixWith is not provided.
type: string
required:
- protocol
type: object
required:
- redirect
Expand Down
61 changes: 36 additions & 25 deletions pkg/controller/s3/bucket/websiteConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,28 +139,35 @@ func GenerateWebsiteConfiguration(config *v1beta1.WebsiteConfiguration) *awss3.W
if config.RedirectAllRequestsTo != nil {
wi.RedirectAllRequestsTo = &awss3.RedirectAllRequestsTo{
HostName: awsclient.String(config.RedirectAllRequestsTo.HostName),
Protocol: awss3.Protocol(config.RedirectAllRequestsTo.Protocol),
}
}
wi.RoutingRules = make([]awss3.RoutingRule, len(config.RoutingRules))
for i, rule := range config.RoutingRules {
rr := awss3.RoutingRule{
Redirect: &awss3.Redirect{
HostName: rule.Redirect.HostName,
HttpRedirectCode: rule.Redirect.HTTPRedirectCode,
Protocol: awss3.Protocol(rule.Redirect.Protocol),
ReplaceKeyPrefixWith: rule.Redirect.ReplaceKeyPrefixWith,
ReplaceKeyWith: rule.Redirect.ReplaceKeyWith,
},
if config.RedirectAllRequestsTo.Protocol != "" {
wi.RedirectAllRequestsTo.Protocol = awss3.Protocol(config.RedirectAllRequestsTo.Protocol)
}
if rule.Condition != nil {
rr.Condition = &awss3.Condition{
HttpErrorCodeReturnedEquals: rule.Condition.HTTPErrorCodeReturnedEquals,
KeyPrefixEquals: rule.Condition.KeyPrefixEquals,
}
if len(config.RoutingRules) != 0 {
wi.RoutingRules = make([]awss3.RoutingRule, len(config.RoutingRules))
for i, rule := range config.RoutingRules {
rr := awss3.RoutingRule{
Redirect: &awss3.Redirect{
HostName: rule.Redirect.HostName,
HttpRedirectCode: rule.Redirect.HTTPRedirectCode,
ReplaceKeyPrefixWith: rule.Redirect.ReplaceKeyPrefixWith,
ReplaceKeyWith: rule.Redirect.ReplaceKeyWith,
},
}
if rule.Redirect.Protocol != "" {
rr.Redirect.Protocol = awss3.Protocol(rule.Redirect.Protocol)
}
if rule.Condition != nil {
rr.Condition = &awss3.Condition{
HttpErrorCodeReturnedEquals: rule.Condition.HTTPErrorCodeReturnedEquals,
KeyPrefixEquals: rule.Condition.KeyPrefixEquals,
}
}
wi.RoutingRules[i] = rr
}
wi.RoutingRules[i] = rr
}

return wi
}

Expand Down Expand Up @@ -190,10 +197,12 @@ func createWebsiteConfigFromExternal(external *awss3.GetBucketWebsiteOutput, con
if config.RedirectAllRequestsTo == nil {
config.RedirectAllRequestsTo = &v1beta1.RedirectAllRequestsTo{}
}
config.RedirectAllRequestsTo.Protocol = awsclient.LateInitializeString(
config.RedirectAllRequestsTo.Protocol,
awsclient.String(string(external.RedirectAllRequestsTo.Protocol)),
)
if external.RedirectAllRequestsTo.Protocol != "" {
config.RedirectAllRequestsTo.Protocol = awsclient.LateInitializeString(
config.RedirectAllRequestsTo.Protocol,
awsclient.String(string(external.RedirectAllRequestsTo.Protocol)),
)
}
config.RedirectAllRequestsTo.HostName = awsclient.LateInitializeString(
config.RedirectAllRequestsTo.HostName,
external.RedirectAllRequestsTo.HostName,
Expand All @@ -219,10 +228,12 @@ func createWebsiteConfigFromExternal(external *awss3.GetBucketWebsiteOutput, con
config.RoutingRules[i].Redirect.ReplaceKeyWith,
rr.Redirect.ReplaceKeyWith,
)
config.RoutingRules[i].Redirect.Protocol = awsclient.LateInitializeString(
config.RoutingRules[i].Redirect.Protocol,
awsclient.String(string(rr.Redirect.Protocol)),
)
if rr.Redirect.Protocol != "" {
config.RoutingRules[i].Redirect.Protocol = awsclient.LateInitializeString(
config.RoutingRules[i].Redirect.Protocol,
awsclient.String(string(rr.Redirect.Protocol)),
)
}
}
if rr.Condition != nil {
if config.RoutingRules[i].Condition == nil {
Expand Down