Skip to content

Commit

Permalink
Adding rule sets functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Bridget Lane authored and sethvargo committed Oct 26, 2017
1 parent 34f0b9f commit a3cdd36
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions fastly/waf.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,3 +435,72 @@ func (c *Client) GetWAFRuleVCL(i *GetWAFRuleVCLInput) (*RuleVCL, error) {
}
return &vcl, nil
}

// Ruleset is the information about a firewall object's ruleset.
type Ruleset struct {
ID string `jsonapi:"primary,ruleset"`
VCL string `jsonapi:"attr,vcl,omitempty"`
LastPush string `jsonapi:"attr,last_push,omitempty"`
}

// GetWAFRuleRuleSetsInput is used as input to the GetWAFRuleRuleSets function.
type GetWAFRuleRuleSetsInput struct {
// Service is the ID of the service. ID is the ID of the firewall.
// Both fields are required.
Service string
ID string
}

// GetWAFRuleRuleSets gets the VCL for rulesets associated with a firewall WAF.
func (c *Client) GetWAFRuleRuleSets(i *GetWAFRuleRuleSetsInput) (*Ruleset, error) {
if i.Service == "" {
return nil, ErrMissingService
}

if i.ID == "" {
return nil, ErrMissingWAFID
}

path := fmt.Sprintf("/service/%s/wafs/%s/ruleset", i.Service, i.ID)
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
}

var ruleset Ruleset
if err := jsonapi.UnmarshalPayload(resp.Body, &ruleset); err != nil {
return nil, err
}
return &ruleset, nil
}

// UpdateWAFRuleRuleSetsInput is used as input to the UpdateWafRuleSets function.
type UpdateWAFRuleRuleSetsInput struct {
// Service is the ID of the service. ID is the ID of the firewall.
// Both fields are required.
Service string
ID string `jsonapi:"primary,ruleset"`
}

// UpdateWafRuleSets updates the rulesets for a role associated with a firewall WAF.
func (c *Client) UpdateWafRuleSets(i *UpdateWAFRuleRuleSetsInput) (*Ruleset, error) {
if i.Service == "" {
return nil, ErrMissingService
}

if i.ID == "" {
return nil, ErrMissingWAFID
}

path := fmt.Sprintf("/service/%s/wafs/%s/ruleset", i.Service, i.ID)
resp, err := c.PatchJSONAPI(path, i, nil)
if err != nil {
return nil, err
}

var ruleset Ruleset
if err := jsonapi.UnmarshalPayload(resp.Body, &ruleset); err != nil {
return nil, err
}
return &ruleset, nil
}

0 comments on commit a3cdd36

Please sign in to comment.