diff --git a/main.go b/main.go new file mode 100644 index 0000000..c624203 --- /dev/null +++ b/main.go @@ -0,0 +1,38 @@ +package main + +import ( + "fmt" + "os" + + "github.com/onelogin/onelogin-go-sdk/v4/pkg/onelogin" + "github.com/onelogin/onelogin-go-sdk/v4/pkg/onelogin/models" +) + +func main() { + + // Set environment variables for OneLogin API credentials + os.Setenv("ONELOGIN_CLIENT_ID", "client_id") + os.Setenv("ONELOGIN_CLIENT_SECRET", "client_secret") + os.Setenv("ONELOGIN_SUBDOMAIN", "your-api-subdomain") + + // Create a user object with the specified attributes + UserTwo := models.User{Firstname: "Mikhail", Lastname: "Beaverton", Email: "mb@example.com"} + + // Create a user query object with the specified email + UserQueryOne := models.UserQuery{Email: &UserTwo.Email} + + // Create a new OneLogin SDK client + Client, err := onelogin.NewOneloginSDK() + if err != nil { + fmt.Println(err) + } + + // Create a new user with the specified attributes + Client.CreateUser(models.User{Firstname: "Jane", Lastname: "Pukalava", Email: "jp@example.com"}) + + // Create a new user with the specified attributes + Client.CreateUser(UserTwo) + + // Get a list of users that match the specified query + Client.GetUsers(&UserQueryOne) +} diff --git a/pkg/onelogin/models/user.go b/pkg/onelogin/models/user.go index 587a49e..1023655 100644 --- a/pkg/onelogin/models/user.go +++ b/pkg/onelogin/models/user.go @@ -46,40 +46,40 @@ type UserQuery struct { // User represents a OneLogin User type User struct { - Firstname *string `json:"firstname,omitempty"` - Lastname *string `json:"lastname,omitempty"` - Username *string `json:"username,omitempty"` - Email *string `json:"email,omitempty"` - DistinguishedName *string `json:"distinguished_name,omitempty"` - Samaccountname *string `json:"samaccountname,omitempty"` - UserPrincipalName *string `json:"userprincipalname,omitempty"` - MemberOf *string `json:"member_of,omitempty"` - Phone *string `json:"phone,omitempty"` - Password *string `json:"password,omitempty"` - PasswordConfirmation *string `json:"password_confirmation,omitempty"` - PasswordAlgorithm *string `json:"password_algorithm,omitempty"` - Salt *string `json:"salt,omitempty"` - Title *string `json:"title,omitempty"` - Company *string `json:"company,omitempty"` - Department *string `json:"department,omitempty"` - Comment *string `json:"comment,omitempty"` - CreatedAt *time.Time `json:"created_at,omitempty"` - UpdatedAt *time.Time `json:"updated_at,omitempty"` - ActivatedAt *time.Time `json:"activated_at,omitempty"` - LastLogin *time.Time `json:"last_login,omitempty"` - PasswordChangedAt *time.Time `json:"password_changed_at,omitempty"` - LockedUntil *time.Time `json:"locked_until,omitempty"` - InvitationSentAt *time.Time `json:"invitation_sent_at,omitempty"` - State *int32 `json:"state,omitempty"` - Status *int32 `json:"status,omitempty"` - InvalidLoginAttempts *int32 `json:"invalid_login_attempts,omitempty"` - GroupID *int32 `json:"group_id,omitempty"` - DirectoryID *int32 `json:"directory_id,omitempty"` - TrustedIDPID *int32 `json:"trusted_idp_id,omitempty"` - ManagerADID *int32 `json:"manager_ad_id,omitempty"` - ManagerUserID *int32 `json:"manager_user_id,omitempty"` - ExternalID *int32 `json:"external_id,omitempty"` - ID *int32 `json:"id,omitempty"` + Firstname string `json:"firstname,omitempty"` + Lastname string `json:"lastname,omitempty"` + Username string `json:"username,omitempty"` + Email string `json:"email,omitempty"` + DistinguishedName string `json:"distinguished_name,omitempty"` + Samaccountname string `json:"samaccountname,omitempty"` + UserPrincipalName string `json:"userprincipalname,omitempty"` + MemberOf string `json:"member_of,omitempty"` + Phone string `json:"phone,omitempty"` + Password string `json:"password,omitempty"` + PasswordConfirmation string `json:"password_confirmation,omitempty"` + PasswordAlgorithm string `json:"password_algorithm,omitempty"` + Salt string `json:"salt,omitempty"` + Title string `json:"title,omitempty"` + Company string `json:"company,omitempty"` + Department string `json:"department,omitempty"` + Comment string `json:"comment,omitempty"` + CreatedAt time.Time `json:"created_at,omitempty"` + UpdatedAt time.Time `json:"updated_at,omitempty"` + ActivatedAt time.Time `json:"activated_at,omitempty"` + LastLogin time.Time `json:"last_login,omitempty"` + PasswordChangedAt time.Time `json:"password_changed_at,omitempty"` + LockedUntil time.Time `json:"locked_until,omitempty"` + InvitationSentAt time.Time `json:"invitation_sent_at,omitempty"` + State int32 `json:"state,omitempty"` + Status int32 `json:"status,omitempty"` + InvalidLoginAttempts int32 `json:"invalid_login_attempts,omitempty"` + GroupID int32 `json:"group_id,omitempty"` + DirectoryID int32 `json:"directory_id,omitempty"` + TrustedIDPID int32 `json:"trusted_idp_id,omitempty"` + ManagerADID int32 `json:"manager_ad_id,omitempty"` + 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"` } diff --git a/pkg/onelogin/models/validation.go b/pkg/onelogin/models/validation.go index c8358eb..0f76f77 100644 --- a/pkg/onelogin/models/validation.go +++ b/pkg/onelogin/models/validation.go @@ -10,24 +10,48 @@ type Queryable interface { // validateString checks if the provided value is a string. func validateString(val interface{}) bool { - _, ok := val.(string) - return ok + switch v := val.(type) { + case string: + return true + case *string: + return v != nil + default: + return false + } } // validateTime checks if the provided value is a time.Time. func validateTime(val interface{}) bool { - _, ok := val.(*time.Time) - return ok + switch v := val.(type) { + case time.Time: + return true + case *time.Time: + return v != nil + default: + return false + } } // validateInt checks if the provided value is an int. func validateInt(val interface{}) bool { - _, ok := val.(int) - return ok + switch v := val.(type) { + case int: + return true + case *int: + return v != nil + default: + return false + } } // validateBool checks if the provided value is a bool. func validateBool(val interface{}) bool { - _, ok := val.(bool) - return ok + switch v := val.(type) { + case bool: + return true + case *bool: + return v != nil + default: + return false + } }