Skip to content

Commit e850a14

Browse files
author
Matheus Politano
committed
feat: add redirect in the update function
1 parent 7cca33f commit e850a14

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
@@ -697,6 +697,51 @@ func (r *distributionResource) Update(ctx context.Context, req resource.UpdateRe
697697
blockedCountries = &tempBlockedCountries
698698
}
699699

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

702747
if configModel.Backend.Type == "http" {

0 commit comments

Comments
 (0)