@@ -38,6 +38,9 @@ func (o *groupBuilder) ResourceType(ctx context.Context) *v2.ResourceType {
3838}
3939
4040func (o * groupBuilder ) List (ctx context.Context , parentResourceID * v2.ResourceId , pToken * pagination.Token ) ([]* v2.Resource , string , annotations.Annotations , error ) {
41+ if parentResourceID != nil {
42+ return nil , "" , nil , nil
43+ }
4144 var (
4245 groups []* client.Group
4346 outputAnnotations = annotations .New ()
@@ -58,14 +61,7 @@ func (o *groupBuilder) List(ctx context.Context, parentResourceID *v2.ResourceId
5861
5962 outResources := make ([]* v2.Resource , 0 , len (groups ))
6063 for _ , group := range groups {
61- shouldCreateResource , err := parentResourceIsParentGroup (group .ParentID , parentResourceID )
62- if err != nil {
63- return nil , "" , outputAnnotations , err
64- }
65-
66- if ! shouldCreateResource {
67- continue
68- }
64+ parentResourceID = getParentGroup (group .ParentID )
6965
7066 resource , err := groupResource (group , parentResourceID , o .client .IsOnPremise )
7167 if err != nil {
@@ -77,32 +73,20 @@ func (o *groupBuilder) List(ctx context.Context, parentResourceID *v2.ResourceId
7773 return outResources , nextPageToken , outputAnnotations , nil
7874}
7975
80- // parentResourceIsParentGroup validates that the parentResourceID received by the function call belongs to the corresponding parent group.
81- // The validation occurs between the ID on the group data (given by the API) and the ID of the parentResource.
8276// parentGroupId will be 0 (zero) if the group isn't a subgroup. parentResourceID will be nil if no parent resource was received in the List function.
8377// Both cases are checked and handled in this function.
84- func parentResourceIsParentGroup (parentGroupId int , parentResourceID * v2.ResourceId ) ( bool , error ) {
85- if parentGroupId != 0 && parentResourceID == nil {
78+ func getParentGroup (parentGroupId int ) * v2.ResourceId {
79+ if parentGroupId == 0 {
8680 // This path occurs on the first execution of the List func. When all groups are received from the API. Subgroups will be skipped.
87- return false , nil
81+ return nil
8882 }
8983
90- if parentResourceID == nil {
91- // If parentResourceID is null, is because it's a root group, not a subgroup, so there is no need to validate a parent group id, and it shouldn't be skipped.
92- return true , nil
84+ parentGroupIdStr := strconv .Itoa (parentGroupId )
85+ parentGroupResourceId := toGroupResourceId (parentGroupIdStr )
86+ return & v2.ResourceId {
87+ ResourceType : groupResourceType .Id ,
88+ Resource : parentGroupResourceId ,
9389 }
94-
95- parentIdSegments := strings .Split (parentResourceID .Resource , "/" )
96- if len (parentIdSegments ) < 2 {
97- return false , fmt .Errorf ("error while segmenting the parentResourceID: %v It has less than 2 segments" , parentResourceID )
98- }
99-
100- parentId , err := strconv .Atoi (parentIdSegments [1 ])
101- if err != nil {
102- return false , err
103- }
104-
105- return parentGroupId == parentId , nil
10690}
10791
10892func (o * groupBuilder ) Entitlements (_ context.Context , resource * v2.Resource , _ * pagination.Token ) ([]* v2.Entitlement , string , annotations.Annotations , error ) {
0 commit comments