github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/networking/v1/security/rules/results.go (about)

     1  package rules
     2  
     3  import "github.com/chnsz/golangsdk/pagination"
     4  
     5  // SecurityGroupRule is a struct that represents the detail of the security group rule.
     6  type SecurityGroupRule struct {
     7  	// Specifies the security group rule ID, which uniquely identifies the security group rule.
     8  	ID string `json:"id"`
     9  	// Provides supplementary information about the security group rule.
    10  	// The value can contain no more than 255 characters, including letters and digits.
    11  	Description string `json:"description"`
    12  	// Specifies the security group ID, which uniquely identifies the security group.
    13  	SecurityGroupId string `json:"security_group_id"`
    14  	// Specifies the direction of access control.
    15  	// Possible values are as follows:
    16  	//   egress
    17  	//   ingress
    18  	Direction string `json:"direction"`
    19  	// Specifies the protocol type. The value can be icmp, tcp, udp, icmpv6 or protocol number.
    20  	// If the parameter is left blank, all protocols are supported.
    21  	// When the protocol is icmpv6, the network type should be IPv6.
    22  	// when the protocol is icmp, the network type should be IPv4.
    23  	Protocol string `json:"protocol"`
    24  	// Specifies the IP protocol version. The value can be IPv4 or IPv6.
    25  	Ethertype string `json:"ethertype"`
    26  	// Specifies the start port number.
    27  	// The value ranges from 1 to 65535.
    28  	// The value cannot be greater than the port_range_max value. An empty value indicates all ports.
    29  	PortRangeMin int `json:"port_range_min"`
    30  	// Specifies the end port number.
    31  	// The value ranges from 1 to 65535.
    32  	// The value cannot be smaller than the port_range_min value. An empty value indicates all ports.
    33  	PortRangeMax int `json:"port_range_max"`
    34  	// Specifies the remote IP address.
    35  	// If the access control direction is set to egress, the parameter specifies the source IP address.
    36  	// If the access control direction is set to ingress, the parameter specifies the destination IP address.
    37  	// The value can be in the CIDR format or IP addresses.
    38  	// The parameter is exclusive with parameter remote_group_id.
    39  	RemoteIpPrefix string `json:"remote_ip_prefix"`
    40  	// Specifies the ID of the peer security group.
    41  	// The value is exclusive with parameter remote_ip_prefix.
    42  	RemoteGroupId string `json:"remote_group_id"`
    43  }
    44  
    45  type SecurityGroupRulePage struct {
    46  	pagination.MarkerPageBase
    47  }
    48  
    49  // LastMarker method returns the last security group rule ID in a SecurityGroupRulePage.
    50  func (p SecurityGroupRulePage) LastMarker() (string, error) {
    51  	secgroups, err := ExtractSecurityGroupRules(p)
    52  	if err != nil {
    53  		return "", err
    54  	}
    55  	if len(secgroups) == 0 {
    56  		return "", nil
    57  	}
    58  	return secgroups[len(secgroups)-1].ID, nil
    59  }
    60  
    61  // IsEmpty method checks whether the current SecurityGroupRulePage is empty.
    62  func (p SecurityGroupRulePage) IsEmpty() (bool, error) {
    63  	secgroups, err := ExtractSecurityGroupRules(p)
    64  	return len(secgroups) == 0, err
    65  }
    66  
    67  // ExtractSecurityGroupRules is a method to extract the list of security group rule details.
    68  func ExtractSecurityGroupRules(r pagination.Page) ([]SecurityGroupRule, error) {
    69  	var s []SecurityGroupRule
    70  	r.(SecurityGroupRulePage).Result.ExtractIntoSlicePtr(&s, "security_group_rules")
    71  	return s, nil
    72  }