From af5af6b624f01b6be142e73e3c2a909146132d00 Mon Sep 17 00:00:00 2001 From: Joe Wolf Date: Tue, 13 Jun 2023 12:40:46 -0700 Subject: [PATCH] services implemented missing mfa --- cmd/main.go | 8 ++ internal/models/app.go | 2 +- internal/models/mfa.go | 26 ++++++ internal/models/smart_hooks.go | 8 +- internal/models/user_mapping.go | 16 ++-- internal/utilities/web.go | 2 +- pkg/onelogin/apps.go | 12 +++ pkg/onelogin/groups.go | 28 ++++++ pkg/onelogin/mfa.go | 49 ++++++++++ pkg/onelogin/onelogin.go | 65 -------------- pkg/onelogin/privileges.go | 142 +++++++++++++++++++++++++++++ pkg/onelogin/saml.go | 34 +++++++ pkg/onelogin/smart_hooks.go | 150 +++++++++++++++++++++++++++++++ pkg/onelogin/user_mappings.go | 155 ++++++++++++++++++++++++++++++++ pkg/onelogin/users.go | 51 ++++++++++- 15 files changed, 668 insertions(+), 80 deletions(-) create mode 100644 internal/models/mfa.go create mode 100644 pkg/onelogin/groups.go create mode 100644 pkg/onelogin/mfa.go create mode 100644 pkg/onelogin/privileges.go create mode 100644 pkg/onelogin/saml.go create mode 100644 pkg/onelogin/smart_hooks.go create mode 100644 pkg/onelogin/user_mappings.go diff --git a/cmd/main.go b/cmd/main.go index 568d0f4..fe4614f 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -28,5 +28,13 @@ func main() { return } fmt.Println("App List:", appList) + description := "Test App Description" + newApp := models.App{Name: "Go SDK Demo App", Description: &description, ConnectorID: 2} + createdApp, err := ol.CreateApp(&newApp) + if err != nil { + fmt.Println("Failed to create app:", err) + return + } + fmt.Println("Created App:", createdApp) } diff --git a/internal/models/app.go b/internal/models/app.go index e23a5c1..f98ecdf 100644 --- a/internal/models/app.go +++ b/internal/models/app.go @@ -1,7 +1,7 @@ package models type App struct { - ID int32 `json:"id"` + ID int32 `json:"id,omitempty"` ConnectorID int32 `json:"connector_id"` Name string `json:"name"` Description *string `json:"description,omitempty"` diff --git a/internal/models/mfa.go b/internal/models/mfa.go new file mode 100644 index 0000000..ff7b0de --- /dev/null +++ b/internal/models/mfa.go @@ -0,0 +1,26 @@ +package models + +type GenerateSAMLTokenRequest struct { + UsernameOrEmail string `json:"username_or_email"` + Password string `json:"password"` + AppID string `json:"app_id"` + Subdomain string `json:"subdomain"` + IPAddress string `json:"ip_address,omitempty"` +} + +type VerifyMFATokenRequest struct { + AppID string `json:"app_id"` + DeviceID string `json:"device_id"` + StateToken string `json:"state_token"` + OTPToken string `json:"otp_token,omitempty"` + DoNotNotify bool `json:"do_not_notify,omitempty"` +} + +type EnrollFactorRequest struct { + FactorID int `json:"factor_id"` + DisplayName string `json:"display_name"` + ExpiresIn string `json:"expires_in,omitempty"` + Verified bool `json:"verified,omitempty"` + RedirectTo string `json:"redirect_to,omitempty"` + CustomMessage string `json:"custom_message,omitempty"` +} diff --git a/internal/models/smart_hooks.go b/internal/models/smart_hooks.go index 30be8db..c14d080 100644 --- a/internal/models/smart_hooks.go +++ b/internal/models/smart_hooks.go @@ -62,10 +62,10 @@ type Options struct { // SmartHookEnvVarQuery represents available query parameters type SmartHookEnvVarQuery struct { - Limit string - Page string - Cursor string - Type string + Limit string `json:"limit,omitempty"` + Page string `json:"page,omitempty"` + Cursor string `json:"cursor,omitempty"` + Type string `json:"type,omitempty"` } // EnvVar represents an Environment Variable to be associated with a SmartHook diff --git a/internal/models/user_mapping.go b/internal/models/user_mapping.go index 97841df..a99863c 100644 --- a/internal/models/user_mapping.go +++ b/internal/models/user_mapping.go @@ -2,14 +2,14 @@ package models // UserMappingsQuery represents available query parameters for mappings type UserMappingsQuery struct { - Limit string - Page string - Cursor string - HasCondition string - HasConditionType string - HasAction string - HasActionType string - Enabled string + Limit string `json:"limit,omitempty"` + Page string `json:"page,omitempty"` + Cursor string `json:"cursor,omitempty"` + HasCondition string `json:"has_condition,omitempty"` + HasConditionType string `json:"has_condition_type,omitempty"` + HasAction string `json:"has_action,omitempty"` + HasActionType string `json:"has_action_type,omitempty"` + Enabled string `json:"enabled,omitempty"` } // UserMapping is the contract for User Mappings. diff --git a/internal/utilities/web.go b/internal/utilities/web.go index 8ae001e..a736687 100644 --- a/internal/utilities/web.go +++ b/internal/utilities/web.go @@ -15,7 +15,7 @@ import ( // else return error func CheckHTTPResponse(resp *http.Response) (interface{}, error) { // Check if the request was successful - if resp.StatusCode != http.StatusOK { + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, fmt.Errorf("request failed with status: %d", resp.StatusCode) } diff --git a/pkg/onelogin/apps.go b/pkg/onelogin/apps.go index 9ce8823..f0c1287 100644 --- a/pkg/onelogin/apps.go +++ b/pkg/onelogin/apps.go @@ -137,3 +137,15 @@ func (sdk *OneloginSDK) DeleteAppRule(id, ruleID int, queryParams map[string]str } return utl.CheckHTTPResponse(resp) } + +func (sdk *OneloginSDK) GetAppUsers(appID int) (interface{}, error) { + p, err := utl.BuildAPIPath(AppPath, appID, "users") + if err != nil { + return nil, err + } + resp, err := sdk.Client.Get(&p, nil) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} diff --git a/pkg/onelogin/groups.go b/pkg/onelogin/groups.go new file mode 100644 index 0000000..97e7ed4 --- /dev/null +++ b/pkg/onelogin/groups.go @@ -0,0 +1,28 @@ +package onelogin + +import utl "github.com/onelogin/onelogin-go-sdk/internal/utilities" + +const ( + GroupsPath = "api/1/groups" +) + +func (sdk *OneloginSDK) GetGroupByID(groupID int) (interface{}, error) { + p, err := utl.BuildAPIPath(GroupsPath, groupID) + if err != nil { + return nil, err + } + resp, err := sdk.Client.Get(&p, nil) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) GetGroups() (interface{}, error) { + p := GroupsPath + resp, err := sdk.Client.Get(&p, nil) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} diff --git a/pkg/onelogin/mfa.go b/pkg/onelogin/mfa.go new file mode 100644 index 0000000..ad608a1 --- /dev/null +++ b/pkg/onelogin/mfa.go @@ -0,0 +1,49 @@ +package onelogin + +import ( + "github.com/onelogin/onelogin-go-sdk/internal/models" + utl "github.com/onelogin/onelogin-go-sdk/internal/utilities" +) + +const ( + MFAPath string = "api/2/mfa/users" +) + +// https:///api/2/mfa/users//factors +func (sdk *OneloginSDK) GetAuthFactors(userID int) (interface{}, error) { + p, err := utl.BuildAPIPath(MFAPath, userID, "factors") + if err != nil { + return nil, err + } + resp, err := sdk.Client.Get(&p, nil) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +// https:///api/2/mfa/users//registrations +func (sdk *OneloginSDK) EnrollMFAFactor(factor models.EnrollFactorRequest, userID int) (interface{}, error) { + p, err := utl.BuildAPIPath(MFAPath, userID, "registrations") + if err != nil { + return nil, err + } + resp, err := sdk.Client.Post(&p, factor) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +// https:///api/2/mfa/users//registrations/ +func (sdk *OneloginSDK) VerifyMFAEnrollment(userID, registrationID, otp int) (interface{}, error) { + p, err := utl.BuildAPIPath(MFAPath, userID, "registrations", registrationID) + if err != nil { + return nil, err + } + resp, err := sdk.Client.Put(&p, otp) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} diff --git a/pkg/onelogin/onelogin.go b/pkg/onelogin/onelogin.go index 8791667..5a9b15d 100644 --- a/pkg/onelogin/onelogin.go +++ b/pkg/onelogin/onelogin.go @@ -29,25 +29,6 @@ func (sdk *OneloginSDK) GetToken() (string, error) { return accessTk, nil } -// MFA-related endpoints -func (sdk *OneloginSDK) ActivateMFAFactor(userID int, deviceID int) { - // Implementation for Activate MFA Factor endpoint -} - -func (sdk *OneloginSDK) EnrollMFAFactor(userID int) { - // Implementation for Enroll MFA Factor endpoint -} - -// Group-related endpoints -func (sdk *OneloginSDK) GetGroupByID(groupID int) { - // Implementation for Get Group By ID endpoint -} - -func (sdk *OneloginSDK) GetGroups() { - // Implementation for Get Groups endpoint -} - -// Invite-related endpoints func (sdk *OneloginSDK) GenerateInviteLink() { // Implementation for Generate Invite Link endpoint } @@ -56,23 +37,16 @@ func (sdk *OneloginSDK) SendInviteLink() { // Implementation for Send Invite Link endpoint } -// Connector-related endpoints func (sdk *OneloginSDK) ListConnectors() { // Implementation for List Connectors endpoint } -// App User-related endpoints -func (sdk *OneloginSDK) GetAppUsers(appID int) { - // Implementation for Get App Users endpoint -} - func (sdk *OneloginSDK) CreateDeviceVerification(userID int) { // Implementation for Create Device Verification endpoint } func (sdk *OneloginSDK) CreateFactorRegistration(userID int) {} func (sdk *OneloginSDK) DeleteEnrolledFactor(userID int, deviceID int) {} func (sdk *OneloginSDK) GenerateOTP(userID int) {} -func (sdk *OneloginSDK) GetAuthFactors(userID int) {} func (sdk *OneloginSDK) GetAuthenticationDevices(userID int) {} func (sdk *OneloginSDK) GetUserRegistration(userID int, registrationID int) {} func (sdk *OneloginSDK) GetUserVerification(userID int, verificationID int) {} @@ -83,42 +57,3 @@ func (sdk *OneloginSDK) GetEnrolledFactors(userID int) { func (sdk *OneloginSDK) GetMFAFactors(userID int) {} func (sdk *OneloginSDK) RemoveMFAFactor(userID int, deviceID int) {} func (sdk *OneloginSDK) VerifyMFAFactor(userID int, deviceID int) {} - -func (sdk *OneloginSDK) AddPrivilegeToRole(privilegeID int, roleID int) {} -func (sdk *OneloginSDK) AssignUsersToPrivilege(privilegeID int) {} -func (sdk *OneloginSDK) CreatePrivilege() {} -func (sdk *OneloginSDK) DeletePrivilege(privilegeID int) {} -func (sdk *OneloginSDK) DeleteRoleFromPrivilege(privilegeID int, roleID int) {} -func (sdk *OneloginSDK) GetAssignedUsers(privilegeID int) {} -func (sdk *OneloginSDK) GetPrivilege(privilegeID int) {} -func (sdk *OneloginSDK) GetPrivilegeRoles(privilegeID int) {} -func (sdk *OneloginSDK) ListPrivileges() {} -func (sdk *OneloginSDK) RemovePrivilegeFromUser(privilegeID int, userID int) {} -func (sdk *OneloginSDK) UpdatePrivilege(privilegeID int) {} - -func (sdk *OneloginSDK) GenerateSAMLAssertion() {} -func (sdk *OneloginSDK) VerifyFactorSAML() {} - -func (sdk *OneloginSDK) CreateEnvironmentVariable() {} -func (sdk *OneloginSDK) CreateHook() {} -func (sdk *OneloginSDK) DeleteEnvironmentVariable(envVarID int) {} -func (sdk *OneloginSDK) DeleteHook(hookID int) {} -func (sdk *OneloginSDK) GetEnvironmentVariable(envVarID int) {} -func (sdk *OneloginSDK) GetHook(hookID int) {} -func (sdk *OneloginSDK) GetHookLogs(hookID int) {} -func (sdk *OneloginSDK) ListEnvironmentVariables() {} -func (sdk *OneloginSDK) ListSmartHooks() {} -func (sdk *OneloginSDK) UpdateEnvironmentVariable(envVarID int) {} -func (sdk *OneloginSDK) UpdateSmartHook(hookID int) {} -func (sdk *OneloginSDK) CreateMapping() {} -func (sdk *OneloginSDK) DeleteMapping(mappingID int) {} -func (sdk *OneloginSDK) GetMapping(mappingID int) {} -func (sdk *OneloginSDK) ListMappings() {} -func (sdk *OneloginSDK) ListActions() {} -func (sdk *OneloginSDK) SortMappings() {} -func (sdk *OneloginSDK) UpdateMapping(mappingID int) {} -func (sdk *OneloginSDK) AddRolesToUser(userID int) {} -func (sdk *OneloginSDK) GetCustomAttributes() {} - -func (sdk *OneloginSDK) RemoveUserRole(userID int) {} -func (sdk *OneloginSDK) SetUserState(userID int) {} diff --git a/pkg/onelogin/privileges.go b/pkg/onelogin/privileges.go new file mode 100644 index 0000000..d8ae218 --- /dev/null +++ b/pkg/onelogin/privileges.go @@ -0,0 +1,142 @@ +package onelogin + +import ( + "github.com/onelogin/onelogin-go-sdk/internal/models" + utl "github.com/onelogin/onelogin-go-sdk/internal/utilities" +) + +const ( + PrivilegesPath string = "api/1/privileges" +) + +func (sdk *OneloginSDK) ListPrivileges() (interface{}, error) { + p, err := utl.BuildAPIPath(PrivilegesPath) + if err != nil { + return nil, err + } + resp, err := sdk.Client.Get(&p, nil) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) CreatePrivilege(privilege models.Privilege) (interface{}, error) { + p, err := utl.BuildAPIPath(PrivilegesPath) + if err != nil { + return nil, err + } + resp, err := sdk.Client.Post(&p, privilege) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) GetPrivilege(privilegeID int) (interface{}, error) { + p, err := utl.BuildAPIPath(PrivilegesPath, privilegeID) + if err != nil { + return nil, err + } + resp, err := sdk.Client.Get(&p, nil) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) DeletePrivilege(privilegeID int) (interface{}, error) { + p, err := utl.BuildAPIPath(PrivilegesPath, privilegeID) + if err != nil { + return nil, err + } + resp, err := sdk.Client.Delete(&p) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) UpdatePrivilege(privilegeID int) (interface{}, error) { + p, err := utl.BuildAPIPath(PrivilegesPath, privilegeID) + if err != nil { + return nil, err + } + resp, err := sdk.Client.Put(&p, nil) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) GetPrivilegeUsers(privilegeID int) (interface{}, error) { + p, err := utl.BuildAPIPath(PrivilegesPath, privilegeID, "users") + if err != nil { + return nil, err + } + resp, err := sdk.Client.Get(&p, nil) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) AssignUsersToPrivilege(privilegeID int) (interface{}, error) { + p, err := utl.BuildAPIPath(PrivilegesPath, privilegeID, "users") + if err != nil { + return nil, err + } + resp, err := sdk.Client.Put(&p, nil) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) RemovePrivilegeFromUser(privilegeID int, userID int) (interface{}, error) { + p, err := utl.BuildAPIPath(PrivilegesPath, privilegeID, "users", userID) + if err != nil { + return nil, err + } + resp, err := sdk.Client.Delete(&p) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) GetPrivilegeRoles(privilegeID int) (interface{}, error) { + p, err := utl.BuildAPIPath(PrivilegesPath, privilegeID, "roles") + if err != nil { + return nil, err + } + resp, err := sdk.Client.Get(&p, nil) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) AddPrivilegeToRole(privilegeID int, roleID int) (interface{}, error) { + p, err := utl.BuildAPIPath(PrivilegesPath, privilegeID, "roles", roleID) + if err != nil { + return nil, err + } + resp, err := sdk.Client.Put(&p, nil) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) DeleteRoleFromPrivilege(privilegeID int, roleID int) (interface{}, error) { + p, err := utl.BuildAPIPath(PrivilegesPath, privilegeID, "roles", roleID) + if err != nil { + return nil, err + } + resp, err := sdk.Client.Delete(&p) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} diff --git a/pkg/onelogin/saml.go b/pkg/onelogin/saml.go new file mode 100644 index 0000000..dd5c1a3 --- /dev/null +++ b/pkg/onelogin/saml.go @@ -0,0 +1,34 @@ +package onelogin + +import ( + "github.com/onelogin/onelogin-go-sdk/internal/models" + utl "github.com/onelogin/onelogin-go-sdk/internal/utilities" +) + +const ( + SAMLPath string = "api/2/saml_assertion" +) + +func (sdk *OneloginSDK) VerifyFactorSAML(request models.VerifyMFATokenRequest) (interface{}, error) { + p, err := utl.BuildAPIPath(SAMLPath, "verify_factor") + if err != nil { + return nil, err + } + resp, err := sdk.Client.Post(&p, request) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) GenerateSAMLAssertion(request models.GenerateSAMLTokenRequest) (interface{}, error) { + p, err := utl.BuildAPIPath(SAMLPath) + if err != nil { + return nil, err + } + resp, err := sdk.Client.Post(&p, request) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} diff --git a/pkg/onelogin/smart_hooks.go b/pkg/onelogin/smart_hooks.go new file mode 100644 index 0000000..244be9d --- /dev/null +++ b/pkg/onelogin/smart_hooks.go @@ -0,0 +1,150 @@ +package onelogin + +import ( + "github.com/onelogin/onelogin-go-sdk/internal/models" + utl "github.com/onelogin/onelogin-go-sdk/internal/utilities" +) + +const ( + SmartHooksPath string = "api/2/hooks" +) + +func (sdk *OneloginSDK) CreateHook(hook models.SmartHook) (interface{}, error) { + p, err := utl.BuildAPIPath(SmartHooksPath) + if err != nil { + return nil, err + } + resp, err := sdk.Client.Post(&p, hook) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) DeleteHook(hookID int) (interface{}, error) { + p, err := utl.BuildAPIPath(SmartHooksPath, hookID) + if err != nil { + return nil, err + } + resp, err := sdk.Client.Delete(&p) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) GetHook(hookID int, query models.Queryable) (interface{}, error) { + p, err := utl.BuildAPIPath(SmartHooksPath, hookID) + if err != nil { + return nil, err + } + resp, err := sdk.Client.Get(&p, query) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) ListHooks(query models.Queryable) (interface{}, error) { + p, err := utl.BuildAPIPath(SmartHooksPath) + if err != nil { + return nil, err + } + resp, err := sdk.Client.Get(&p, query) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) UpdateSmartHook(hookID int, hook models.SmartHook) (interface{}, error) { + p, err := utl.BuildAPIPath(SmartHooksPath, hookID) + if err != nil { + return nil, err + } + resp, err := sdk.Client.Put(&p, hook) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) ListEnvironmentVariables() (interface{}, error) { + p, err := utl.BuildAPIPath(SmartHooksPath, "envs") + if err != nil { + return nil, err + } + resp, err := sdk.Client.Get(&p, nil) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) CreateEnvironmentVariable(name, value string) (interface{}, error) { + p, err := utl.BuildAPIPath(SmartHooksPath, "envs") + if err != nil { + return nil, err + } + envVar := map[string]string{ + "name": name, + "value": value, + } + resp, err := sdk.Client.Post(&p, envVar) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) GetEnvironmentVariable(envVarID int) (interface{}, error) { + p, err := utl.BuildAPIPath(SmartHooksPath, "envs", envVarID) + if err != nil { + return nil, err + } + resp, err := sdk.Client.Get(&p, nil) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) UpdateEnvironmentVariable(envVarID int, name, value string) (interface{}, error) { + p, err := utl.BuildAPIPath(SmartHooksPath, "envs", envVarID) + if err != nil { + return nil, err + } + envVar := map[string]string{ + "name": name, + "value": value, + } + resp, err := sdk.Client.Put(&p, envVar) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) DeleteEnvironmentVariable(envVarID int) (interface{}, error) { + p, err := utl.BuildAPIPath(SmartHooksPath, "envs", envVarID) + if err != nil { + return nil, err + } + resp, err := sdk.Client.Delete(&p) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) GetHookLogs(hookID int, query models.Queryable) (interface{}, error) { + p, err := utl.BuildAPIPath(SmartHooksPath, hookID, "logs") + if err != nil { + return nil, err + } + resp, err := sdk.Client.Get(&p, query) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} diff --git a/pkg/onelogin/user_mappings.go b/pkg/onelogin/user_mappings.go new file mode 100644 index 0000000..dc71d85 --- /dev/null +++ b/pkg/onelogin/user_mappings.go @@ -0,0 +1,155 @@ +package onelogin + +import ( + mod "github.com/onelogin/onelogin-go-sdk/internal/models" + utl "github.com/onelogin/onelogin-go-sdk/internal/utilities" +) + +const ( + MappingsPath string = "api/2/mappings" +) + +func (sdk *OneloginSDK) ListMappings() (interface{}, error) { + p, err := utl.BuildAPIPath(MappingsPath) + if err != nil { + return nil, err + } + resp, err := sdk.Client.Get(&p, nil) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) CreateMapping(mapping mod.UserMapping) (interface{}, error) { + p, err := utl.BuildAPIPath(MappingsPath) + if err != nil { + return nil, err + } + resp, err := sdk.Client.Post(&p, mapping) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) DeleteMapping(mappingID int) (interface{}, error) { + p, err := utl.BuildAPIPath(MappingsPath, mappingID) + if err != nil { + return nil, err + } + resp, err := sdk.Client.Delete(&p) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) GetMapping(mappingID int) (interface{}, error) { + p, err := utl.BuildAPIPath(MappingsPath, mappingID) + if err != nil { + return nil, err + } + resp, err := sdk.Client.Get(&p, nil) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) ListActions() (interface{}, error) { + p, err := utl.BuildAPIPath(MappingsPath, "actions") + if err != nil { + return nil, err + } + resp, err := sdk.Client.Get(&p, nil) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) UpdateMapping(mappingID int) (interface{}, error) { + p, err := utl.BuildAPIPath(MappingsPath, mappingID) + if err != nil { + return nil, err + } + resp, err := sdk.Client.Put(&p, nil) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) BulkSortMappings(mappingIDs []int) (interface{}, error) { + p, err := utl.BuildAPIPath(MappingsPath, "bulk_sort") + if err != nil { + return nil, err + } + resp, err := sdk.Client.Put(&p, mappingIDs) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) ListActionValues(actionValue string) (interface{}, error) { + p, err := utl.BuildAPIPath(MappingsPath, "actions", actionValue, "values") + if err != nil { + return nil, err + } + resp, err := sdk.Client.Get(&p, nil) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) ListConditionValues(conditionValue string) (interface{}, error) { + p, err := utl.BuildAPIPath(MappingsPath, "conditions", conditionValue, "values") + if err != nil { + return nil, err + } + resp, err := sdk.Client.Get(&p, nil) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) ListConditionOperators(conditionValue string) (interface{}, error) { + p, err := utl.BuildAPIPath(MappingsPath, "conditions", conditionValue, "operators") + if err != nil { + return nil, err + } + resp, err := sdk.Client.Get(&p, nil) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) DryrunMapping(mappingID int) (interface{}, error) { + p, err := utl.BuildAPIPath(MappingsPath, mappingID, "dryrun") + if err != nil { + return nil, err + } + resp, err := sdk.Client.Post(&p, nil) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +// https:///api/2/mappings/conditions +func (sdk *OneloginSDK) ListConditions() (interface{}, error) { + p, err := utl.BuildAPIPath(MappingsPath, "conditions") + if err != nil { + return nil, err + } + resp, err := sdk.Client.Get(&p, nil) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} diff --git a/pkg/onelogin/users.go b/pkg/onelogin/users.go index 3ba5b49..e615803 100644 --- a/pkg/onelogin/users.go +++ b/pkg/onelogin/users.go @@ -15,7 +15,7 @@ const ( ) // Users V2 -func (sdk *OneloginSDK) CreateUser(user *mod.User) (interface{}, error) { +func (sdk *OneloginSDK) CreateUser(user mod.User) (interface{}, error) { p := UserPathV2 resp, err := sdk.Client.Post(&p, user) if err != nil { @@ -170,3 +170,52 @@ func (sdk *OneloginSDK) AssignRolesToUser(userID int, roles []int) (interface{}, } return utl.CheckHTTPResponse(resp) } + +func (sdk *OneloginSDK) SetUserState(userID, state int) (interface{}, error) { + p, err := utl.BuildAPIPath(UserPathV1, userID, "set_state") + if err != nil { + return nil, err + } + payload := map[string]int{"state": state} + resp, err := sdk.Client.Put(&p, payload) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) RemoveUserRole(userID int) (interface{}, error) { + p, err := utl.BuildAPIPath(UserPathV1, userID, "remove_roles") + if err != nil { + return nil, err + } + resp, err := sdk.Client.Put(&p, nil) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) GetCustomAttributes() (interface{}, error) { + p, err := utl.BuildAPIPath(UserPathV1, "custom_attributes") + if err != nil { + return nil, err + } + resp, err := sdk.Client.Get(&p, nil) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +} + +func (sdk *OneloginSDK) SetCustomAttributes(userID int, attr interface{}) (interface{}, error) { + p, err := utl.BuildAPIPath(UserPathV1, userID, "set_custom_attributes") + if err != nil { + return nil, err + } + resp, err := sdk.Client.Put(&p, attr) + if err != nil { + return nil, err + } + return utl.CheckHTTPResponse(resp) +}