Skip to content

Commit

Permalink
Add getUsersModels func
Browse files Browse the repository at this point in the history
Same as getUsers func but return an array of models.User
This is simple to use as a client of the sdk
  • Loading branch information
melchiormoulin committed Apr 26, 2024
1 parent 7995bb9 commit ff98ca8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/onelogin/models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ type User struct {
ManagerUserID int32 `json:"manager_user_id,omitempty"`
ExternalID int32 `json:"external_id,omitempty"`
ID int32 `json:"id,omitempty"`
CustomAttributes map[string]interface{} `json:"custom_attributes,omitempty"`
CustomAttributes map[string]string `json:"custom_attributes,omitempty"`
}

func (q *UserQuery) GetKeyValidators() map[string]func(interface{}) bool {
Expand Down
35 changes: 35 additions & 0 deletions pkg/onelogin/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"

"github.com/onelogin/onelogin-go-sdk/v4/pkg/onelogin/models"
mod "github.com/onelogin/onelogin-go-sdk/v4/pkg/onelogin/models"
utl "github.com/onelogin/onelogin-go-sdk/v4/pkg/onelogin/utilities"
)
Expand Down Expand Up @@ -48,6 +49,40 @@ func (sdk *OneloginSDK) GetUsers(query mod.Queryable) (interface{}, error) {
}
return utl.CheckHTTPResponse(resp)
}
func (sdk *OneloginSDK) GetUsersModels(query mod.Queryable) ([]models.User, error) {
p, err := utl.BuildAPIPath(UserPathV2)
if err != nil {
return nil, err
}

// Validate query parameters
validators := query.GetKeyValidators()
if !utl.ValidateQueryParams(query, validators) {
return nil, errors.New("invalid query parameters")
}


resp, err := sdk.Client.Get(&p, query)
if err != nil {
return nil, err
}

tmp,err := utl.CheckHTTPResponse(resp)
if err != nil {
return nil, err
}

var users []models.User
tmpBytes,err := json.Marshal(tmp)
if err != nil {
return nil, err
}
err= json.Unmarshal(tmpBytes,&users)
if err != nil {
return nil, err
}
return users,nil
}

func (sdk *OneloginSDK) GetUserByID(id int, queryParams mod.Queryable) (interface{}, error) {
p, err := utl.BuildAPIPath(UserPathV2, id)
Expand Down

0 comments on commit ff98ca8

Please sign in to comment.