github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/waf_hw/v1/datamasking_rules/requests.go (about) 1 /* 2 Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved. 3 */ 4 5 package datamasking_rules 6 7 import ( 8 "github.com/huaweicloud/golangsdk" 9 ) 10 11 var RequestOpts golangsdk.RequestOpts = golangsdk.RequestOpts{ 12 MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"}, 13 } 14 15 // CreateOptsBuilder allows extensions to add additional parameters to the 16 // Create request. 17 type CreateOptsBuilder interface { 18 ToDataMaskingCreateMap() (map[string]interface{}, error) 19 } 20 21 // CreateOpts contains all the values needed to create a new datamasking rule. 22 type CreateOpts struct { 23 Path string `json:"url" required:"true"` 24 Category string `json:"category" required:"true"` 25 Index string `json:"index" required:"true"` 26 Description string `json:"description,omitempty"` 27 } 28 29 // ToDataMaskingCreateMap builds a create request body from CreateOpts. 30 func (opts CreateOpts) ToDataMaskingCreateMap() (map[string]interface{}, error) { 31 return golangsdk.BuildRequestBody(opts, "") 32 } 33 34 // Create will create a new datamasking rule based on the values in CreateOpts. 35 func Create(c *golangsdk.ServiceClient, policyID string, opts CreateOptsBuilder) (r CreateResult) { 36 b, err := opts.ToDataMaskingCreateMap() 37 if err != nil { 38 r.Err = err 39 return 40 } 41 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 42 _, r.Err = c.Post(rootURL(c, policyID), b, &r.Body, reqOpt) 43 return 44 } 45 46 // UpdateOptsBuilder allows extensions to add additional parameters to the 47 // Update request. 48 type UpdateOptsBuilder interface { 49 ToDataMaskingUpdateMap() (map[string]interface{}, error) 50 } 51 52 // UpdateOpts contains all the values needed to update a datamasking rule. 53 type UpdateOpts struct { 54 Path string `json:"url" required:"true"` 55 Category string `json:"category" required:"true"` 56 Index string `json:"index" required:"true"` 57 Description string `json:"description,omitempty"` 58 } 59 60 // ToDataMaskingUpdateMap builds a update request body from UpdateOpts. 61 func (opts UpdateOpts) ToDataMaskingUpdateMap() (map[string]interface{}, error) { 62 return golangsdk.BuildRequestBody(opts, "") 63 } 64 65 // Update accepts a UpdateOpts struct and uses the values to update a rule.The response code from api is 200 66 func Update(c *golangsdk.ServiceClient, policyID, ruleID string, opts UpdateOptsBuilder) (r UpdateResult) { 67 b, err := opts.ToDataMaskingUpdateMap() 68 if err != nil { 69 r.Err = err 70 return 71 } 72 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 73 _, r.Err = c.Put(resourceURL(c, policyID, ruleID), b, nil, reqOpt) 74 return 75 } 76 77 // Get retrieves a particular datamasking rule based on its unique ID. 78 func Get(c *golangsdk.ServiceClient, policyID, ruleID string) (r GetResult) { 79 reqOpt := &golangsdk.RequestOpts{ 80 MoreHeaders: RequestOpts.MoreHeaders, 81 } 82 83 _, r.Err = c.Get(resourceURL(c, policyID, ruleID), &r.Body, reqOpt) 84 return 85 } 86 87 // Delete will permanently delete a particular datamasking rule based on its unique ID. 88 func Delete(c *golangsdk.ServiceClient, policyID, ruleID string) (r DeleteResult) { 89 reqOpt := &golangsdk.RequestOpts{ 90 OkCodes: []int{200}, 91 MoreHeaders: RequestOpts.MoreHeaders, 92 } 93 _, r.Err = c.Delete(resourceURL(c, policyID, ruleID), reqOpt) 94 return 95 }