github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/networking/v3/security/groups/results.go (about) 1 package groups 2 3 import ( 4 "github.com/chnsz/golangsdk/openstack/networking/v3/security/rules" 5 "github.com/chnsz/golangsdk/pagination" 6 ) 7 8 // SecurityGroup is a struct that represents the detail of the security group. 9 type SecurityGroup struct { 10 // Specifies the security group name. 11 Name string `json:"name"` 12 // Provides supplementary information about the security group. 13 Description string `json:"description"` 14 // Specifies the security group ID, which uniquely identifies the security group. 15 ID string `json:"id"` 16 // Specifies the resource ID of the VPC to which the security group belongs. 17 // Note: This parameter has been discarded, it is not recommended to use it. 18 VpcId string `json:"vpc_id"` 19 // Enterprise project ID, the default value is 0. 20 EnterpriseProjectId string `json:"enterprise_project_id"` 21 // Specifies the default security group rules, which ensure that resources in the security group can communicate 22 // with one another. 23 SecurityGroupRules []rules.SecurityGroupRule `json:"security_group_rules"` 24 // ID of the project to which the security group rule belongs. 25 ProjectId string `json:"project_id"` 26 // Security group creation time, in UTC format: yyyy-MM-ddTHH:mm:ss. 27 CreatedAt string `json:"created_at"` 28 // Security group rule udpate time, in UTC format: yyyy-MM-ddTHH:mm:ss. 29 UpdatedAt string `json:"updated_at"` 30 } 31 32 type SecurityGroupPage struct { 33 pagination.MarkerPageBase 34 } 35 36 // LastMarker method returns the last security group ID in a security group page. 37 func (p SecurityGroupPage) LastMarker() (string, error) { 38 secgroups, err := ExtractSecurityGroups(p) 39 if err != nil { 40 return "", err 41 } 42 if len(secgroups) == 0 { 43 return "", nil 44 } 45 return secgroups[len(secgroups)-1].ID, nil 46 } 47 48 // IsEmpty method checks whether the current security group page is empty. 49 func (p SecurityGroupPage) IsEmpty() (bool, error) { 50 secgroups, err := ExtractSecurityGroups(p) 51 return len(secgroups) == 0, err 52 } 53 54 // ExtractSecurityGroups is a method to extract the list of security group details. 55 func ExtractSecurityGroups(r pagination.Page) ([]SecurityGroup, error) { 56 var s []SecurityGroup 57 err := r.(SecurityGroupPage).Result.ExtractIntoSlicePtr(&s, "security_groups") 58 return s, err 59 }