github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/waf-premium/v1/rules/CreateReferenceTable.go (about)

     1  package rules
     2  
     3  import (
     4  	"github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
     6  	"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
     7  )
     8  
     9  type CreateReferenceTableOpts struct {
    10  	// Reference table name. The value can contain a maximum of 64 characters.
    11  	// Only digits, letters, hyphens (-), underscores (_), and periods (.) are allowed.
    12  	Name string `json:"name" required:"true"`
    13  	// Reference table type. For details, see the enumeration values as followed.
    14  	// Enumeration values:
    15  	// url
    16  	// params
    17  	// ip
    18  	// cookie
    19  	// referer
    20  	// user-agent
    21  	// header
    22  	// response_code
    23  	// response_header
    24  	// response_body
    25  	Type string `json:"type" required:"true"`
    26  	// Value of the reference table.
    27  	Values []string `json:"values"`
    28  }
    29  
    30  // CreateReferenceTable will create a reference table on the values in CreateOpts.
    31  func CreateReferenceTable(client *golangsdk.ServiceClient, opts CreateReferenceTableOpts) (*ReferenceTable, error) {
    32  	b, err := build.RequestBody(opts, "")
    33  	if err != nil {
    34  		return nil, err
    35  	}
    36  
    37  	// POST /v1/{project_id}/waf/valuelist
    38  	raw, err := client.Post(client.ServiceURL("waf", "valuelist"), b,
    39  		nil, &golangsdk.RequestOpts{
    40  			OkCodes:     []int{200},
    41  			MoreHeaders: map[string]string{"Content-Type": "application/json;charset=utf8"},
    42  		})
    43  	if err != nil {
    44  		return nil, err
    45  	}
    46  
    47  	var res ReferenceTable
    48  	err = extract.Into(raw.Body, &res)
    49  	return &res, err
    50  }
    51  
    52  type ReferenceTable struct {
    53  	// ID of a reference table.
    54  	ID string `json:"id"`
    55  	// Reference table name.
    56  	Name string `json:"name"`
    57  	// Type
    58  	Type string `json:"type"`
    59  	// Reference table timestamp.
    60  	CreatedAt int64 `json:"timestamp"`
    61  	// Value of the reference table.
    62  	Values []string `json:"values"`
    63  	// Reference table description.
    64  	Description string `json:"description"`
    65  	Producer    int    `json:"producer"`
    66  }