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

feat(computeacls): Add support for Compute platform ACLs. #574

Merged
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
350beec
feat(compute_acl): add support for compute ACLs
philippschulte Jan 9, 2025
894062a
test(compute_acl_test.go): fix array indexing
philippschulte Jan 14, 2025
542f3a3
refactor(compute_acl): use struct as input to update an acl
philippschulte Jan 22, 2025
9bc205c
Merge branch 'main' into pschulte/add-support-for-compute-acls
philippschulte Jan 22, 2025
7d6e0fb
refactor(compute_acls): use new project layout
philippschulte Jan 24, 2025
787427e
chore(api_delete.go): update struct field description
philippschulte Jan 24, 2025
e66c9a7
chore(api_describe.go): update struct field description
philippschulte Jan 24, 2025
13c05e7
chore(api_list_entries.go): update struct field description
philippschulte Jan 24, 2025
3ccc553
chore(api_lookup.go): update struct field description
philippschulte Jan 24, 2025
9d36248
chore(api_lookup.go): update struct field description
philippschulte Jan 24, 2025
416545a
chore(api_response.go): add struct field description
philippschulte Jan 24, 2025
60edb37
chore(api_response.go): add struct field description
philippschulte Jan 24, 2025
8d9914f
chore(api_update.go): update struct field description
philippschulte Jan 24, 2025
b76dde9
chore(api_update.go): add struct field description
philippschulte Jan 24, 2025
5ff3905
chore(api_update.go): add struct field description
philippschulte Jan 24, 2025
830fbf2
chore(api_update.go): add struct field description
philippschulte Jan 24, 2025
07aaf5a
chore(api_response.go): add struct field description
philippschulte Jan 24, 2025
2c36a68
chore(api_response.go): add struct field description
philippschulte Jan 24, 2025
3cafb0a
refactor(computeacls): remove reference to API version
philippschulte Jan 24, 2025
ddb218b
Merge branch 'main' into pschulte/add-support-for-compute-acls
kpfleming Jan 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions fastly/computeacl/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Package computeacls contains subpackages which offer various operations to
// configure Fastly compute ACLs.
package computeacls
35 changes: 35 additions & 0 deletions fastly/computeacl/v1/api_create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package v1
kpfleming marked this conversation as resolved.
Show resolved Hide resolved

import (
"encoding/json"
"fmt"

"github.com/fastly/go-fastly/v9/fastly"
)

// CreateInput specifies the information needed for the Create() function to
// perform the operation.
type CreateInput struct {
// Name is the name of the compute ACL to create (required).
Name *string `json:"name"`
}

// Create creates a new compute ACL.
func Create(c *fastly.Client, i *CreateInput) (*ComputeACL, error) {
if i.Name == nil {
return nil, fastly.ErrMissingName
}

resp, err := c.PostJSON("/resources/acls", i, nil)
if err != nil {
return nil, err
}
defer resp.Body.Close()

var acl *ComputeACL
if err := json.NewDecoder(resp.Body).Decode(&acl); err != nil {
return nil, fmt.Errorf("failed to decode json response: %w", err)
}

return acl, nil
}
35 changes: 35 additions & 0 deletions fastly/computeacl/v1/api_delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package v1

import (
"net/http"

"github.com/fastly/go-fastly/v9/fastly"
)

// DeleteInput specifies the information needed for the Delete() function to
// perform the operation.
type DeleteInput struct {
// ComputeACLID is an ACL Identifier (required).
ComputeACLID *string
}

// DeleteComputeACL deletes the specified compute ACL.
func Delete(c *fastly.Client, i *DeleteInput) error {
if i.ComputeACLID == nil {
return fastly.ErrMissingComputeACLID
}

path := fastly.ToSafeURL("resources", "acls", *i.ComputeACLID)

resp, err := c.Delete(path, nil)
if err != nil {
return err
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return fastly.NewHTTPError(resp)
}

return nil
}
37 changes: 37 additions & 0 deletions fastly/computeacl/v1/api_describe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package v1

import (
"encoding/json"
"fmt"

"github.com/fastly/go-fastly/v9/fastly"
)

// DescribeInput specifies the information needed for the Describe() function to perform
// the operation.
type DescribeInput struct {
// ComputeACLID is an ACL Identifier (required).
ComputeACLID *string
}

// Describe describes a specified compute ACL.
func Describe(c *fastly.Client, i *DescribeInput) (*ComputeACL, error) {
if i.ComputeACLID == nil {
return nil, fastly.ErrMissingComputeACLID
}

path := fastly.ToSafeURL("resources", "acls", *i.ComputeACLID)

resp, err := c.Get(path, nil)
if err != nil {
return nil, err
}
defer resp.Body.Close()

var acl *ComputeACL
if err := json.NewDecoder(resp.Body).Decode(&acl); err != nil {
return nil, fmt.Errorf("failed to decode json response: %w", err)
}

return acl, nil
}
25 changes: 25 additions & 0 deletions fastly/computeacl/v1/api_list_acls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package v1

import (
"encoding/json"
"fmt"

"github.com/fastly/go-fastly/v9/fastly"
)

