diff options
Diffstat (limited to 'app/services/alert_management')
-rw-r--r-- | app/services/alert_management/http_integrations/create_service.rb | 13 | ||||
-rw-r--r-- | app/services/alert_management/sync_alert_service_data_service.rb | 56 |
2 files changed, 11 insertions, 58 deletions
diff --git a/app/services/alert_management/http_integrations/create_service.rb b/app/services/alert_management/http_integrations/create_service.rb index 576e38c23aa..e7f1084ce5c 100644 --- a/app/services/alert_management/http_integrations/create_service.rb +++ b/app/services/alert_management/http_integrations/create_service.rb @@ -9,14 +9,14 @@ module AlertManagement def initialize(project, current_user, params) @project = project @current_user = current_user - @params = params + @params = params.with_indifferent_access end def execute return error_no_permissions unless allowed? return error_multiple_integrations unless creation_allowed? - integration = project.alert_management_http_integrations.create(params) + integration = project.alert_management_http_integrations.create(permitted_params) return error_in_create(integration) unless integration.valid? success(integration) @@ -34,6 +34,15 @@ module AlertManagement project.alert_management_http_integrations.empty? end + def permitted_params + params.slice(*permitted_params_keys) + end + + # overriden in EE + def permitted_params_keys + %i[name active] + end + def error(message) ServiceResponse.error(message: message) end diff --git a/app/services/alert_management/sync_alert_service_data_service.rb b/app/services/alert_management/sync_alert_service_data_service.rb deleted file mode 100644 index 1ba197065c5..00000000000 --- a/app/services/alert_management/sync_alert_service_data_service.rb +++ /dev/null @@ -1,56 +0,0 @@ -# frozen_string_literal: true - -module AlertManagement - class SyncAlertServiceDataService - # @param alert_service [AlertsService] - def initialize(alert_service) - @alert_service = alert_service - end - - def execute - http_integration = find_http_integration - - result = if http_integration - update_integration_data(http_integration) - else - create_integration - end - - result ? ServiceResponse.success : ServiceResponse.error(message: 'Update failed') - end - - private - - attr_reader :alert_service - - def find_http_integration - AlertManagement::HttpIntegrationsFinder.new( - alert_service.project, - endpoint_identifier: ::AlertManagement::HttpIntegration::LEGACY_IDENTIFIER - ) - .execute - .first - end - - def create_integration - new_integration = AlertManagement::HttpIntegration.create( - project_id: alert_service.project_id, - name: 'HTTP endpoint', - endpoint_identifier: AlertManagement::HttpIntegration::LEGACY_IDENTIFIER, - active: alert_service.active, - encrypted_token: alert_service.data.encrypted_token, - encrypted_token_iv: alert_service.data.encrypted_token_iv - ) - - new_integration.persisted? - end - - def update_integration_data(http_integration) - http_integration.update( - active: alert_service.active, - encrypted_token: alert_service.data.encrypted_token, - encrypted_token_iv: alert_service.data.encrypted_token_iv - ) - end - end -end |