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
7 changes: 7 additions & 0 deletions openstack/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,13 @@ func NewCCE(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golan
return sc, err
}

// NewWAF creates a ServiceClient that may be used to access the WAF service.
func NewWAFV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "waf")
sc.ResourceBase = sc.Endpoint + "v1/" + client.ProjectID + "/waf/"
return sc, err
}

func NewSDKClient(c *golangsdk.ProviderClient, eo golangsdk.EndpointOpts, serviceType string) (*golangsdk.ServiceClient, error) {
switch serviceType {
case "mls":
Expand Down
85 changes: 85 additions & 0 deletions openstack/waf/v1/certificates/requests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package certificates

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 {
ToCertCreateMap() (map[string]interface{}, error)
}

// CreateOpts contains all the values needed to create a new certificate.
type CreateOpts struct {
//Certificate name
Name string `json:"name" required:"true"`
//Certificate content
Content string `json:"content" required:"true"`
//Private Key
Key string `json:"key" required:"true"`
}

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

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

// UpdateOptsBuilder allows extensions to add additional parameters to the
// Update request.
type UpdateOptsBuilder interface {
ToCertUpdateMap() (map[string]interface{}, error)
}

// UpdateOpts contains all the values needed to update a certificate.
type UpdateOpts struct {
//Certificate name
Name string `json:"name,omitempty"`
}

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

// Update accepts a UpdateOpts struct and uses the values to update a certificate.The response code from api is 200
func Update(c *golangsdk.ServiceClient, certID string, opts UpdateOptsBuilder) (r UpdateResult) {
b, err := opts.ToCertUpdateMap()
if err != nil {
r.Err = err
return
}
reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}}
_, r.Err = c.Put(resourceURL(c, certID), b, nil, reqOpt)
return
}

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

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

import (
"time"

"github.com/huaweicloud/golangsdk"
)

type Certificate struct {
//Certificate ID
Id string `json:"id"`
//Certificate Name
Name string `json:"name"`
//When the certificate expires
ExpireTime time.Time `json:"expireTime"`
}

type commonResult struct {
golangsdk.Result
}

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

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

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

// GetResult represents the result of a get operation. Call its Extract
// method to interpret it as a Certificate.
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/certificates/urls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package certificates

import "github.com/huaweicloud/golangsdk"

func rootURL(c *golangsdk.ServiceClient) string {
return c.ServiceURL("certificate")
}

func resourceURL(c *golangsdk.ServiceClient, id string) string {
return c.ServiceURL("certificate", id)
}
110 changes: 110 additions & 0 deletions openstack/waf/v1/domains/requests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package domains

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 {
ToDomainCreateMap() (map[string]interface{}, error)
}

// CreateOpts contains all the values needed to create a new backup.
type CreateOpts struct {
//Domain name
HostName string `json:"hostname" required:"true"`
//Certificate ID
CertificateId string `json:"certificateid,omitempty"`
//The original server information
Server []ServerOpts `json:"server" required:"true"`
//Whether proxy is configured
Proxy *bool `json:"proxy" required:"true"`
//The type of the source IP header
SipHeaderName string `json:"sip_header_name,omitempty"`
//The HTTP request header for identifying the real source IP.
SipHeaderList []string `json:"sip_header_list,omitempty"`
}

type ServerOpts struct {
//Protocol type of the client
FrontProtocol string `json:"front_protocol" required:"true"`
//Protocol used by WAF to forward client requests to the server
BackProtocol string `json:"back_protocol" required:"true"`
//IP address or domain name of the web server that the client accesses.
Address string `json:"address" required:"true"`
//Port number used by the web server
Port string `json:"port" required:"true"`
}

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

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

// UpdateOptsBuilder allows extensions to add additional parameters to the
// Update request.
type UpdateOptsBuilder interface {
ToDomainUpdateMap() (map[string]interface{}, error)
}

// UpdateOpts contains all the values needed to update a Domain.
type UpdateOpts struct {
//Certificate ID
CertificateId string `json:"certificateid,omitempty"`
//The original server information
Server []ServerOpts `json:"server,omitempty"`
//Whether proxy is configured
Proxy *bool `json:"proxy,omitempty"`
//The type of the source IP header
SipHeaderName string `json:"sip_header_name,omitempty"`
//The HTTP request header for identifying the real source IP.
SipHeaderList []string `json:"sip_header_list,omitempty"`
}

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

// Update accepts a UpdateOpts struct and uses the values to update a Domain.The response code from api is 200
func Update(c *golangsdk.ServiceClient, domainID string, opts UpdateOptsBuilder) (r UpdateResult) {
b, err := opts.ToDomainUpdateMap()
if err != nil {
r.Err = err
return
}
reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}}
_, r.Err = c.Put(resourceURL(c, domainID), b, nil, reqOpt)
return
}

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

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

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

type Domain struct {
//Domain ID
Id string `json:"id"`
//Domain name
HostName string `json:"hostname"`
//Access Code
AccessCode string `json:"access_code"`
//CNAME value
Cname string `json:"cname"`
//TXT record
TxtCode string `json:"txt_code"`
//Sub Domain name
SubDomain string `json:"sub_domain"`
//Policy ID
PolicyID string `json:"policy_id"`
//WAF mode
ProtectStatus int `json:"protect_status"`
//Whether a domain name is connected to WAF
AccessStatus int `json:"access_status"`
//Protocol type
Protocol string `json:"protocol"`
//Certificate ID
CertificateId string `json:"certificateid"`
//The original server information
Server []Server `json:"server"`
//Whether proxy is configured
Proxy bool `json:"proxy"`
//The type of the source IP header
SipHeaderName string `json:"sip_header_name"`
//The HTTP request header for identifying the real source IP.
SipHeaderList []string `json:"sip_header_list"`
}

type Server struct {
//Protocol type of the client
FrontProtocol string `json:"front_protocol" required:"true"`
//Protocol used by WAF to forward client requests to the server
BackProtocol string `json:"back_protocol" required:"true"`
//IP address or domain name of the web server that the client accesses.
Address string `json:"address" required:"true"`
//Port number used by the web server
Port int `json:"port" required:"true"`
}

type commonResult struct {
golangsdk.Result
}

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

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

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

// GetResult represents the result of a get operation. Call its Extract
// method to interpret it as a Domain.
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/domains/urls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package domains

import "github.com/huaweicloud/golangsdk"

func rootURL(c *golangsdk.ServiceClient) string {
return c.ServiceURL("instance")
}

func resourceURL(c *golangsdk.ServiceClient, id string) string {
return c.ServiceURL("instance", id)
}
Loading