// ListACLs retrieves all compute ACLs.
kpfleming marked this conversation as resolved.
Show resolved Hide resolved
func ListACLs(c *fastly.Client) (*ComputeACLs, error) {
resp, err := c.Get("/resources/acls", nil)
if err != nil {
return nil, err
}
defer resp.Body.Close()

var acls *ComputeACLs

if err := json.NewDecoder(resp.Body).Decode(&acls); err != nil {
return nil, fmt.Errorf("failed to decode json response: %w", err)
}

return acls, nil
}
52 changes: 52 additions & 0 deletions fastly/computeacl/v1/api_list_entries.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package v1

import (
"encoding/json"
"fmt"
"strconv"

"github.com/fastly/go-fastly/v9/fastly"
)

// ListEntriesInput specifies the information needed for the ListEntries() function to perform
// the operation.
type ListEntriesInput struct {
// ComputeACLID is an ACL Identifier (required).
ComputeACLID *string
// Cursor is used for paginating through results.
Cursor *string
// Limit is the maximum number of entries included the response.
Limit *int
}

// ListEntries
func ListEntries(c *fastly.Client, i *ListEntriesInput) (*ComputeACLEntries, error) {
if i.ComputeACLID == nil {
return nil, fastly.ErrMissingComputeACLID
}

ro := &fastly.RequestOptions{
Params: map[string]string{},
}
if i.Cursor != nil {
ro.Params["cursor"] = *i.Cursor
}
if i.Limit != nil {
ro.Params["limit"] = strconv.Itoa(*i.Limit)
}

path := fastly.ToSafeURL("resources", "acls", *i.ComputeACLID, "entries")

resp, err := c.Get(path, ro)
if err != nil {
return nil, err
}
defer resp.Body.Close()

var entries *ComputeACLEntries
if err := json.NewDecoder(resp.Body).Decode(&entries); err != nil {
return nil, fmt.Errorf("failed to decode json response: %w", err)
}

return entries, nil
}
42 changes: 42 additions & 0 deletions fastly/computeacl/v1/api_lookup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package v1

import (
"encoding/json"
"fmt"

"github.com/fastly/go-fastly/v9/fastly"
)

// LookupInput specifies the information needed for the Lookup() function to perform
// the operation.
type LookupInput struct {
// ComputeACLID is an ACL Identifier (required).
ComputeACLID *string
// ComputeACLIP is a valid IPv4 or IPv6 address (required).
ComputeACLIP *string
}

// Lookup finds a matching ACL entry for an IP address.
func Lookup(c *fastly.Client, i *LookupInput) (*ComputeACLEntry, error) {
if i.ComputeACLID == nil {
return nil, fastly.ErrMissingComputeACLID
}
if i.ComputeACLIP == nil {
return nil, fastly.ErrMissingComputeACLIP
}

path := fastly.ToSafeURL("resources", "acls", *i.ComputeACLID, "entry", *i.ComputeACLIP)

resp, err := c.Get(path, nil)
if err != nil {
return nil, err
}
defer resp.Body.Close()

var entry *ComputeACLEntry
if err := json.NewDecoder(resp.Body).Decode(&entry); err != nil {
return nil, fmt.Errorf("failed to decode json response: %w", err)
}

return entry, nil
}
47 changes: 47 additions & 0 deletions fastly/computeacl/v1/api_response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package v1

// ComputeACL is the API response structure for the create and describe operations.
type ComputeACL struct {
// Name is an ACL name.
Name string `json:"name"`
// ComputeACLID is an ACL Identifier.
ComputeACLID string `json:"id"`
philippschulte marked this conversation as resolved.
Show resolved Hide resolved
}

// ComputeACLs is the API response structure for the list compute ACLs operation.
type ComputeACLs struct {
// Data is the list of returned cumpute ACLs.
Data []ComputeACL `json:"data"`
// Meta is the information for total compute ACLs.
Meta MetaACLs `json:"meta"`
}

// MetaACLs is a subset of the ComputeACLs response structure.
type MetaACLs struct {
// Total is the sum of compute ACLs.
Total int `json:"total"`
}

// ComputeACLEntry is the API response structure for the lookup operation.
type ComputeACLEntry struct {
// Prefix is an IP prefix defined in Classless Inter-Domain Routing (CIDR) format.
Prefix string `json:"prefix"`
philippschulte marked this conversation as resolved.
Show resolved Hide resolved
// Action is one of "ALLOW" or "BLOCK".
Action string `json:"action"`
philippschulte marked this conversation as resolved.
Show resolved Hide resolved
}

// ComputeACLEntries is the API response structure for the list compute ACL entries operation.
type ComputeACLEntries struct {
// Entries is the list of returned cumpute ACL entries.
Entries []ComputeACLEntry
// Meta is the information for pagination.
Meta MetaEntries `json:"meta"`
}

// MetaEntries is a subset of the ComputeACLs response structure.
type MetaEntries struct {
// Limit is how many results are included in this response.
Limit int `json:"limit"`
// NextCursor is the cursor value used to retrieve the next page.
NextCursor string `json:"next_cursor"`
}
Loading
Loading