github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/apigw/apis/requests.go (about)

     1  package apis
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  )
     6  
     7  type VpcChannel struct {
     8  	VpcId        string `json:"vpc_id" required:"true"`
     9  	VpcProxyHost string `json:"vpc_proxy_host,omitempty"`
    10  }
    11  
    12  type BackendOpts struct {
    13  	Protocol     string     `json:"req_protocol" required:"true"`
    14  	Method       string     `json:"req_method" required:"true"`
    15  	Uri          string     `json:"req_uri" required:"true"`
    16  	Timeout      int        `json:"timeout" required:"true"`
    17  	VpcStatus    int        `json:"vpc_status,omitempty"`
    18  	VpcInfo      VpcChannel `json:"vpc_info,omitempty"`
    19  	UrlDomain    string     `json:"url_domain,omitempty"`
    20  	Version      string     `json:"version,omitempty"`
    21  	Remark       string     `json:"remark,omitempty"`
    22  	AuthorizerId string     `json:"authorizer_id,omitempty"`
    23  }
    24  type FunctionOpts FunctionInfo
    25  type MockOpts MockInfo
    26  
    27  // CreateOptsBuilder allows extensions to add additional parameters to the
    28  // Create request.
    29  type CreateOptsBuilder interface {
    30  	ToAPICreateMap() (map[string]interface{}, error)
    31  }
    32  
    33  // CreateOpts contains options for creating a API. This object is passed to
    34  // the APIs Create function.
    35  type CreateOpts struct {
    36  	// ID of the API group to which the API to be created will belong
    37  	// The value cannot be modified when updating
    38  	GroupId string `json:"group_id" required:"true"`
    39  	// Name of the API
    40  	Name string `json:"name" required:"true"`
    41  	// Type of the API. 1: public, 2: private
    42  	Type int `json:"type" required:"true"`
    43  	// Request method
    44  	ReqMethod string `json:"req_method" required:"true"`
    45  	// Access address
    46  	ReqUri string `json:"req_uri" required:"true"`
    47  	// Request protocol, defaults to HTTPS
    48  	ReqProtocol string `json:"req_protocol,omitempty"`
    49  	// Request parameter list
    50  	ReqParams []RequestParameter `json:"req_params,omitempty"`
    51  	// Security authentication mode, which can be: None, App and IAM
    52  	AuthType string `json:"auth_type" required:"true"`
    53  	// backend type, which can be: HTTP, Function and MOCK
    54  	BackendType string `json:"backend_type" required:"true"`
    55  	// Backend parameter list
    56  	BackendParams []BackendParameter `json:"backend_params,omitempty"`
    57  	//Web backend details
    58  	BackendOpts BackendOpts `json:"backend_api,omitempty"`
    59  	// FunctionGraph backend details
    60  	FunctionOpts FunctionOpts `json:"func_info,omitempty"`
    61  	// Mock backend details
    62  	MockOpts MockOpts `json:"mock_info,omitempty"`
    63  	// Example response for a successful request
    64  	ResultNormalSample string `json:"result_normal_sample" required:"true"`
    65  	// Example response for a failed request
    66  	ResultFailureSample string `json:"result_failure_sample,omitempty"`
    67  	// ID of customer authorizer
    68  	AuthorizerId string `json:"authorizer_id,omitempty"`
    69  	// Version of the API
    70  	Version string `json:"version,omitempty"`
    71  	// Route matching mode
    72  	MatchMode string `json:"match_mode,omitempty"`
    73  	// Description of the API
    74  	Remark string `json:"remark,omitempty"`
    75  	// tags of the API
    76  	Tags []string `json:"tags,omitempty"`
    77  	// Description of the API request body
    78  	BodyRemark string `json:"body_remark,omitempty"`
    79  	// whether CORS is supported
    80  	Cors bool `json:"cors,omitempty"`
    81  }
    82  
    83  // ToAPICreateMap assembles a request body based on the contents of a
    84  // CreateOpts.
    85  func (opts CreateOpts) ToAPICreateMap() (map[string]interface{}, error) {
    86  	return golangsdk.BuildRequestBody(opts, "")
    87  }
    88  
    89  // Create will create a new API based on the values in CreateOpts.
    90  func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
    91  	b, err := opts.ToAPICreateMap()
    92  	if err != nil {
    93  		r.Err = err
    94  		return
    95  	}
    96  	_, r.Err = client.Post(createURL(client), b, &r.Body, &golangsdk.RequestOpts{
    97  		OkCodes: []int{201},
    98  	})
    99  	return
   100  }
   101  
   102  // Update will update the API with provided information. To extract the updated
   103  // API from the response, call the Extract method on the UpdateResult.
   104  // parameters of update is same with parameters of create. (group_id cannot be modified)
   105  func Update(client *golangsdk.ServiceClient, id string, opts CreateOptsBuilder) (r UpdateResult) {
   106  	b, err := opts.ToAPICreateMap()
   107  	if err != nil {
   108  		r.Err = err
   109  		return
   110  	}
   111  	_, r.Err = client.Put(groupURL(client, id), b, &r.Body, &golangsdk.RequestOpts{
   112  		OkCodes: []int{200},
   113  	})
   114  	return
   115  }
   116  
   117  // Delete will delete the existing API with the provided ID.
   118  func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) {
   119  	_, r.Err = client.Delete(groupURL(client, id), nil)
   120  	return
   121  }
   122  
   123  // Get retrieves the API with the provided ID. To extract the API object
   124  // from the response, call the Extract method on the GetResult.
   125  func Get(client *golangsdk.ServiceClient, id string) (r GetResult) {
   126  	_, r.Err = client.Get(groupURL(client, id), &r.Body, nil)
   127  	return
   128  }