Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
52 changes: 52 additions & 0 deletions openstack/waf/v1/webtamperprotection_rules/requests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package webtamperprotection_rules

import (
"github.com/huaweicloud/golangsdk"
)

var RequestOpts golangsdk.RequestOpts = golangsdk.RequestOpts{
MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"},
}

// CreateOptsBuilder allows extensions to add additional parameters to the
// Create request.
type CreateOptsBuilder interface {
ToWebTamperCreateMap() (map[string]interface{}, error)
}

// CreateOpts contains all the values needed to create a new web tamper protection rule.
type CreateOpts struct {
Hostname string `json:"hostname" required:"true"`
Url string `json:"url" required:"true"`
}

// ToWebTamperCreateMap builds a create request body from CreateOpts.
func (opts CreateOpts) ToWebTamperCreateMap() (map[string]interface{}, error) {
return golangsdk.BuildRequestBody(opts, "")
}

// Create will create a new web tamper protection rule based on the values in CreateOpts.
func Create(c *golangsdk.ServiceClient, policyID string, opts CreateOptsBuilder) (r CreateResult) {
b, err := opts.ToWebTamperCreateMap()
if err != nil {
r.Err = err
return
}
reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}}
_, r.Err = c.Post(rootURL(c, policyID), b, &r.Body, reqOpt)
return
}

// Get retrieves a particular web tamper protection rule based on its unique ID.
func Get(c *golangsdk.ServiceClient, policyID, ruleID string) (r GetResult) {
_, r.Err = c.Get(resourceURL(c, policyID, ruleID), &r.Body, &RequestOpts)
return
}

// Delete will permanently delete a particular web tamper protection rule based on its unique ID.
func Delete(c *golangsdk.ServiceClient, policyID, ruleID string) (r DeleteResult) {
reqOpt := &golangsdk.RequestOpts{OkCodes: []int{204},
MoreHeaders: RequestOpts.MoreHeaders}
_, r.Err = c.Delete(resourceURL(c, policyID, ruleID), reqOpt)
return
}
47 changes: 47 additions & 0 deletions openstack/waf/v1/webtamperprotection_rules/results.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package webtamperprotection_rules

import (
"github.com/huaweicloud/golangsdk"
)

type WebTamper struct {
Id string `json:"id"`
PolicyID string `json:"policyid"`
Hostname string `json:"hostname"`
Url string `json:"url"`
}

type commonResult struct {
golangsdk.Result
}

// Extract is a function that accepts a result and extracts a web tamper protection rule.
func (r commonResult) Extract() (*WebTamper, error) {
var response WebTamper
err := r.ExtractInto(&response)
return &response, err
}

// CreateResult represents the result of a create operation. Call its Extract
// method to interpret it as a Web Tamper Protection rule.
type CreateResult struct {
commonResult
}

// UpdateResult represents the result of a update operation. Call its Extract
// method to interpret it as a Web Tamper Protection rule.
type UpdateResult struct {
commonResult
}

// GetResult represents the result of a get operation. Call its Extract
// method to interpret it as a Web Tamper Protection rule.
type GetResult struct {
commonResult
}

// DeleteResult represents the result of a delete operation. Call its ExtractErr
// method to determine if the request succeeded or failed.
type DeleteResult struct {
golangsdk.ErrResult
}
11 changes: 11 additions & 0 deletions openstack/waf/v1/webtamperprotection_rules/urls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package webtamperprotection_rules

import "github.com/huaweicloud/golangsdk"

func rootURL(c *golangsdk.ServiceClient, policy_id string) string {
return c.ServiceURL("policy", policy_id, "antitamper")
}

func resourceURL(c *golangsdk.ServiceClient, policy_id, id string) string {
return c.ServiceURL("policy", policy_id, "antitamper", id)
}