github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v1/security/securitygroups/results.go (about)

     1  package securitygroups
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/golangsdk/pagination"
     6  )
     7  
     8  type commonResult struct {
     9  	golangsdk.Result
    10  }
    11  
    12  type SecurityGroup struct {
    13  	// Specifies the security group name.
    14  	Name string `json:"name"`
    15  
    16  	// Provides supplementary information about the security group.
    17  	Description string `json:"description"`
    18  
    19  	// Specifies the security group ID, which uniquely identifies the
    20  	// security group.
    21  	ID string `json:"id"`
    22  
    23  	// Specifies the resource ID of the VPC to which the security
    24  	// group belongs.
    25  	VpcId string `json:"vpc_id"`
    26  
    27  	// Specifies the default security group rule, which ensures that
    28  	// hosts in the security group can communicate with one another.
    29  	SecurityGroupRules []SecurityGroupRule `json:"security_group_rules"`
    30  
    31  	EnterpriseProjectId string `json:"enterprise_project_id,omitempty"`
    32  }
    33  
    34  type SecurityGroupRule struct {
    35  	// Specifies the security group rule ID.
    36  	ID string `json:"id,omitempty"`
    37  
    38  	// Specifies the description.
    39  	Description string `json:"description,omitempty"`
    40  
    41  	// Specifies the security group ID.
    42  	SecurityGroupId string `json:"security_group_id,omitempty"`
    43  
    44  	// Specifies the direction of access control. The value can
    45  	// be?egress?or?ingress.
    46  	Direction string `json:"direction,omitempty"`
    47  
    48  	// Specifies the version of the Internet Protocol. The value can
    49  	// be?IPv4?or?IPv6.
    50  	Ethertype string `json:"ethertype,omitempty"`
    51  
    52  	// Specifies the protocol type. If the parameter is left blank,
    53  	// the security group supports all types of protocols. The value can be?icmp,?tcp,
    54  	// or?udp.
    55  	Protocol string `json:"protocol,omitempty"`
    56  
    57  	// Specifies the start port. The value ranges from 1 to 65,535.
    58  	// The value must be less than or equal to the value of?port_range_max. An empty value
    59  	// indicates all ports. If?protocol?is?icmp, the value range is determined by the
    60  	// ICMP-port range relationship table provided in Appendix A.2.
    61  	PortRangeMin *int `json:"port_range_min,omitempty"`
    62  
    63  	// Specifies the end port. The value ranges from 1 to 65,535. The
    64  	// value must be greater than or equal to the value of?port_range_min. An empty value
    65  	// indicates all ports. If?protocol?is?icmp, the value range is determined by the
    66  	// ICMP-port range relationship table provided in Appendix A.2.
    67  	PortRangeMax *int `json:"port_range_max,omitempty"`
    68  
    69  	// Specifies the remote IP address. If the access control
    70  	// direction is set to?egress, the parameter specifies the source IP address. If the
    71  	// access control direction is set to?ingress, the parameter specifies the destination
    72  	// IP address. The parameter is exclusive with parameter?remote_group_id. The value can
    73  	// be in the CIDR format or IP addresses.
    74  	RemoteIpPrefix string `json:"remote_ip_prefix,omitempty"`
    75  
    76  	// Specifies the ID of the peer security group. The value is
    77  	// exclusive with parameter?remote_ip_prefix.
    78  	RemoteGroupId string `json:"remote_group_id,omitempty"`
    79  }
    80  
    81  type CreateResult struct {
    82  	commonResult
    83  }
    84  
    85  func (r CreateResult) Extract() (*SecurityGroup, error) {
    86  	var entity SecurityGroup
    87  	err := r.ExtractIntoStructPtr(&entity, "security_group")
    88  	return &entity, err
    89  }
    90  
    91  type DeleteResult struct {
    92  	golangsdk.ErrResult
    93  }
    94  
    95  type GetResult struct {
    96  	commonResult
    97  }
    98  
    99  func (r GetResult) Extract() (*SecurityGroup, error) {
   100  	var entity SecurityGroup
   101  	err := r.ExtractIntoStructPtr(&entity, "security_group")
   102  	return &entity, err
   103  }
   104  
   105  type ListResult struct {
   106  	commonResult
   107  }
   108  
   109  func (r ListResult) Extract() (*[]SecurityGroup, error) {
   110  	var list []SecurityGroup
   111  	err := r.ExtractIntoSlicePtr(&list, "security_groups")
   112  	return &list, err
   113  }
   114  
   115  func (r SecurityGroupPage) IsEmpty() (bool, error) {
   116  	list, err := ExtractSecurityGroups(r)
   117  	return len(list) == 0, err
   118  }
   119  
   120  type SecurityGroupPage struct {
   121  	pagination.LinkedPageBase
   122  }
   123  
   124  func ExtractSecurityGroups(r pagination.Page) ([]SecurityGroup, error) {
   125  	var s struct {
   126  		SecurityGroups []SecurityGroup `json:"security_groups"`
   127  	}
   128  	err := r.(SecurityGroupPage).ExtractInto(&s)
   129  	return s.SecurityGroups, err
   130  }
   131  
   132  func (r SecurityGroupPage) NextPageURL() (string, error) {
   133  	s, err := ExtractSecurityGroups(r)
   134  	if err != nil {
   135  		return "", err
   136  	}
   137  	return r.WrapNextPageURL(s[len(s)-1].ID)
   138  }