From 56ab957aedd373ff7c379dc1aa251e90233ee402 Mon Sep 17 00:00:00 2001 From: janis Date: Fri, 21 Oct 2022 17:04:40 +0200 Subject: [PATCH 1/5] Add cloudflare integration Changelog: added --- app/models/integration.rb | 2 +- app/models/integrations/cloudflare.rb | 29 +++++++++++++++++++++++++++ app/models/project.rb | 1 + 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 app/models/integrations/cloudflare.rb diff --git a/app/models/integration.rb b/app/models/integration.rb index 54eeab1036086b..cbf1fd91c3f71c 100644 --- a/app/models/integration.rb +++ b/app/models/integration.rb @@ -18,7 +18,7 @@ class Integration < ApplicationRecord self.inheritance_column = :type_new INTEGRATION_NAMES = %w[ - asana assembla bamboo bugzilla buildkite campfire confluence custom_issue_tracker datadog discord + asana assembla bamboo bugzilla buildkite campfire cloudflare confluence custom_issue_tracker datadog discord drone_ci emails_on_push ewm external_wiki hangouts_chat harbor irker jira mattermost mattermost_slash_commands microsoft_teams packagist pipelines_email pivotaltracker prometheus pumble pushover redmine slack slack_slash_commands teamcity unify_circuit webex_teams youtrack zentao diff --git a/app/models/integrations/cloudflare.rb b/app/models/integrations/cloudflare.rb new file mode 100644 index 00000000000000..cfc92d1f3d17d6 --- /dev/null +++ b/app/models/integrations/cloudflare.rb @@ -0,0 +1,29 @@ +module Integrations + class Cloudflare < Integration + include HasWebHook + + prop_accessor :api_token + prop_accessor :service_account_id + + def self.supported_events + %w[deployment] + end + + def fields + [ + { + type: 'text', + name: 'api_token', + title: s_('CloudflareIntegration|API Token'), + required: true + }, + { + type: 'text', + name: 'service_account_id', + title: s_('CloudflareIntegration|Serviceaccount ID'), + required: true + } + ] + end + end +end diff --git a/app/models/project.rb b/app/models/project.rb index 561a842f23a499..280824557e3c10 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -177,6 +177,7 @@ def self.integration_association_name(name) has_one :bugzilla_integration, class_name: 'Integrations::Bugzilla' has_one :buildkite_integration, class_name: 'Integrations::Buildkite' has_one :campfire_integration, class_name: 'Integrations::Campfire' + has_one :cloudflare_integration, class_name: 'Integrations::Cloudflare' has_one :confluence_integration, class_name: 'Integrations::Confluence' has_one :custom_issue_tracker_integration, class_name: 'Integrations::CustomIssueTracker' has_one :datadog_integration, class_name: 'Integrations::Datadog' -- GitLab From 82c2669ebcc90a428939e10903ce5a69c1b568aa Mon Sep 17 00:00:00 2001 From: janis Date: Fri, 21 Oct 2022 17:29:56 +0200 Subject: [PATCH 2/5] Add cloudflare integration Changelog: added --- app/models/integrations/cloudflare.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/integrations/cloudflare.rb b/app/models/integrations/cloudflare.rb index cfc92d1f3d17d6..d07a56b907d87d 100644 --- a/app/models/integrations/cloudflare.rb +++ b/app/models/integrations/cloudflare.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Integrations class Cloudflare < Integration include HasWebHook -- GitLab From dd23e1d00e26ef0c09b0227f3b1fc1ac409e5f1b Mon Sep 17 00:00:00 2001 From: janis Date: Fri, 28 Oct 2022 13:05:54 +0200 Subject: [PATCH 3/5] Add test execute function Changelog: added --- app/models/integrations/cloudflare.rb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/app/models/integrations/cloudflare.rb b/app/models/integrations/cloudflare.rb index d07a56b907d87d..e896912f6b3308 100644 --- a/app/models/integrations/cloudflare.rb +++ b/app/models/integrations/cloudflare.rb @@ -1,13 +1,21 @@ # frozen_string_literal: true module Integrations class Cloudflare < Integration - include HasWebHook + # include HasWebHook prop_accessor :api_token prop_accessor :service_account_id def self.supported_events - %w[deployment] + %w[push commit deployment job] + end + + def title + 'Cloudflare' + end + + def self.to_param + 'cloudflare' end def fields @@ -27,4 +35,11 @@ def fields ] end end + + def execute(data) + # return unless supported_events.include?(data[:object_kind]) + + url = "http://localhost:5173/" + Gitlab::HTTP.post(url, body: { payload: data }.to_json, headers: { 'Content-Type' => 'application/json' }) + end end -- GitLab From b6177cf4163bcdc2d7b1ad9e781158881c8fc610 Mon Sep 17 00:00:00 2001 From: janis Date: Mon, 14 Nov 2022 10:07:46 +0100 Subject: [PATCH 4/5] add some test data --- app/models/integrations/cloudflare.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/models/integrations/cloudflare.rb b/app/models/integrations/cloudflare.rb index e896912f6b3308..70864617ee83f7 100644 --- a/app/models/integrations/cloudflare.rb +++ b/app/models/integrations/cloudflare.rb @@ -39,7 +39,6 @@ def fields def execute(data) # return unless supported_events.include?(data[:object_kind]) - url = "http://localhost:5173/" - Gitlab::HTTP.post(url, body: { payload: data }.to_json, headers: { 'Content-Type' => 'application/json' }) + Gitlab::HTTP.post("http://localhost:8080/", body: { payload: data }.to_json, headers: { 'Content-Type' => 'application/json' }) end end -- GitLab From b948971262f130f0306b8365038b7e287dd35ac9 Mon Sep 17 00:00:00 2001 From: janis Date: Wed, 18 Jan 2023 11:16:20 +0100 Subject: [PATCH 5/5] add additional types of logging to see what happens --- app/models/integrations/cloudflare.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/integrations/cloudflare.rb b/app/models/integrations/cloudflare.rb index 70864617ee83f7..a169106de9c004 100644 --- a/app/models/integrations/cloudflare.rb +++ b/app/models/integrations/cloudflare.rb @@ -7,7 +7,7 @@ class Cloudflare < Integration prop_accessor :service_account_id def self.supported_events - %w[push commit deployment job] + %w[push] end def title @@ -38,7 +38,8 @@ def fields def execute(data) # return unless supported_events.include?(data[:object_kind]) - - Gitlab::HTTP.post("http://localhost:8080/", body: { payload: data }.to_json, headers: { 'Content-Type' => 'application/json' }) + Gitlab::AppLogger.warn("executing Cloudflare Integration") + Gitlab::HTTP.post("http://localhost:7676/dump", body: { payload: data }.to_json, headers: { 'Content-Type' => + 'application/json' }) end end -- GitLab