-
Notifications
You must be signed in to change notification settings - Fork 129
[CDTOOL-1089] Add support for ngwaf lists #700
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package lists | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
|
|
||
| "github.com/fastly/go-fastly/v10/fastly" | ||
| ) | ||
|
|
||
| // CreateInput specifies the information needed for the Create() function to | ||
| // perform the operation. | ||
| type CreateInput struct { | ||
| // Context, if supplied, will be used as the Request's context. | ||
| Context *context.Context | ||
| // Description is the description of the list. | ||
| Description *string `json:"description"` | ||
| // Entries are the entries of the list (required). | ||
| Entries *[]string `json:"entries"` | ||
| // Name is the name of the list (required). | ||
| Name *string `json:"name"` | ||
| // Type is the type of the list. Must be one of string | wildcard | ip | country | signal (required). | ||
| Type *string `json:"type"` | ||
| // WorkspaceID is the workspace identifier (required). | ||
| WorkspaceID *string | ||
| } | ||
|
|
||
| // Create creates a new workspace. | ||
| func Create(c *fastly.Client, i *CreateInput) (*List, error) { | ||
| if i.WorkspaceID == nil { | ||
| return nil, fastly.ErrMissingWorkspaceID | ||
| } | ||
| if i.Entries == nil { | ||
| return nil, fastly.ErrMissingEntries | ||
| } | ||
| if i.Name == nil { | ||
| return nil, fastly.ErrMissingName | ||
| } | ||
| if i.Type == nil { | ||
| return nil, fastly.ErrMissingType | ||
| } | ||
|
|
||
| path := fastly.ToSafeURL("ngwaf", "v1", "workspaces", *i.WorkspaceID, "lists") | ||
|
|
||
| resp, err := c.PostJSON(path, i, fastly.CreateRequestOptions(i.Context)) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| defer resp.Body.Close() | ||
|
|
||
| var list *List | ||
| if err := json.NewDecoder(resp.Body).Decode(&list); err != nil { | ||
| return nil, fmt.Errorf("failed to decode json response: %w", err) | ||
| } | ||
|
|
||
| return list, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package lists | ||
|
|
||
| import ( | ||
| "context" | ||
| "net/http" | ||
|
|
||
| "github.com/fastly/go-fastly/v10/fastly" | ||
| ) | ||
|
|
||
| // DeleteInput specifies the information needed for the Delete() function to | ||
| // perform the operation. | ||
| type DeleteInput struct { | ||
| // Context, if supplied, will be used as the Request's context. | ||
| Context *context.Context | ||
| // ListID is the id of the list to be deleted (required). | ||
| ListID *string | ||
| // WorkspaceID is the workspace identifier (required). | ||
| WorkspaceID *string | ||
| } | ||
|
|
||
| // Delete deletes the specified workspace. | ||
| func Delete(c *fastly.Client, i *DeleteInput) error { | ||
| if i.WorkspaceID == nil { | ||
| return fastly.ErrMissingWorkspaceID | ||
| } | ||
| if i.ListID == nil { | ||
| return fastly.ErrMissingListID | ||
| } | ||
|
|
||
| path := fastly.ToSafeURL("ngwaf", "v1", "workspaces", *i.WorkspaceID, "lists", *i.ListID) | ||
|
|
||
| resp, err := c.Delete(path, fastly.CreateRequestOptions(i.Context)) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| defer resp.Body.Close() | ||
|
|
||
| if resp.StatusCode != http.StatusNoContent { | ||
| return fastly.NewHTTPError(resp) | ||
| } | ||
|
|
||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package lists | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
|
|
||
| "github.com/fastly/go-fastly/v10/fastly" | ||
| ) | ||
|
|
||
| // GetInput specifies the information needed for the Get() function to perform | ||
| // the operation. | ||
| type GetInput struct { | ||
| // Context, if supplied, will be used as the Request's context. | ||
| Context *context.Context | ||
| // ListID is the workspace identifier (required). | ||
| ListID *string | ||
| // WorkspaceID is the workspace identifier (required). | ||
| WorkspaceID *string | ||
| } | ||
|
|
||
| // Get retrieves the specified workspace. | ||
| func Get(c *fastly.Client, i *GetInput) (*List, error) { | ||
| if i.WorkspaceID == nil { | ||
| return nil, fastly.ErrMissingWorkspaceID | ||
| } | ||
| if i.ListID == nil { | ||
| return nil, fastly.ErrMissingListID | ||
| } | ||
|
|
||
| path := fastly.ToSafeURL("ngwaf", "v1", "workspaces", *i.WorkspaceID, "lists", *i.ListID) | ||
|
|
||
| resp, err := c.Get(path, fastly.CreateRequestOptions(i.Context)) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| defer resp.Body.Close() | ||
|
|
||
| var list *List | ||
| if err := json.NewDecoder(resp.Body).Decode(&list); err != nil { | ||
| return nil, fmt.Errorf("failed to decode json response: %w", err) | ||
| } | ||
|
|
||
| return list, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package lists | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
|
|
||
| "github.com/fastly/go-fastly/v10/fastly" | ||
| ) | ||
|
|
||
| // ListInput specifies the information needed for the List() function to perform | ||
| // the operation. | ||
| type ListInput struct { | ||
| // Context, if supplied, will be used as the Request's context. | ||
| Context *context.Context | ||
| // WorkspaceID is the workspace identifier (required). | ||
| WorkspaceID *string | ||
| } | ||
|
|
||
| // ListLists retrieves a list of lists for the given workspace. | ||
| func ListLists(c *fastly.Client, i *ListInput) (*Lists, error) { | ||
| if i.WorkspaceID == nil { | ||
| return nil, fastly.ErrMissingWorkspaceID | ||
| } | ||
|
|
||
| path := fastly.ToSafeURL("ngwaf", "v1", "workspaces", *i.WorkspaceID, "lists") | ||
|
|
||
| resp, err := c.Get(path, fastly.CreateRequestOptions(i.Context)) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| defer resp.Body.Close() | ||
|
|
||
| var lists *Lists | ||
| if err := json.NewDecoder(resp.Body).Decode(&lists); err != nil { | ||
| return nil, fmt.Errorf("failed to decode json response: %w", err) | ||
| } | ||
|
|
||
| return lists, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package lists | ||
|
|
||
| import "time" | ||
|
|
||
| // List is the API response structure for the create, update, and get operations. | ||
| type List struct { | ||
| // CreatedAt is the date and time in ISO 8601 format. | ||
| CreatedAt time.Time `json:"created_at"` | ||
| // Description is the description of the list. | ||
| Description string `json:"description"` | ||
| // Entries are the entries of the list. | ||
| Entries []string `json:"entries"` | ||
| // ListID is the list identifier (UUID). | ||
| ListID string `json:"id"` | ||
| // Name is the name of the list. | ||
| Name string `json:"name"` | ||
| // ReferenceID is the reference ID of the list. | ||
| ReferenceID string `json:"reference_id"` | ||
| // Scope is the scope of the list. | ||
| Scope Scope `json:"scope"` | ||
| // Type is the type of the list. | ||
| Type string `json:"type"` | ||
| // UpdatedAt is the date and time in ISO 8601 format. | ||
| UpdatedAt time.Time `json:"updated_at"` | ||
| } | ||
|
|
||
| // Scope is the API response structure for the scope of the list. | ||
| type Scope struct { | ||
| // Type is the type of the scope. | ||
| Type string `json:"type"` | ||
| } | ||
|
|
||
| // Lists is the API response structure for the list lists operation. | ||
| type Lists struct { | ||
| // Data is the list of returned lists. | ||
| Data []List `json:"data"` | ||
| // Meta is the information for total lists. | ||
| Meta MetaLists `json:"meta"` | ||
| } | ||
|
|
||
| // MetaLists is a subset of the Lists response structure. | ||
| type MetaLists struct { | ||
| // Total is the sum of lists. | ||
| Total int `json:"total"` | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.