Skip to content

Commit

Permalink
Method for fetching single WAF rule status
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich Abdill authored and sethvargo committed Dec 22, 2017
1 parent 959f73b commit 9ac3984
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## v0.4.3 (Unreleased)

- WAF methods added for fetching status of rules
- Add WAF methods for fetching status of rules, both one at a time and in lists
- Rename `UpdateWafRuleSets` function to `UpdateWAFRuleSets` to match other names

## v0.4.2 (September 5, 2017)
Expand All @@ -18,7 +18,7 @@

FEATURES:

- Add support for real-time stats [GH-48]
- Add support for real-time stats [GH-48]

## v0.3.0 (July 19, 2017)

Expand Down
32 changes: 31 additions & 1 deletion fastly/waf.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,6 @@ type paginationInfo struct {
// GetWAFRuleStatusesResponse is the data returned to the user from a GetWAFRuleStatus call
type GetWAFRuleStatusesResponse struct {
Rules []WAFRuleStatus
Links paginationInfo
}

// getPages parses a response to get the pagination data without destroying
Expand All @@ -771,3 +770,34 @@ func getPages(body io.ReadCloser) (paginationInfo, io.Reader, error) {
json.Unmarshal(bodyBytes, &pages)
return pages.Links, bytes.NewReader(buf.Bytes()), nil
}

// GetWAFRuleStatusInput specifies the parameters for the GetWAFRuleStatus call
type GetWAFRuleStatusInput struct {
ID int
Service string
WAF string
}

// GetWAFRuleStatus fetches the status of a single rule associated with a WAF.
func (c *Client) GetWAFRuleStatus(i *GetWAFRuleStatusInput) (WAFRuleStatus, error) {
if i.ID == 0 {
return WAFRuleStatus{}, ErrMissingRuleID
}
if i.Service == "" {
return WAFRuleStatus{}, ErrMissingService
}
if i.WAF == "" {
return WAFRuleStatus{}, ErrMissingWAFID
}

path := fmt.Sprintf("/service/%s/wafs/%s/rules/%d/rule_status", i.Service, i.WAF, i.ID)

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

var status receivedWAFRuleStatus
err = jsonapi.UnmarshalPayload(resp.Body, &status)
return status.simplify(), err
}

0 comments on commit 9ac3984

Please sign in to comment.