From 04faf1fabada3613a764948b8a737a3e639a4d59 Mon Sep 17 00:00:00 2001 From: Zhenguo Niu Date: Thu, 27 Jun 2019 11:33:00 +0000 Subject: [PATCH] Add Web Tamper Protection Rule --- .../v1/webtamperprotection_rules/requests.go | 52 +++++++++++++++++++ .../v1/webtamperprotection_rules/results.go | 47 +++++++++++++++++ .../waf/v1/webtamperprotection_rules/urls.go | 11 ++++ 3 files changed, 110 insertions(+) create mode 100644 openstack/waf/v1/webtamperprotection_rules/requests.go create mode 100644 openstack/waf/v1/webtamperprotection_rules/results.go create mode 100644 openstack/waf/v1/webtamperprotection_rules/urls.go diff --git a/openstack/waf/v1/webtamperprotection_rules/requests.go b/openstack/waf/v1/webtamperprotection_rules/requests.go new file mode 100644 index 000000000..c9a49a659 --- /dev/null +++ b/openstack/waf/v1/webtamperprotection_rules/requests.go @@ -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 +} diff --git a/openstack/waf/v1/webtamperprotection_rules/results.go b/openstack/waf/v1/webtamperprotection_rules/results.go new file mode 100644 index 000000000..24181bff2 --- /dev/null +++ b/openstack/waf/v1/webtamperprotection_rules/results.go @@ -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 +} diff --git a/openstack/waf/v1/webtamperprotection_rules/urls.go b/openstack/waf/v1/webtamperprotection_rules/urls.go new file mode 100644 index 000000000..08ea399bf --- /dev/null +++ b/openstack/waf/v1/webtamperprotection_rules/urls.go @@ -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) +}