Skip to content

Commit

Permalink
big refactor, removed the originals methods
Browse files Browse the repository at this point in the history
  • Loading branch information
christiangda committed Mar 21, 2021
1 parent 612f2a4 commit 8236de5
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 224 deletions.
36 changes: 6 additions & 30 deletions internal/google/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ import (

// Client is the Interface for the Client
type Client interface {
GetUsers() ([]*admin.User, error)
GetUsersMatch(string) ([]*admin.User, error)
GetUsers(string) ([]*admin.User, error)
GetDeletedUsers() ([]*admin.User, error)
GetGroups() ([]*admin.Group, error)
GetGroupsMatch(string) ([]*admin.Group, error)
GetGroups(string) ([]*admin.Group, error)
GetGroupMembers(*admin.Group) ([]*admin.Member, error)
}

Expand Down Expand Up @@ -74,28 +72,6 @@ func (c *client) GetDeletedUsers() ([]*admin.User, error) {
return u, err
}

// GetUsers will get the users from Google's Admin API
func (c *client) GetUsers() ([]*admin.User, error) {
u := make([]*admin.User, 0)
err := c.service.Users.List().Customer("my_customer").Pages(c.ctx, func(users *admin.Users) error {
u = append(u, users.Users...)
return nil
})

return u, err
}

// GetGroups will get the groups from Google's Admin API
func (c *client) GetGroups() ([]*admin.Group, error) {
g := make([]*admin.Group, 0)
err := c.service.Groups.List().Customer("my_customer").Pages(context.TODO(), func(groups *admin.Groups) error {
g = append(g, groups.Groups...)
return nil
})

return g, err
}

// GetGroupMembers will get the members of the group specified
func (c *client) GetGroupMembers(g *admin.Group) ([]*admin.Member, error) {
m := make([]*admin.Member, 0)
Expand All @@ -107,7 +83,7 @@ func (c *client) GetGroupMembers(g *admin.Group) ([]*admin.Member, error) {
return m, err
}

// GetUsersMatch will get the users from Google's Admin API
// GetUsers will get the users from Google's Admin API
// using the Method: users.list with parameter "query"
// References:
// * https://developers.google.com/admin-sdk/directory/reference/rest/v1/users/list
Expand All @@ -119,7 +95,7 @@ func (c *client) GetGroupMembers(g *admin.Group) ([]*admin.Member, error) {
// manager='janesmith@example.com'
// orgName=Engineering orgTitle:Manager
// EmploymentData.projects:'GeneGnomes'
func (c *client) GetUsersMatch(query string) ([]*admin.User, error) {
func (c *client) GetUsers(query string) ([]*admin.User, error) {
u := make([]*admin.User, 0)
err := c.service.Users.List().Query(query).Customer("my_customer").Pages(c.ctx, func(users *admin.Users) error {
u = append(u, users.Users...)
Expand All @@ -129,7 +105,7 @@ func (c *client) GetUsersMatch(query string) ([]*admin.User, error) {
return u, err
}

// GetGroupsMatch will get the groups from Google's Admin API
// GetGroups will get the groups from Google's Admin API
// using the Method: groups.list with parameter "query"
// References:
// * https://developers.google.com/admin-sdk/directory/reference/rest/v1/groups/list
Expand All @@ -141,7 +117,7 @@ func (c *client) GetUsersMatch(query string) ([]*admin.User, error) {
// name:contact* email:contact*
// name:Admin* email:aws-*
// email:aws-*
func (c *client) GetGroupsMatch(query string) ([]*admin.Group, error) {
func (c *client) GetGroups(query string) ([]*admin.Group, error) {
g := make([]*admin.Group, 0)
err := c.service.Groups.List().Customer("my_customer").Query(query).Pages(context.TODO(), func(groups *admin.Groups) error {
g = append(g, groups.Groups...)
Expand Down
Loading

0 comments on commit 8236de5

Please sign in to comment.