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

     1  package hosts
     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 CreateOpts struct {
    10  	// HTTPS certificate ID.
    11  	// It can be obtained by calling the ListCertificates API.
    12  	// This parameter is not required when the client protocol is HTTP,
    13  	// but it is mandatory when the client protocol is HTTPS.
    14  	CertificateId string `json:"certificateid"`
    15  	// Certificate name.
    16  	// Certifacteid and certificatename are required at the same.
    17  	// If certificateid does not match certificatename, an error is reported.
    18  	// This parameter is not required when the client protocol is HTTP,
    19  	// but it is mandatory when the client protocol is HTTPS.
    20  	CertificateName string `json:"certificatename"`
    21  	// Protected domain name or IP address (port allowed)
    22  	Hostname string `json:"hostname" required:"true"`
    23  	// Whether a proxy is used for the domain name.
    24  	// If your website has no layer-7 proxy server
    25  	// such as CDN and cloud acceleration service deployed
    26  	// in front of WAF and uses only layer-4 load balancers
    27  	// (or NAT), set Proxy Configured to No. Otherwise,
    28  	// Proxy Configured must be set to Yes.
    29  	// This ensures that WAF obtains real IP addresses of website
    30  	// visitors and takes protective actions configured in
    31  	// protection policies.
    32  	Proxy *bool `json:"proxy" required:"true"`
    33  	// ID of the policy initially used to the domain name.
    34  	// It can be obtained by calling the API described in 2.1.1
    35  	// Querying Protection Policies.
    36  	PolicyId string `json:"policyid"`
    37  	// Server configuration in dedicated mode
    38  	Server []PremiumWafServer `json:"server" required:"true"`
    39  	// Website name
    40  	WebTag string `json:"web_tag"`
    41  	// Description
    42  	Description string `json:"description"`
    43  }
    44  
    45  type PremiumWafServer struct {
    46  	// Client protocol
    47  	// Enumeration values:
    48  	// HTTP
    49  	// HTTPS
    50  	FrontProtocol string `json:"front_protocol" required:"true"`
    51  	// Server protocol
    52  	// Enumeration values:
    53  	// HTTP
    54  	// HTTPS
    55  	BackProtocol string `json:"back_protocol" required:"true"`
    56  	// IP address or domain name of the origin server that the client accesses.
    57  	Address string `json:"address" required:"true"`
    58  	// Server port
    59  	Port int `json:"port" required:"true"`
    60  	// The origin server address is an IPv4 or IPv6 address. Default value: ipv4
    61  	// Enumeration values:
    62  	// ipv4
    63  	// ipv6
    64  	Type string `json:"type" required:"true"`
    65  	// VPC ID. Perform the following steps to obtain the VPC ID:
    66  	// 1.Find the name of the VPC where the dedicated engine is located. The VPC name is in the VPC\Subnet column. Log in to the WAF console and choose Instance Management > Dedicated Engine > VPC\Subnet.
    67  	// Log in to the VPC console and click the VPC name. On the page displayed, copy the VPC ID in the VPC Information area.
    68  	VpcId string `json:"vpc_id" required:"true"`
    69  	// Weight can be ignored by now
    70  	Weight int `json:"weight"`
    71  }
    72  
    73  // Create will create a new Protected Domain Name on the values in CreateOpts.
    74  func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*HostResponse, error) {
    75  	b, err := build.RequestBody(opts, "")
    76  	if err != nil {
    77  		return nil, err
    78  	}
    79  
    80  	// POST /v1/{project_id}/premium-waf/host
    81  	raw, err := client.Post(client.ServiceURL("premium-waf", "host"), b,
    82  		nil, &golangsdk.RequestOpts{
    83  			OkCodes: []int{200},
    84  		})
    85  	if err != nil {
    86  		return nil, err
    87  	}
    88  
    89  	var res HostResponse
    90  	err = extract.Into(raw.Body, &res)
    91  	return &res, err
    92  }
    93  
    94  type HostResponse struct {
    95  	// Protected domain name ID
    96  	ID string `json:"id"`
    97  	// Policy ID
    98  	PolicyId string `json:"policyid"`
    99  	// Protected domain name
   100  	Hostname string `json:"hostname"`
   101  	// Tenant ID
   102  	DomainId string `json:"domainid"`
   103  	// Project ID
   104  	ProjectId string `json:"projectid"`
   105  	// HTTP protocol
   106  	Protocol string `json:"protocol"`
   107  	// WAF status of the protected domain name.
   108  	// -1: Bypassed. Requests are directly sent to the backend servers without passing through WAF.
   109  	// 0: Suspended. WAF only forwards requests for the domain name but does not detect attacks.
   110  	// -1: Enabled. WAF detects attacks based on the configured policy.
   111  	ProtectStatus int `json:"protect_status"`
   112  	// Whether a domain name is connected to WAF.
   113  	// 0: disconnected
   114  	// 1: connected
   115  	AccessStatus int `json:"access_status"`
   116  	// Whether a proxy is used.
   117  	// true: The proxy is enabled.
   118  	// false: The proxy is disabled.
   119  	Proxy bool `json:"proxy"`
   120  	// Origin server list
   121  	Server []ServerResponse `json:"server"`
   122  	// Special domain name identifier, which is used to store additional domain name configuration.
   123  	Flag *FlagObject `json:"flag"`
   124  	// Alarm configuration page
   125  	BlockPage *BlockPageResponse `json:"block_page"`
   126  	// Not described
   127  	Extend *ExtendResponse `json:"extend"`
   128  	// Creation time.
   129  	CreatedAt int `json:"timestamp"`
   130  	// Website name
   131  	WebTag string `json:"web_tag"`
   132  	// Description
   133  	Description string `json:"description"`
   134  	// This parameter is reserved, which will be used to freeze a domain name.
   135  	// Default: 0
   136  	Locked int `json:"locked"`
   137  }
   138  
   139  type ServerResponse struct {
   140  	// Client protocol
   141  	// Enumeration values:
   142  	// HTTP
   143  	// HTTPS
   144  	FrontProtocol string `json:"front_protocol"`
   145  	// Server protocol
   146  	// Enumeration values:
   147  	// HTTP
   148  	// HTTPS
   149  	BackProtocol string `json:"back_protocol"`
   150  	// IP address or domain name of the origin server that the client accesses.
   151  	Address string `json:"address"`
   152  	// Server port
   153  	Port int `json:"port"`
   154  	// The origin server address is an IPv4 or IPv6 address. Default value: ipv4
   155  	// Enumeration values:
   156  	// ipv4
   157  	// ipv6
   158  	Type string `json:"type"`
   159  	// VPC ID. Perform the following steps to obtain the VPC ID:
   160  	// 1.Find the name of the VPC where the dedicated engine is located. The VPC name is in the VPC\Subnet column. Log in to the WAF console and choose Instance Management > Dedicated Engine > VPC\Subnet.
   161  	// Log in to the VPC console and click the VPC name. On the page displayed, copy the VPC ID in the VPC Information area.
   162  	VpcId string `json:"vpc_id"`
   163  	// Weight can be ignored by now
   164  	Weight int `json:"weight"`
   165  }
   166  
   167  type FlagObject struct {
   168  	// Whether PCI 3DS certification check is enabled for the domain name. Currently, this function is not supported. The default value is false. You can ignore this parameter.
   169  	// true: PCI 3DS check is enabled.
   170  	// false: PCI 3DS check is disabled.
   171  	Pci3ds string `json:"pci_3ds"`
   172  	// Whether PCI DDS certification check is enabled for the domain name.
   173  	// true: PCI DDS check is enabled.
   174  	// false: PCI DDS check is disabled.
   175  	PciDss string `json:"pci_dss"`
   176  }
   177  
   178  type BlockPageResponse struct {
   179  	// Template name
   180  	Template string `json:"template"`
   181  	// Custom alarm page
   182  	CustomPage *CustomPageResponse `json:"custom_page"`
   183  	// Redirection URL
   184  	RedirectUrl string `json:"redirect_url"`
   185  }
   186  
   187  type CustomPageResponse struct {
   188  	StatusCode  string `json:"status_code"`
   189  	ContentType string `json:"content_type"`
   190  	Content     string `json:"content"`
   191  }
   192  
   193  type ExtendResponse struct {
   194  	// Details about LTS configuration
   195  	LtsConfig string `json:"ltsInfo"`
   196  	// Timeout configuration details.
   197  	TimeoutConfig string `json:"extend"`
   198  }