diff options
Diffstat (limited to 'app/models/alerting/project_alerting_setting.rb')
-rw-r--r-- | app/models/alerting/project_alerting_setting.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/app/models/alerting/project_alerting_setting.rb b/app/models/alerting/project_alerting_setting.rb index 34fa27eb29b..7e94d41137f 100644 --- a/app/models/alerting/project_alerting_setting.rb +++ b/app/models/alerting/project_alerting_setting.rb @@ -14,6 +14,8 @@ module Alerting algorithm: 'aes-256-gcm' before_validation :ensure_token + after_create :create_http_integration + after_update :sync_http_integration private @@ -24,5 +26,31 @@ module Alerting def generate_token SecureRandom.hex end + + # Remove in next required stop after %16.4 + # https://gitlab.com/gitlab-org/gitlab/-/issues/338838 + def sync_http_integration + project.alert_management_http_integrations + .for_endpoint_identifier('legacy-prometheus') + .take + &.update_columns( + encrypted_token: encrypted_token, + encrypted_token_iv: encrypted_token_iv + ) + end + + # Remove in next required stop after %16.4 + # https://gitlab.com/gitlab-org/gitlab/-/issues/338838 + def create_http_integration + AlertManagement::HttpIntegration.insert({ + project_id: project_id, + encrypted_token: encrypted_token, + encrypted_token_iv: encrypted_token_iv, + active: true, + name: 'Prometheus', + endpoint_identifier: 'legacy-prometheus', + type_identifier: :prometheus + }) + end end end |