-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some scoping on some resources somewhere.
- Loading branch information
Showing
9 changed files
with
257 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package queries | ||
|
||
import ( | ||
"fmt" | ||
|
||
apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" | ||
"github.com/metal-stack/metal-lib/pkg/tag" | ||
|
||
r "gopkg.in/rethinkdb/rethinkdb-go.v6" | ||
) | ||
|
||
func IpProjectScoped(project string) func(q r.Term) r.Term { | ||
return func(q r.Term) r.Term { | ||
return q.Filter(func(row r.Term) r.Term { | ||
return row.Field("projectid").Eq(project) | ||
}) | ||
} | ||
} | ||
|
||
func IpFilter(rq *apiv2.IPServiceListRequest) func(q r.Term) r.Term { | ||
return func(q r.Term) r.Term { | ||
// Project is mandatory | ||
q = q.Filter(func(row r.Term) r.Term { | ||
return row.Field("projectid").Eq(rq.Project) | ||
}) | ||
|
||
if rq.Ip != nil { | ||
q = q.Filter(func(row r.Term) r.Term { | ||
return row.Field("id").Eq(*rq.Ip) | ||
}) | ||
} | ||
|
||
if rq.Uuid != nil { | ||
q = q.Filter(func(row r.Term) r.Term { | ||
return row.Field("allocationuuid").Eq(*rq.Uuid) | ||
}) | ||
} | ||
|
||
if rq.Name != nil { | ||
q = q.Filter(func(row r.Term) r.Term { | ||
return row.Field("name").Eq(*rq.Name) | ||
}) | ||
} | ||
|
||
if rq.Network != nil { | ||
q = q.Filter(func(row r.Term) r.Term { | ||
return row.Field("networkid").Eq(*rq.Network) | ||
}) | ||
} | ||
|
||
if rq.ParentPrefixCidr != nil { | ||
q = q.Filter(func(row r.Term) r.Term { | ||
return row.Field("prefix").Eq(*rq.ParentPrefixCidr) | ||
}) | ||
} | ||
|
||
if rq.MachineId != nil { | ||
rq.Tags = append(rq.Tags, fmt.Sprintf("%s=%s", tag.MachineID, *rq.MachineId)) | ||
} | ||
|
||
for _, t := range rq.Tags { | ||
t := t | ||
q = q.Filter(func(row r.Term) r.Term { | ||
return row.Field("tags").Contains(r.Expr(t)) | ||
}) | ||
} | ||
|
||
if rq.Type != nil { | ||
q = q.Filter(func(row r.Term) r.Term { | ||
return row.Field("type").Eq(rq.Type.String()) | ||
}) | ||
} | ||
|
||
if rq.AddressFamily != nil { | ||
var separator string | ||
switch rq.AddressFamily.String() { | ||
case apiv2.IPAddressFamily_IP_ADDRESS_FAMILY_V4.String(): | ||
separator = "\\." | ||
case apiv2.IPAddressFamily_IP_ADDRESS_FAMILY_V6.String(): | ||
separator = ":" | ||
} | ||
|
||
q = q.Filter(func(row r.Term) r.Term { | ||
return row.Field("id").Match(separator) | ||
}) | ||
} | ||
|
||
return q | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package repository | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/metal-stack/api-server/pkg/db/metal" | ||
) | ||
|
||
type ipUnscopedRepository struct { | ||
r *Repository | ||
} | ||
|
||
func (ur *ipUnscopedRepository) List(ctx context.Context) ([]*metal.IP, error) { | ||
return ur.r.ds.IP().List(ctx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.