Skip to content

Commit

Permalink
fix(computeacls): lookup call to treat status 204 properly (#605)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippschulte authored Feb 13, 2025
1 parent 2e8e27b commit e651634
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 75 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

**Bug fixes:**

- fix(computeacls): lookup call to treat status 204 properly [#605](https://github.com/fastly/go-fastly/pull/605)

**Dependencies:**

- build(deps): upgrade Go from 1.20 to 1.22 [#606](https://github.com/fastly/go-fastly/pull/606)
Expand Down
6 changes: 6 additions & 0 deletions fastly/computeacls/api_lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package computeacls
import (
"encoding/json"
"fmt"
"net/http"

"github.com/fastly/go-fastly/v9/fastly"
)
Expand Down Expand Up @@ -33,6 +34,11 @@ func Lookup(c *fastly.Client, i *LookupInput) (*ComputeACLEntry, error) {
}
defer resp.Body.Close()

// In the case that no matching IP was found, the API will return a 204 No Content. This is not an error condition, rather a lack of results.
if resp.StatusCode == http.StatusNoContent {
return nil, nil
}

var entry *ComputeACLEntry
if err := json.NewDecoder(resp.Body).Decode(&entry); err != nil {
return nil, fmt.Errorf("failed to decode json response: %w", err)
Expand Down
16 changes: 15 additions & 1 deletion fastly/computeacls/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func TestClient_ComputeACL(t *testing.T) {

ip, ipNet, err := net.ParseCIDR(actualACLEntries.Entries[0].Prefix)
if err != nil {
t.Errorf("error parsing IP: %v", err)
t.Fatal(err)
}

entry, err := Lookup(c, &LookupInput{
Expand Down Expand Up @@ -194,6 +194,20 @@ func TestClient_ComputeACL(t *testing.T) {
page++
}
})

// Lookup a non-existing IP in the test compute ACL
fastly.Record(t, "lookup_non_existing_ip", func(c *fastly.Client) {
entry, err := Lookup(c, &LookupInput{
ComputeACLID: fastly.ToPointer(acl.ComputeACLID),
ComputeACLIP: fastly.ToPointer("73.49.184.42"),
})
if entry != nil {
t.Errorf("unexpected lookup result: got %+v, expected 'nil'", entry)
}
if err != nil {
t.Errorf("unexpected error: %v", err)
}
})
}

func TestClient_Create_validation(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions fastly/computeacls/fixtures/create_acl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ interactions:
Content-Type:
- application/json
User-Agent:
- FastlyGo/9.11.0 (+github.com/fastly/go-fastly; go1.23.3)
- FastlyGo/9.13.0 (+github.com/fastly/go-fastly; go1.23.3)
url: https://api.fastly.com/resources/acls
method: POST
response:
body: '{"name":"test-compute-acl","id":"txVGyFOCzyFBvjJMqENpwA"}'
body: '{"name":"test-compute-acl","id":"twgcU5NNpY0GsVfsCav4o6"}'
headers:
Accept-Ranges:
- bytes
Expand All @@ -25,7 +25,7 @@ interactions:
Content-Type:
- application/json
Date:
- Fri, 24 Jan 2025 01:22:59 GMT
- Wed, 12 Feb 2025 23:49:33 GMT
Pragma:
- no-cache
Server:
Expand All @@ -39,9 +39,9 @@ interactions:
X-Cache-Hits:
- "0"
X-Served-By:
- cache-mia-kmia1760041-MIA, cache-mia-kmia1760041-MIA
- cache-mia-kmia1760066-MIA, cache-mia-kmia1760066-MIA
X-Timer:
- S1737681779.789838,VS0,VE607
- S1739404173.528059,VS0,VE498
status: 200 OK
code: 200
duration: ""
10 changes: 5 additions & 5 deletions fastly/computeacls/fixtures/delete_acl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ interactions:
form: {}
headers:
User-Agent:
- FastlyGo/9.11.0 (+github.com/fastly/go-fastly; go1.23.3)
url: https://api.fastly.com/resources/acls/txVGyFOCzyFBvjJMqENpwA
- FastlyGo/9.13.0 (+github.com/fastly/go-fastly; go1.23.3)
url: https://api.fastly.com/resources/acls/twgcU5NNpY0GsVfsCav4o6
method: DELETE
response:
body: ""
Expand All @@ -19,7 +19,7 @@ interactions:
Content-Length:
- "0"
Date:
- Fri, 24 Jan 2025 01:23:07 GMT
- Wed, 12 Feb 2025 23:49:38 GMT
Pragma:
- no-cache
Server:
Expand All @@ -33,9 +33,9 @@ interactions:
X-Cache-Hits:
- "0"
X-Served-By:
- cache-mia-kmia1760041-MIA, cache-mia-kmia1760041-MIA
- cache-mia-kmia1760066-MIA, cache-mia-kmia1760066-MIA
X-Timer:
- S1737681787.850150,VS0,VE413
- S1739404178.760091,VS0,VE341
status: 200 OK
code: 200
duration: ""
12 changes: 6 additions & 6 deletions fastly/computeacls/fixtures/describe_acl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ interactions:
form: {}
headers:
User-Agent:
- FastlyGo/9.11.0 (+github.com/fastly/go-fastly; go1.23.3)
url: https://api.fastly.com/resources/acls/txVGyFOCzyFBvjJMqENpwA
- FastlyGo/9.13.0 (+github.com/fastly/go-fastly; go1.23.3)
url: https://api.fastly.com/resources/acls/twgcU5NNpY0GsVfsCav4o6
method: GET
response:
body: '{"name":"test-compute-acl","id":"txVGyFOCzyFBvjJMqENpwA"}'
body: '{"name":"test-compute-acl","id":"twgcU5NNpY0GsVfsCav4o6"}'
headers:
Accept-Ranges:
- bytes
Expand All @@ -21,7 +21,7 @@ interactions:
Content-Type:
- application/json
Date:
- Fri, 24 Jan 2025 01:23:00 GMT
- Wed, 12 Feb 2025 23:49:33 GMT
Pragma:
- no-cache
Server:
Expand All @@ -35,9 +35,9 @@ interactions:
X-Cache-Hits:
- "0"
X-Served-By:
- cache-mia-kmia1760074-MIA, cache-mia-kmia1760041-MIA
- cache-mia-kmia1760025-MIA, cache-mia-kmia1760066-MIA
X-Timer:
- S1737681779.445909,VS0,VE742
- S1739404173.046379,VS0,VE342
status: 200 OK
code: 200
duration: ""
10 changes: 5 additions & 5 deletions fastly/computeacls/fixtures/list_acls.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ interactions:
form: {}
headers:
User-Agent:
- FastlyGo/9.11.0 (+github.com/fastly/go-fastly; go1.23.3)
- FastlyGo/9.13.0 (+github.com/fastly/go-fastly; go1.23.3)
url: https://api.fastly.com/resources/acls
method: GET
response:
body: '{"data":[{"id":"4rldWNzVJ4SVFG4HHF8RF8","name":"my-compute-acl"}],"meta":{"total":1}}'
body: '{"data":[{"id":"P3Z6xZXOcbt3l5C3CUxWh0","name":"my-compute-acl"}],"meta":{"total":1}}'
headers:
Accept-Ranges:
- bytes
Expand All @@ -21,7 +21,7 @@ interactions:
Content-Type:
- application/json
Date:
- Fri, 24 Jan 2025 01:22:58 GMT
- Wed, 12 Feb 2025 23:49:32 GMT
Pragma:
- no-cache
Server:
Expand All @@ -35,9 +35,9 @@ interactions:
X-Cache-Hits:
- "0"
X-Served-By:
- cache-mia-kmia1760066-MIA, cache-mia-kmia1760041-MIA
- cache-mia-kmia1760066-MIA, cache-mia-kmia1760066-MIA
X-Timer:
- S1737681778.293905,VS0,VE412
- S1739404172.032133,VS0,VE475
status: 200 OK
code: 200
duration: ""
10 changes: 5 additions & 5 deletions fastly/computeacls/fixtures/list_entries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ interactions:
form: {}
headers:
User-Agent:
- FastlyGo/9.11.0 (+github.com/fastly/go-fastly; go1.23.3)
url: https://api.fastly.com/resources/acls/txVGyFOCzyFBvjJMqENpwA/entries
- FastlyGo/9.13.0 (+github.com/fastly/go-fastly; go1.23.3)
url: https://api.fastly.com/resources/acls/twgcU5NNpY0GsVfsCav4o6/entries
method: GET
response:
body: '{"entries":[{"prefix":"1.2.3.0/24","action":"BLOCK"},{"prefix":"1.2.3.4/32","action":"ALLOW"},{"prefix":"23.23.23.23/32","action":"ALLOW"},{"prefix":"192.168.0.0/16","action":"BLOCK"}],"meta":{"limit":100}}'
Expand All @@ -21,7 +21,7 @@ interactions:
Content-Type:
- application/json
Date:
- Fri, 24 Jan 2025 01:23:02 GMT
- Wed, 12 Feb 2025 23:49:34 GMT
Pragma:
- no-cache
Server:
Expand All @@ -35,9 +35,9 @@ interactions:
X-Cache-Hits:
- "0"
X-Served-By:
- cache-mia-kmia1760026-MIA, cache-mia-kmia1760041-MIA
- cache-mia-kmia1760035-MIA, cache-mia-kmia1760066-MIA
X-Timer:
- S1737681781.168683,VS0,VE1344
- S1739404174.787765,VS0,VE782
status: 200 OK
code: 200
duration: ""
Loading

0 comments on commit e651634

Please sign in to comment.