Skip to content

Commit

Permalink
satisfy linter
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 committed Feb 3, 2025
1 parent ff87efa commit de2aee0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
12 changes: 9 additions & 3 deletions cmd/metal-api/internal/datastore/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type IPSearchQuery struct {
}

// GenerateTerm generates the project search query term.
func (p *IPSearchQuery) generateTerm(rs *RethinkStore) *r.Term {
func (p *IPSearchQuery) generateTerm(rs *RethinkStore) (*r.Term, error) {
q := *rs.ipTable()

if p.IPAddress != nil {
Expand Down Expand Up @@ -88,14 +88,16 @@ func (p *IPSearchQuery) generateTerm(rs *RethinkStore) *r.Term {
separator = "\\."
case metal.IPv6AddressFamily:
separator = ":"
case metal.InvalidAddressFamily:
return nil, fmt.Errorf("given addressfamily is invalid:%s", af)
}

q = q.Filter(func(row r.Term) r.Term {
return row.Field("id").Match(separator)
})
}

return &q
return &q, nil
}

// FindIPByID returns an ip of a given id.
Expand All @@ -110,7 +112,11 @@ func (rs *RethinkStore) FindIPByID(id string) (*metal.IP, error) {

// SearchIPs returns the result of the ips search request query.
func (rs *RethinkStore) SearchIPs(q *IPSearchQuery, ips *metal.IPs) error {
return rs.searchEntities(q.generateTerm(rs), ips)
term, err := q.generateTerm(rs)
if err != nil {
return err
}
return rs.searchEntities(term, ips)
}

// ListIPs returns all ips.
Expand Down
2 changes: 2 additions & 0 deletions cmd/metal-api/internal/datastore/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ func (p *NetworkSearchQuery) generateTerm(rs *RethinkStore) (*r.Term, error) {
separator = "\\."
case metal.IPv6AddressFamily:
separator = ":"
case metal.InvalidAddressFamily:
return nil, fmt.Errorf("given addressfamily is invalid:%s", af)
}

q = q.Filter(func(row r.Term) r.Term {
Expand Down
2 changes: 2 additions & 0 deletions cmd/metal-api/internal/service/network-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,8 @@ func (r *networkResource) getNetworkUsage(ctx context.Context, nw *metal.Network
consumption.IPv6.UsedIPs += u.UsedIPs
consumption.IPv6.AvailablePrefixes += u.AvailablePrefixes
consumption.IPv6.UsedPrefixes += u.UsedPrefixes
case metal.InvalidAddressFamily:
return nil, fmt.Errorf("given addressfamily is invalid:%s", af)
}

}
Expand Down

0 comments on commit de2aee0

Please sign in to comment.