summaryrefslogtreecommitdiff
path: root/app/graphql/mutations/alert_management/http_integration
diff options
context:
space:
mode:
Diffstat (limited to 'app/graphql/mutations/alert_management/http_integration')
-rw-r--r--app/graphql/mutations/alert_management/http_integration/create.rb41
-rw-r--r--app/graphql/mutations/alert_management/http_integration/destroy.rb24
-rw-r--r--app/graphql/mutations/alert_management/http_integration/http_integration_base.rb29
-rw-r--r--app/graphql/mutations/alert_management/http_integration/reset_token.rb25
-rw-r--r--app/graphql/mutations/alert_management/http_integration/update.rb33
5 files changed, 152 insertions, 0 deletions
diff --git a/app/graphql/mutations/alert_management/http_integration/create.rb b/app/graphql/mutations/alert_management/http_integration/create.rb
new file mode 100644
index 00000000000..ddb75e66bb4
--- /dev/null
+++ b/app/graphql/mutations/alert_management/http_integration/create.rb
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+
+module Mutations
+ module AlertManagement
+ module HttpIntegration
+ class Create < HttpIntegrationBase
+ include ResolvesProject
+
+ graphql_name 'HttpIntegrationCreate'
+
+ argument :project_path, GraphQL::ID_TYPE,
+ required: true,
+ description: 'The project to create the integration in'
+
+ argument :name, GraphQL::STRING_TYPE,
+ required: true,
+ description: 'The name of the integration'
+
+ argument :active, GraphQL::BOOLEAN_TYPE,
+ required: true,
+ description: 'Whether the integration is receiving alerts'
+
+ def resolve(args)
+ project = authorized_find!(full_path: args[:project_path])
+
+ response ::AlertManagement::HttpIntegrations::CreateService.new(
+ project,
+ current_user,
+ args.slice(:name, :active)
+ ).execute
+ end
+
+ private
+
+ def find_object(full_path:)
+ resolve_project(full_path: full_path)
+ end
+ end
+ end
+ end
+end
diff --git a/app/graphql/mutations/alert_management/http_integration/destroy.rb b/app/graphql/mutations/alert_management/http_integration/destroy.rb
new file mode 100644
index 00000000000..0f478760aab
--- /dev/null
+++ b/app/graphql/mutations/alert_management/http_integration/destroy.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+module Mutations
+ module AlertManagement
+ module HttpIntegration
+ class Destroy < HttpIntegrationBase
+ graphql_name 'HttpIntegrationDestroy'
+
+ argument :id, Types::GlobalIDType[::AlertManagement::HttpIntegration],
+ required: true,
+ description: "The id of the integration to remove"
+
+ def resolve(id:)
+ integration = authorized_find!(id: id)
+
+ response ::AlertManagement::HttpIntegrations::DestroyService.new(
+ integration,
+ current_user
+ ).execute
+ end
+ end
+ end
+ end
+end
diff --git a/app/graphql/mutations/alert_management/http_integration/http_integration_base.rb b/app/graphql/mutations/alert_management/http_integration/http_integration_base.rb
new file mode 100644
index 00000000000..d328eabf244
--- /dev/null
+++ b/app/graphql/mutations/alert_management/http_integration/http_integration_base.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+module Mutations
+ module AlertManagement
+ module HttpIntegration
+ class HttpIntegrationBase < BaseMutation
+ field :integration,
+ Types::AlertManagement::HttpIntegrationType,
+ null: true,
+ description: "The HTTP integration"
+
+ authorize :admin_operations
+
+ private
+
+ def find_object(id:)
+ GitlabSchema.object_from_id(id, expected_class: ::AlertManagement::HttpIntegration)
+ end
+
+ def response(result)
+ {
+ integration: result.payload[:integration],
+ errors: result.errors
+ }
+ end
+ end
+ end
+ end
+end
diff --git a/app/graphql/mutations/alert_management/http_integration/reset_token.rb b/app/graphql/mutations/alert_management/http_integration/reset_token.rb
new file mode 100644
index 00000000000..eefab156825
--- /dev/null
+++ b/app/graphql/mutations/alert_management/http_integration/reset_token.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+module Mutations
+ module AlertManagement
+ module HttpIntegration
+ class ResetToken < HttpIntegrationBase
+ graphql_name 'HttpIntegrationResetToken'
+
+ argument :id, Types::GlobalIDType[::AlertManagement::HttpIntegration],
+ required: true,
+ description: "The id of the integration to mutate"
+
+ def resolve(id:)
+ integration = authorized_find!(id: id)
+
+ response ::AlertManagement::HttpIntegrations::UpdateService.new(
+ integration,
+ current_user,
+ regenerate_token: true
+ ).execute
+ end
+ end
+ end
+ end
+end
diff --git a/app/graphql/mutations/alert_management/http_integration/update.rb b/app/graphql/mutations/alert_management/http_integration/update.rb
new file mode 100644
index 00000000000..309c45b04ac
--- /dev/null
+++ b/app/graphql/mutations/alert_management/http_integration/update.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+module Mutations
+ module AlertManagement
+ module HttpIntegration
+ class Update < HttpIntegrationBase
+ graphql_name 'HttpIntegrationUpdate'
+
+ argument :id, Types::GlobalIDType[::AlertManagement::HttpIntegration],
+ required: true,
+ description: "The id of the integration to mutate"
+
+ argument :name, GraphQL::STRING_TYPE,
+ required: false,
+ description: "The name of the integration"
+
+ argument :active, GraphQL::BOOLEAN_TYPE,
+ required: false,
+ description: "Whether the integration is receiving alerts"
+
+ def resolve(args)
+ integration = authorized_find!(id: args[:id])
+
+ response ::AlertManagement::HttpIntegrations::UpdateService.new(
+ integration,
+ current_user,
+ args.slice(:name, :active)
+ ).execute
+ end
+ end
+ end
+ end
+end