Skip to content

Commit

Permalink
fix(group): Ignore empty resolve values in referencers
Browse files Browse the repository at this point in the history
Signed-off-by: Maximilian Blatt <[email protected]>
  • Loading branch information
MisterMX committed Jan 31, 2024
1 parent 947dabf commit 64d06d3
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions apis/groups/v1alpha1/referencers.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,13 @@ func fromPtrValue(v *int) string {
}

// resolve string value to int pointer
func toPtrValue(v string) *int {
func toPtrValue(v string) (*int, error) {
if v == "" {
return nil
return nil, nil
}

r, err := strconv.Atoi(v)
if err != nil {
return nil
}

return &r
return &r, err
}

// ResolveReferences of this Variable
Expand All @@ -64,7 +60,12 @@ func (mg *Variable) ResolveReferences(ctx context.Context, c client.Reader) erro
return errors.Wrap(err, "spec.forProvider.groupId")
}

mg.Spec.ForProvider.GroupID = toPtrValue(rsp.ResolvedValue)
resolvedId, err := toPtrValue(rsp.ResolvedValue)
if err != nil {
return errors.Wrap(err, "spec.forProvider.groupId")
}

mg.Spec.ForProvider.GroupID = resolvedId
mg.Spec.ForProvider.GroupIDRef = rsp.ResolvedReference

return nil
Expand All @@ -87,7 +88,12 @@ func (mg *Member) ResolveReferences(ctx context.Context, c client.Reader) error
return errors.Wrap(err, "spec.forProvider.groupId")
}

mg.Spec.ForProvider.GroupID = toPtrValue(rsp.ResolvedValue)
resolvedId, err := toPtrValue(rsp.ResolvedValue)
if err != nil {
return errors.Wrap(err, "spec.forProvider.groupId")
}

mg.Spec.ForProvider.GroupID = resolvedId
mg.Spec.ForProvider.GroupIDRef = rsp.ResolvedReference

return nil
Expand All @@ -110,7 +116,12 @@ func (mg *DeployToken) ResolveReferences(ctx context.Context, c client.Reader) e
return errors.Wrap(err, "spec.forProvider.groupId")
}

mg.Spec.ForProvider.GroupID = toPtrValue(rsp.ResolvedValue)
resolvedId, err := toPtrValue(rsp.ResolvedValue)
if err != nil {
return errors.Wrap(err, "spec.forProvider.groupId")
}

mg.Spec.ForProvider.GroupID = resolvedId
mg.Spec.ForProvider.GroupIDRef = rsp.ResolvedReference

return nil
Expand Down Expand Up @@ -143,12 +154,12 @@ func (mg *Group) ResolveReferences(ctx context.Context, c client.Reader) error {
return errors.Wrap(err, "mg.Spec.ForProvider.ParentID")
}

id, err := strconv.Atoi(rsp.ResolvedValue)
id, err := toPtrValue(rsp.ResolvedValue)
if err != nil {
return errors.Wrap(err, "mg.Spec.ForProvider.ParentID")
}

mg.Spec.ForProvider.ParentID = &id
mg.Spec.ForProvider.ParentID = id
mg.Spec.ForProvider.ParentIDRef = rsp.ResolvedReference

for i3 := 0; i3 < len(mg.Spec.ForProvider.SharedWithGroups); i3++ {
Expand All @@ -167,11 +178,11 @@ func (mg *Group) ResolveReferences(ctx context.Context, c client.Reader) error {
return errors.Wrap(err, "mg.Spec.ForProvider.SharedWithGroups[i3].GroupID")
}

id, err = strconv.Atoi(rsp.ResolvedValue)
id, err := toPtrValue(rsp.ResolvedValue)
if err != nil {
return errors.Wrap(err, "mg.Spec.ForProvider.SharedWithGroups[i3].GroupID")
}
mg.Spec.ForProvider.SharedWithGroups[i3].GroupID = &id
mg.Spec.ForProvider.SharedWithGroups[i3].GroupID = id
mg.Spec.ForProvider.SharedWithGroups[i3].GroupIDRef = rsp.ResolvedReference

}
Expand Down

0 comments on commit 64d06d3

Please sign in to comment.