Skip to content

Commit e85f254

Browse files
author
Matheus Politano
committed
feat: add redirect in the update function
1 parent 4c3125f commit e85f254

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

stackit/internal/services/cdn/distribution/resource.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,51 @@ func (r *distributionResource) Update(ctx context.Context, req resource.UpdateRe
698698
blockedCountries = &tempBlockedCountries
699699
}
700700

701+
// redirects
702+
var redirectsConfig *cdn.RedirectConfig
703+
if configModel.Redirects != nil {
704+
sdkRules := []cdn.RedirectRule{}
705+
if len(configModel.Redirects.Rules) > 0 {
706+
for _, rule := range configModel.Redirects.Rules {
707+
matchers := []cdn.Matcher{}
708+
for _, matcher := range rule.Matchers {
709+
var matchCond *cdn.MatchCondition
710+
if matcher.ValueMatchCondition != nil {
711+
cond := cdn.MatchCondition(*matcher.ValueMatchCondition)
712+
matchCond = &cond
713+
}
714+
715+
matchers = append(matchers, cdn.Matcher{
716+
Values: &matcher.Values,
717+
ValueMatchCondition: matchCond,
718+
})
719+
}
720+
721+
var ruleMatchCond *cdn.MatchCondition
722+
if rule.RuleMatchCondition != nil {
723+
cond := cdn.MatchCondition(*rule.RuleMatchCondition)
724+
ruleMatchCond = &cond
725+
}
726+
727+
statusCode := cdn.RedirectRuleStatusCode(rule.StatusCode)
728+
targetUrl := rule.TargetUrl
729+
730+
sdkConfigRule := cdn.RedirectRule{
731+
Description: rule.Description,
732+
Enabled: rule.Enabled,
733+
Matchers: &matchers,
734+
RuleMatchCondition: ruleMatchCond,
735+
StatusCode: &statusCode,
736+
TargetUrl: &targetUrl,
737+
}
738+
sdkRules = append(sdkRules, sdkConfigRule)
739+
}
740+
}
741+
redirectsConfig = &cdn.RedirectConfig{
742+
Rules: &sdkRules,
743+
}
744+
}
745+
701746
configPatchBackend := &cdn.ConfigPatchBackend{}
702747

703748
switch configModel.Backend.Type {

0 commit comments

Comments
 (0)