mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-04 12:14:19 +08:00
feat(go): apply filters only if they exist;
This commit is contained in:
parent
146d907f5d
commit
5eea06f887
1 changed files with 18 additions and 10 deletions
|
@ -68,14 +68,18 @@ func (g *Client) GetUsers(filters []string) ([]idp.User, error) {
|
|||
Fields("users(id,primaryEmail,name,suspended,archived)", "nextPageToken").
|
||||
Pages(context.TODO(), func(users *admindir.Users) error {
|
||||
for _, user := range users.Users {
|
||||
var found bool
|
||||
for _, filter := range filters {
|
||||
if strings.HasPrefix(user.PrimaryEmail, filter) {
|
||||
found = true
|
||||
var keep bool
|
||||
if len(filters) > 0 {
|
||||
for _, filter := range filters {
|
||||
if strings.HasPrefix(user.PrimaryEmail, filter) {
|
||||
keep = true
|
||||
}
|
||||
}
|
||||
} else {
|
||||
keep = true
|
||||
}
|
||||
|
||||
if !found {
|
||||
if !keep {
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -101,14 +105,18 @@ func (g *Client) GetGroups(filters []string) ([]idp.Group, error) {
|
|||
Fields("groups(id,name)", "nextPageToken").
|
||||
Pages(context.TODO(), func(groups *admindir.Groups) error {
|
||||
for _, group := range groups.Groups {
|
||||
var found bool
|
||||
for _, filter := range filters {
|
||||
if strings.HasPrefix(group.Name, filter) {
|
||||
found = true
|
||||
var keep bool
|
||||
if len(filters) > 0 {
|
||||
for _, filter := range filters {
|
||||
if strings.HasPrefix(group.Name, filter) {
|
||||
keep = true
|
||||
}
|
||||
}
|
||||
} else {
|
||||
keep = true
|
||||
}
|
||||
|
||||
if !found {
|
||||
if !keep {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue