Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UsersFindBy function #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,31 @@ func (c *Client) UserShow(uid string) (*UserRecord, error) {
return &userRec, nil
}

// UsersFindBy looking for users using search attributes
// For example, searchParams["mail"] = "SomeOne@mail.example"
func (c *Client) UsersFindBy(searchParams map[string]interface{}) ([]string, error) {
options := searchParams

res, err := c.rpc("user_find", []string{""}, options)

if err != nil {
return nil, err
}

var userRec []UserRecord
err = json.Unmarshal(res.Result.Data, &userRec)
if err != nil {
return nil, err
}

result := []string{}
for _, value := range userRec {
result = append(result, value.Uid.String())
}

return result, nil
}

// Update ssh public keys for user uid. Returns the fingerprints on success.
func (c *Client) UpdateSSHPubKeys(uid string, keys []string) ([]string, error) {
options := map[string]interface{}{
Expand Down