Skip to content

Commit 7f5c87e

Browse files
feat(ngwaf): add support for signals
1 parent 2a1eab3 commit 7f5c87e

18 files changed

+757
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
### Enhancements:
1010
- feat(ngwaf): add support for timeseries ([#689](https://github.com/fastly/go-fastly/pull/689))
11+
- feat(ngwaf): add support for signals ([#692](https://github.com/fastly/go-fastly/pull/692))
1112

1213
### Bug fixes:
1314
- fix(logging): Improve documentation of Region and ProcessingRegion fields. ([#690](https://github.com/fastly/go-fastly/pull/690))

fastly/errors.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ var ErrMissingIsExpired = NewFieldError("IsExpired")
109109
// requires a "RedactionID" key, but one was not set.
110110
var ErrMissingRedactionID = NewFieldError("RedactionID")
111111

112+
// ErrMissingSignalID is an error that is returned when an input struct
113+
// requires a "SignalID" key, but one was not set.
114+
var ErrMissingSignalID = NewFieldError("SignalID")
115+
116+
// ErrMissingRequestID is an error that is returned when an input struct
117+
// requires a "RequestID" key, but one was not set.
118+
var ErrMissingRequestID = NewFieldError("RequestID")
119+
120+
// ErrMissingLimit is an error that is returned when an input struct
121+
// requires a "Limit" key, but one was not set.
122+
var ErrMissingLimit = NewFieldError("Limit")
123+
112124
// ErrMissingField is an error that is returned when an input struct
113125
// requires a "Field" key, but one was not set.
114126
var ErrMissingField = NewFieldError("Field")

fastly/ngwaf/v1/redactions/api_create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import (
1313
type CreateInput struct {
1414
// Context, if supplied, will be used as the Request's context.
1515
Context *context.Context `json:"-"`
16-
// Field is the name of the field to redact (required). Will be converted to lowercase.
16+
// Field is the name of the field to redact (required). Will be converted to lowercase.
1717
Field *string `json:"field"`
1818
// Type is the type of field being redacted. Must be one of `request_parameter`, `request_header`, or `response_header`.
1919
Type *string `json:"type"`
20-
// WorkspaceID is the ID of the workspace that the redaction is being created in
20+
// WorkspaceID is the ID of the workspace that the redaction is being created in.
2121
WorkspaceID *string `json:"-"`
2222
}
2323

fastly/ngwaf/v1/redactions/api_response.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package redactions
22

33
import "time"
44

5-
// Workspace is the API response structure for the create, update, and get operations.
5+
// Redaction is the API response structure for the create, update, and get operations.
66
type Redaction struct {
77
// CreatedAt is the date and time in ISO 8601 format.
88
CreatedAt time.Time `json:"created_at"`
@@ -14,7 +14,7 @@ type Redaction struct {
1414
RedactionID string `json:"id"`
1515
}
1616

17-
// WorkspRedactionsaces is the API response structure for the list Redactions operation.
17+
// Redactions is the API response structure for the list Redactions operation.
1818
type Redactions struct {
1919
// Data is the list of returned redactions.
2020
Data []Redaction `json:"data"`

fastly/ngwaf/v1/redactions/api_update.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ import (
1313
type UpdateInput struct {
1414
// Context, if supplied, will be used as the Request's context.
1515
Context *context.Context `json:"-"`
16-
// Field is the name of the field to redact (required). Will be converted to lowercase.
16+
// Field is the name of the field to redact (required). Will be converted to lowercase.
1717
Field *string `json:"field"`
1818
// RedactionID is the id of the redaction that's being updated (required).
1919
RedactionID *string `json:"-"`
2020
// Type is the type of field being redacted. Must be one of `request_parameter`, `request_header`, or `response_header`.
2121
Type *string `json:"type"`
22-
// WorkspaceID is the ID of the workspace that the redaction is being created in
22+
// WorkspaceID is the ID of the workspace that the redaction belongs to.
2323
WorkspaceID *string `json:"-"`
2424
}
2525

fastly/ngwaf/v1/signals/api_create.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package signals
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
8+
"github.com/fastly/go-fastly/v10/fastly"
9+
)
10+
11+
// CreateInput specifies the information needed for the Create() function to
12+
// perform the operation.
13+
type CreateInput struct {
14+
// Context, if supplied, will be used as the Request's context.
15+
Context *context.Context `json:"-"`
16+
// Description is a description of the signal (optional).
17+
Description *string `json:"description"`
18+
// Name is the name of the signal. Must be between 3 and 25 characters. Letters, numbers, hyphens, and spaces are accepted. Special characters and periods are not accepted.
19+
Name *string `json:"name"`
20+
// WorkspaceID is the ID of the workspace that the signal is being created in.
21+
WorkspaceID *string `json:"-"`
22+
}
23+
24+
// Create creates a new workspace.
25+
func Create(c *fastly.Client, i *CreateInput) (*Signal, error) {
26+
if i.WorkspaceID == nil {
27+
return nil, fastly.ErrMissingWorkspaceID
28+
}
29+
if i.Name == nil {
30+
return nil, fastly.ErrMissingName
31+
}
32+
33+
path := fastly.ToSafeURL("ngwaf", "v1", "workspaces", *i.WorkspaceID, "signals")
34+
35+
resp, err := c.PostJSON(path, i, fastly.CreateRequestOptions(i.Context))
36+
if err != nil {
37+
return nil, err
38+
}
39+
defer resp.Body.Close()
40+
41+
var signal *Signal
42+
if err := json.NewDecoder(resp.Body).Decode(&signal); err != nil {
43+
return nil, fmt.Errorf("failed to decode json response: %w", err)
44+
}
45+
46+
return signal, nil
47+
}

fastly/ngwaf/v1/signals/api_delete.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package signals
2+
3+
import (
4+
"context"
5+
"net/http"
6+
7+
"github.com/fastly/go-fastly/v10/fastly"
8+
)
9+
10+
// DeleteInput specifies the information needed for the Delete() function to
11+
// perform the operation.
12+
type DeleteInput struct {
13+
// Context, if supplied, will be used as the Request's context.
14+
Context *context.Context
15+
// SignalID is the signal identifier (required).
16+
SignalID *string
17+
// WorkspaceID is the workspace identifier (required).
18+
WorkspaceID *string
19+
}
20+
21+
// Delete deletes the specified workspace.
22+
func Delete(c *fastly.Client, i *DeleteInput) error {
23+
if i.WorkspaceID == nil {
24+
return fastly.ErrMissingWorkspaceID
25+
}
26+
if i.SignalID == nil {
27+
return fastly.ErrMissingSignalID
28+
}
29+
30+
path := fastly.ToSafeURL("ngwaf", "v1", "workspaces", *i.WorkspaceID, "signals", *i.SignalID)
31+
32+
resp, err := c.Delete(path, fastly.CreateRequestOptions(i.Context))
33+
if err != nil {
34+
return err
35+
}
36+
defer resp.Body.Close()
37+
38+
if resp.StatusCode != http.StatusNoContent {
39+
return fastly.NewHTTPError(resp)
40+
}
41+
42+
return nil
43+
}

fastly/ngwaf/v1/signals/api_get.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package signals
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
8+
"github.com/fastly/go-fastly/v10/fastly"
9+
)
10+
11+
// GetInput specifies the information needed for the Get() function to perform
12+
// the operation.
13+
type GetInput struct {
14+
// Context, if supplied, will be used as the Request's context.
15+
Context *context.Context
16+
// SignalID is the signal identifier (required).
17+
SignalID *string
18+
// WorkspaceID is the workspace identifier (required).
19+
WorkspaceID *string
20+
}
21+
22+
// Get retrieves the specified workspace.
23+
func Get(c *fastly.Client, i *GetInput) (*Signal, error) {
24+
if i.WorkspaceID == nil {
25+
return nil, fastly.ErrMissingWorkspaceID
26+
}
27+
if i.SignalID == nil {
28+
return nil, fastly.ErrMissingSignalID
29+
}
30+
31+
path := fastly.ToSafeURL("ngwaf", "v1", "workspaces", *i.WorkspaceID, "signals", *i.SignalID)
32+
33+
resp, err := c.Get(path, fastly.CreateRequestOptions(i.Context))
34+
if err != nil {
35+
return nil, err
36+
}
37+
defer resp.Body.Close()
38+
39+
var signal *Signal
40+
if err := json.NewDecoder(resp.Body).Decode(&signal); err != nil {
41+
return nil, fmt.Errorf("failed to decode json response: %w", err)
42+
}
43+
44+
return signal, nil
45+
}

fastly/ngwaf/v1/signals/api_list.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package signals
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
"strconv"
8+
9+
"github.com/fastly/go-fastly/v10/fastly"
10+
)
11+
12+
// ListInput specifies the information needed for the List() function to perform
13+
// the operation.
14+
type ListInput struct {
15+
// Context, if supplied, will be used as the Request's context.
16+
Context *context.Context
17+
// Limit how many results are returned.
18+
Limit *int
19+
// Mode filter results based on mode.
20+
Mode *string
21+
// Page number of the collection to request.
22+
Page *int
23+
// WorkspaceID is the workspace identifier (required).
24+
WorkspaceID *string
25+
}
26+
27+
// List retrieves a list of workspaces, with optional filtering and pagination.
28+
func List(c *fastly.Client, i *ListInput) (*Signals, error) {
29+
requestOptions := fastly.CreateRequestOptions(i.Context)
30+
if i.Limit != nil {
31+
requestOptions.Params["limit"] = strconv.Itoa(*i.Limit)
32+
}
33+
if i.Mode != nil {
34+
requestOptions.Params["mode"] = *i.Mode
35+
}
36+
if i.Page != nil {
37+
requestOptions.Params["page"] = strconv.Itoa(*i.Page)
38+
}
39+
40+
path := fastly.ToSafeURL("ngwaf", "v1", "workspaces", *i.WorkspaceID, "signals")
41+
42+
resp, err := c.Get(path, requestOptions)
43+
if err != nil {
44+
return nil, err
45+
}
46+
defer resp.Body.Close()
47+
48+
var signals *Signals
49+
if err := json.NewDecoder(resp.Body).Decode(&signals); err != nil {
50+
return nil, fmt.Errorf("failed to decode json response: %w", err)
51+
}
52+
53+
return signals, nil
54+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package signals
2+
3+
import "time"
4+
5+
// Signal is the api response to signals and signals operations.
6+
type Signal struct {
7+
// CreatedAt is the created date and time the event was created in ISO 8601 format.
8+
CreatedAt time.Time `json:"created_at"`
9+
// Description is the user created description of the signal
10+
Description string `json:"description"`
11+
// Name is the user created name of the signal.
12+
Name string `json:"name"`
13+
// ReferenceID is the reference ID of the signal.
14+
ReferenceID string `json:"reference_id"`
15+
// Scope is the scope that the signal applies to
16+
Scope Scope `json:"scope"`
17+
// SignalID is the ID of the signal (auto generated).
18+
SignalID string `json:"id"`
19+
// UpdatedAt is the date and time in ISO 8601 format.
20+
UpdatedAt time.Time `json:"updated_at"`
21+
}
22+
23+
// Signals is the API response structure for the list Signals operation.
24+
type Signals struct {
25+
// Data is the list of returned signals.
26+
Data []Signal `json:"data"`
27+
// Meta is the information for total signals.
28+
Meta MetaSignals `json:"meta"`
29+
}
30+
31+
// MetaSignals is a subset of the signals response structure.
32+
type MetaSignals struct {
33+
// Limit is the limit of signals.
34+
Limit int `json:"limit"`
35+
// Total is the sum of signals.
36+
Total int `json:"total"`
37+
}
38+
39+
// Scope is the definition of the scope that a signal applies to.
40+
type Scope struct {
41+
// Type is the type of scope
42+
Type string `json:"type"`
43+
// AppliesTo defines what scope the signal applies to.
44+
AppliesTo []string `json:"applies_to"`
45+
}
46+
47+
// Reason is the signal that corresponds to the reason an event was triggered.
48+
type Reason struct {
49+
// Signal ID is the ID of the signal that triggered the event
50+
SignalID string `json:"signal_id"`
51+
// Count is the number of times this signal was detected
52+
Count int `json:"count"`
53+
}

0 commit comments

Comments
 (0)