Skip to content

Commit

Permalink
fix: single_origin was being ignored in manifest read
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickMenoti committed May 29, 2024
1 parent f2428cf commit 71965d0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
10 changes: 6 additions & 4 deletions pkg/contracts/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,12 @@ type CacheSetting struct {
}

type Origin struct {
Name string `json:"name"`
OriginType string `json:"origin_type,omitempty"`
Bucket string `json:"bucket,omitempty"`
Prefix string `json:"prefix,omitempty"`
Name string `json:"name"`
OriginType string `json:"origin_type,omitempty"`
Bucket string `json:"bucket,omitempty"`
Prefix string `json:"prefix,omitempty"`
Addresses []sdk.CreateOriginsRequestAddresses `json:"addresses,omitempty"`
HostHeader string `json:"host_header,omitempty"`
}

type RuleEngine struct {
Expand Down
44 changes: 34 additions & 10 deletions pkg/manifest/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,25 @@ func makeRuleRequestCreate(rule contracts.RuleEngine, conf *contracts.AzionAppli
func makeOriginCreateRequest(origin contracts.Origin, conf *contracts.AzionApplicationOptions) *apiOrigin.CreateRequest {
request := &apiOrigin.CreateRequest{}

request.SetBucket(conf.Bucket)
switch origin.OriginType {
case "single_origin":
if origin.HostHeader != "" {
request.SetHostHeader(origin.HostHeader)
}
if len(origin.Addresses) > 0 {
request.SetAddresses(origin.Addresses)
}

case "object_storage":
request.SetBucket(conf.Bucket)

if origin.Prefix != "" {
request.SetPrefix(origin.Prefix)
} else {
request.SetPrefix(conf.Prefix)
if origin.Prefix != "" {
request.SetPrefix(origin.Prefix)
} else {
request.SetPrefix(conf.Prefix)
}
}

if origin.OriginType != "" {
request.SetOriginType(origin.OriginType)
}
Expand All @@ -340,13 +352,25 @@ func makeOriginCreateRequest(origin contracts.Origin, conf *contracts.AzionAppli
func makeOriginUpdateRequest(origin contracts.Origin, conf *contracts.AzionApplicationOptions) *apiOrigin.UpdateRequest {
request := &apiOrigin.UpdateRequest{}

request.SetBucket(conf.Bucket)
switch origin.OriginType {
case "single_origin":
if origin.HostHeader != "" {
request.SetHostHeader(origin.HostHeader)
}
if len(origin.Addresses) > 0 {
request.SetAddresses(origin.Addresses)
}

case "object_storage":
request.SetBucket(conf.Bucket)

if origin.Prefix != "" {
request.SetPrefix(origin.Prefix)
} else {
request.SetPrefix(conf.Prefix)
if origin.Prefix != "" {
request.SetPrefix(origin.Prefix)
} else {
request.SetPrefix(conf.Prefix)
}
}

if origin.OriginType != "" {
request.SetOriginType(origin.OriginType)
}
Expand Down

0 comments on commit 71965d0

Please sign in to comment.