Explorar el Código

feat(go): apply filters only if they exist;

Vishal Dalwadi hace 2 semanas
padre
commit
5eea06f887
Se han modificado 1 ficheros con 18 adiciones y 10 borrados
  1. 18 10
      pro/idp/google/google.go

+ 18 - 10
pro/idp/google/google.go

@@ -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
 				}