foreman_webhooks 0.0.3 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/api/v2/webhooks_controller.rb +7 -1
- data/app/controllers/concerns/foreman_webhooks/controller/parameters/webhook.rb +1 -0
- data/app/controllers/webhooks_controller.rb +1 -24
- data/app/models/concerns/foreman_webhooks/taxonomy_extensions.rb +11 -0
- data/app/models/webhook_template.rb +4 -0
- data/app/services/foreman_webhooks/webhook_service.rb +1 -1
- data/app/views/foreman_webhooks/webhook_templates/katello_-_content_view.erb +16 -0
- data/app/views/foreman_webhooks/webhook_templates/katello_-_promote.erb +23 -0
- data/app/views/foreman_webhooks/webhook_templates/katello_-_publish.erb +24 -0
- data/app/views/foreman_webhooks/webhook_templates/katello_-_repo_sync.erb +27 -0
- data/app/views/foreman_webhooks/webhook_templates/remote_execution_-_host_job.erb +0 -1
- data/config/routes.rb +6 -2
- data/lib/foreman_webhooks/engine.rb +3 -3
- data/lib/foreman_webhooks/version.rb +1 -1
- data/package.json +6 -6
- data/webpack/ForemanWebhooks/Routes/ForemanWebhooksRoutes.js +2 -2
- data/webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/Components/ForemanFormikField.js +117 -0
- data/webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/Components/WebhookFormTabs.css +7 -0
- data/webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/Components/WebhookFormTabs.js +163 -0
- data/webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/WebhookForm.js +69 -0
- data/webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/WebhookFormSelectors.js +58 -0
- data/webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/__tests__/WebhookForm.test.js +51 -0
- data/webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/__tests__/__snapshots__/WebhookForm.test.js.snap +510 -0
- data/webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/constants.js +9 -0
- data/webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/index.js +73 -0
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/EmptyWebhooksIndexPage/index.js +63 -0
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhookCreateModal.js +69 -0
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhookDeleteModal.js +1 -0
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhookEditModal.js +107 -0
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhookEditModalSelectors.js +22 -0
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhookModal.scss +6 -0
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/Components/Formatters/index.js +1 -0
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/Components/Formatters/nameToEditFormatter.js +19 -0
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/Components/NameToEditCell.js +35 -0
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/WebhooksTable.js +31 -14
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/WebhooksTableSchema.js +12 -4
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/__tests__/WebhooksTable.test.js +13 -8
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/__tests__/__snapshots__/WebhooksTable.test.js.snap +61 -22
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/index.js +27 -5
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/WebhooksIndexPage.js +60 -34
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/__tests__/WebhooksIndexPage.fixtures.js +36 -0
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/__tests__/WebhooksIndexPage.test.js +3 -2
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/__tests__/__snapshots__/WebhooksIndexPage.test.js.snap +17 -60
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/__tests__/__snapshots__/integration.test.js.snap +43 -0
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/__tests__/integration.test.js +34 -0
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/index.js +0 -8
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksPageActions.js +3 -0
- data/webpack/ForemanWebhooks/Routes/Webhooks/constants.js +11 -1
- data/webpack/__mocks__/foremanReact/Root/Context/ForemanContext.js +1 -0
- data/webpack/__mocks__/foremanReact/common/HOC.js +30 -2
- data/webpack/__mocks__/foremanReact/common/urlHelpers.js +7 -0
- data/webpack/__mocks__/foremanReact/components/ForemanModal/index.js +6 -1
- data/webpack/__mocks__/foremanReact/components/Loading/Loading.js +2 -0
- data/webpack/__mocks__/foremanReact/components/Loading/index.js +3 -0
- data/webpack/__mocks__/foremanReact/components/Pagination/PaginationWrapper.js +3 -1
- data/webpack/__mocks__/foremanReact/components/common/forms/ForemanForm.js +9 -0
- data/webpack/__mocks__/foremanReact/components/common/forms/FormField.js +3 -0
- data/webpack/__mocks__/foremanReact/components/common/table.js +21 -0
- data/webpack/__mocks__/foremanReact/history.js +3 -0
- data/webpack/__mocks__/foremanReact/redux/actions/common/forms.js +1 -0
- data/webpack/test_setup.js +12 -0
- metadata +35 -7
- data/app/views/webhooks/_form.html.erb +0 -38
- data/app/views/webhooks/_templates.html.erb +0 -5
- data/app/views/webhooks/edit.html.erb +0 -3
- data/app/views/webhooks/new.html.erb +0 -3
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/EmptyWebhooksTable/index.js +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9acc94d42d1da3f77bd90c0383a6f22ed44ece4fd1dbdadff575a56983dcbd22
|
4
|
+
data.tar.gz: 5b4dfd3d9b5f224182fdd6ab3d320df4ed8fbb2fc1030f5abf823c1e01cf8343
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 824471769ea8d3cf27a8fc14bf8d1780a456cedb3013630636416a89fa0b2405b96b3d8674a290e66b0163636467a0773d23f574a70ec64222ba9a4d43f67dff
|
7
|
+
data.tar.gz: 25c3cc1fc29b99de2eb08ec6e7bdb9b36024d6c2c323e797611c569429822557a103fc4ac9ad839cee01c1ce6c40ff7a5f9ae4294b08195acd2cc1f370d60e7d
|
@@ -6,7 +6,7 @@ module Api
|
|
6
6
|
include Api::Version2
|
7
7
|
include ForemanWebhooks::Controller::Parameters::Webhook
|
8
8
|
|
9
|
-
before_action :find_resource, only: %i[show
|
9
|
+
before_action :find_resource, only: %i[show destroy]
|
10
10
|
|
11
11
|
api :GET, '/webhooks/', N_('List Webhooks')
|
12
12
|
param_group :search_and_pagination, ::Api::V2::BaseController
|
@@ -50,6 +50,7 @@ module Api
|
|
50
50
|
param :id, :identifier, required: true
|
51
51
|
param_group :webhook, as: :update
|
52
52
|
def update
|
53
|
+
@webhook = Webhook.find(params[:id])
|
53
54
|
process_response @webhook.update(webhook_params)
|
54
55
|
end
|
55
56
|
|
@@ -58,6 +59,11 @@ module Api
|
|
58
59
|
def destroy
|
59
60
|
process_response @webhook.destroy
|
60
61
|
end
|
62
|
+
|
63
|
+
api :GET, '/webhooks/events', N_('List available events for subscription')
|
64
|
+
def events
|
65
|
+
render json: Webhook.available_events.sort.map { |e| e.delete_suffix(Webhook::EVENT_POSTFIX) }.to_json
|
66
|
+
end
|
61
67
|
end
|
62
68
|
end
|
63
69
|
end
|
@@ -4,30 +4,7 @@ class WebhooksController < ::ApplicationController
|
|
4
4
|
include ForemanWebhooks::Controller::Parameters::Webhook
|
5
5
|
include Foreman::Controller::AutoCompleteSearch
|
6
6
|
|
7
|
-
before_action :find_resource, only: %i[
|
8
|
-
|
9
|
-
def new
|
10
|
-
@webhook = Webhook.new
|
11
|
-
end
|
12
|
-
|
13
|
-
def create
|
14
|
-
@webhook = Webhook.new(webhook_params)
|
15
|
-
if @webhook.save
|
16
|
-
process_success success_redirect: '/webhooks'
|
17
|
-
else
|
18
|
-
process_error
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def edit; end
|
23
|
-
|
24
|
-
def update
|
25
|
-
if @webhook.update(webhook_params)
|
26
|
-
process_success success_redirect: '/webhooks'
|
27
|
-
else
|
28
|
-
process_error
|
29
|
-
end
|
30
|
-
end
|
7
|
+
before_action :find_resource, only: %i[destroy]
|
31
8
|
|
32
9
|
def destroy
|
33
10
|
if @webhook.destroy
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ForemanWebhooks
|
4
|
+
module TaxonomyExtensions
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
has_many :webhook_templates, -> { where(type: 'WebhookTemplate') }, through: :taxable_taxonomies, source: :taxable, source_type: 'WebhookTemplate'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -95,7 +95,7 @@ module ForemanWebhooks
|
|
95
95
|
uri = URI.parse(url)
|
96
96
|
|
97
97
|
request = Object.const_get("Net::HTTP::#{http_method.to_s.capitalize}").new(uri.request_uri)
|
98
|
-
request.basic_auth(user, password) if user && password
|
98
|
+
request.basic_auth(user, password) if !user.blank? && !password.blank?
|
99
99
|
request['Content-Type'] = content_type
|
100
100
|
request['X-Request-Id'] = ::Logging.mdc['request'] || SecureRandom.uuid
|
101
101
|
request['X-Session-Id'] = ::Logging.mdc['session'] || SecureRandom.uuid
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<%#
|
2
|
+
name: Katello Content View
|
3
|
+
description: Example payload for content_view_*.event.foreman
|
4
|
+
snippet: false
|
5
|
+
model: WebhookTemplate
|
6
|
+
-%>
|
7
|
+
#
|
8
|
+
# Example webhook template, @object carries Action instance.
|
9
|
+
# For more information about available helpers visit /templates_doc
|
10
|
+
#
|
11
|
+
# Content view id <%= @object.id %>
|
12
|
+
# Content view name <%= @object.name %>
|
13
|
+
# Content view label <%= @object.label %>
|
14
|
+
# Organization id <%= @object.organization.id %>
|
15
|
+
# Organization name <%= @object.organization.name %>
|
16
|
+
# Organization label <%= @object.organization.label %>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<%#
|
2
|
+
name: Katello Promote
|
3
|
+
description: Example payload for actions.katello.content_view.promote_suceeded
|
4
|
+
snippet: false
|
5
|
+
model: WebhookTemplate
|
6
|
+
-%>
|
7
|
+
#
|
8
|
+
# Example webhook template, @object carries Action instance.
|
9
|
+
# For more information about available helpers visit /templates_doc
|
10
|
+
#
|
11
|
+
# Environments <%= @object.environments %>
|
12
|
+
# Content view ID <%= @object.content_view_id %>
|
13
|
+
# Content view name <%= @object.content_view_name %>
|
14
|
+
# Content view label <%= @object.content_view_label %>
|
15
|
+
# Organization id <%= @object.organization_id %>
|
16
|
+
# Organization name <%= @object.organization_name %>
|
17
|
+
# Organization label <%= @object.organization_label %>
|
18
|
+
# Task label <%= @object.task.label %>
|
19
|
+
# Task started at <%= @object.task.started_at %>
|
20
|
+
# Task ended at <%= @object.task.ended_at %>
|
21
|
+
# Task resulted with <%= @object.task.result %>
|
22
|
+
# Task state <%= @object.task.state %>
|
23
|
+
# Task action output <%= @object.task.action_output %>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<%#
|
2
|
+
name: Katello Publish
|
3
|
+
description: Example payload for actions.katello.content_view.publish_suceeded
|
4
|
+
snippet: false
|
5
|
+
model: WebhookTemplate
|
6
|
+
-%>
|
7
|
+
#
|
8
|
+
# Example webhook template, @object carries Action instance.
|
9
|
+
# For more information about available helpers visit /templates_doc
|
10
|
+
#
|
11
|
+
# Content view version id <%= @object.content_view_version_id %>
|
12
|
+
# Content view version name <%= @object.content_view_version_name %>
|
13
|
+
# Content view id <%= @object.content_view_id %>
|
14
|
+
# Content view name <%= @object.content_view_name %>
|
15
|
+
# Content view label <%= @object.content_view_label %>
|
16
|
+
# Organization id <%= @object.organization_id %>
|
17
|
+
# Organization name <%= @object.organization_name %>
|
18
|
+
# Organization label <%= @object.organization_label %>
|
19
|
+
# Task label <%= @object.task.label %>
|
20
|
+
# Task started at <%= @object.task.started_at %>
|
21
|
+
# Task ended at <%= @object.task.ended_at %>
|
22
|
+
# Task resulted with <%= @object.task.result %>
|
23
|
+
# Task state <%= @object.task.state %>
|
24
|
+
# Task action output <%= @object.task.action_output %>
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<%#
|
2
|
+
name: Katello Sync
|
3
|
+
description: Example payload for actions.katello.repository.sync_succeeded
|
4
|
+
snippet: false
|
5
|
+
model: WebhookTemplate
|
6
|
+
-%>
|
7
|
+
#
|
8
|
+
# Example webhook template, @object carries Action instance.
|
9
|
+
# For more information about available helpers visit /templates_doc
|
10
|
+
#
|
11
|
+
# Repository id <%= @object.repository_id %>
|
12
|
+
# Repository name <%= @object.repository_name %>
|
13
|
+
# Repository label <%= @object.repository_label %>
|
14
|
+
# Repository contents_changed <%= @object.contents_changed %>
|
15
|
+
# Repository sync_result <%= @object.sync_result %>
|
16
|
+
# Product id <%= @object.product_id %>
|
17
|
+
# Product name <%= @object.product_name %>
|
18
|
+
# Product label <%= @object.product_label %>
|
19
|
+
# Organization id <%= @object.organization_id %>
|
20
|
+
# Organization name <%= @object.organization_name %>
|
21
|
+
# Organization label <%= @object.organization_label %>
|
22
|
+
# Task label <%= @object.task.label %>
|
23
|
+
# Task started at <%= @object.task.started_at %>
|
24
|
+
# Task ended at <%= @object.task.ended_at %>
|
25
|
+
# Task resulted with <%= @object.task.result %>
|
26
|
+
# Task state <%= @object.task.state %>
|
27
|
+
# Task action output <%= @object.task.action_output %>
|
data/config/routes.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
Rails.application.routes.draw do
|
4
|
-
resources :webhooks, except: %i[index show] do
|
4
|
+
resources :webhooks, except: %i[index show new edit update] do
|
5
5
|
collection do
|
6
6
|
get 'auto_complete_search'
|
7
7
|
end
|
@@ -14,7 +14,11 @@ Rails.application.routes.draw do
|
|
14
14
|
defaults: { apiv: 'v2' },
|
15
15
|
apiv: /v1|v2/,
|
16
16
|
constraints: ApiConstraints.new(version: 2, default: true) do
|
17
|
-
resources :webhooks, only: %i[index show create update destroy]
|
17
|
+
resources :webhooks, only: %i[index show create update destroy] do
|
18
|
+
collection do
|
19
|
+
get :events
|
20
|
+
end
|
21
|
+
end
|
18
22
|
resources :webhook_templates, except: %i[new edit] do
|
19
23
|
member do
|
20
24
|
post :clone
|
@@ -15,7 +15,7 @@ module ForemanWebhooks
|
|
15
15
|
|
16
16
|
initializer 'foreman_webhooks.register_plugin', before: :finisher_hook do |_app|
|
17
17
|
Foreman::Plugin.register :foreman_webhooks do
|
18
|
-
requires_foreman '>=
|
18
|
+
requires_foreman '>= 3.0'
|
19
19
|
|
20
20
|
apipie_documented_controllers ["#{ForemanWebhooks::Engine.root}/app/controllers/api/v2/*.rb"]
|
21
21
|
ApipieDSL.configuration.sections += ['webhooks']
|
@@ -28,7 +28,7 @@ module ForemanWebhooks
|
|
28
28
|
# Add permissions
|
29
29
|
security_block :foreman_webhooks do
|
30
30
|
permission :view_webhooks, { webhooks: %i[index show auto_complete_search],
|
31
|
-
'api/v2/webhooks': %i[index show] }, resource_type: 'Webhook'
|
31
|
+
'api/v2/webhooks': %i[index show events] }, resource_type: 'Webhook'
|
32
32
|
permission :create_webhooks, { webhooks: %i[new create],
|
33
33
|
'api/v2/webhooks': [:create] }, resource_type: 'Webhook'
|
34
34
|
permission :edit_webhooks, { webhooks: %i[edit update],
|
@@ -81,7 +81,7 @@ module ForemanWebhooks
|
|
81
81
|
|
82
82
|
# Include concerns in this config.to_prepare block
|
83
83
|
config.to_prepare do
|
84
|
-
|
84
|
+
(Taxonomy.descendants + [Taxonomy]).each { |klass| klass.send(:include, ForemanWebhooks::TaxonomyExtensions) }
|
85
85
|
rescue StandardError => e
|
86
86
|
Rails.logger.warn "ForemanWebhooks: skipping engine hook (#{e})"
|
87
87
|
end
|
data/package.json
CHANGED
@@ -21,15 +21,15 @@
|
|
21
21
|
"url": "https://projects.theforeman.org/projects/webhooks/issues"
|
22
22
|
},
|
23
23
|
"peerDependencies": {
|
24
|
-
"@theforeman/vendor": ">= 4.
|
24
|
+
"@theforeman/vendor": ">= 8.4.1"
|
25
25
|
},
|
26
26
|
"devDependencies": {
|
27
27
|
"@babel/core": "^7.7.0",
|
28
|
-
"@theforeman/builder": "^4.
|
29
|
-
"@theforeman/stories": "^4.
|
30
|
-
"@theforeman/test": "^4.
|
31
|
-
"@theforeman/vendor-dev": "^4.
|
32
|
-
"@theforeman/eslint-plugin-foreman": "^4.
|
28
|
+
"@theforeman/builder": "^8.4.1",
|
29
|
+
"@theforeman/stories": "^8.4.1",
|
30
|
+
"@theforeman/test": "^8.4.1",
|
31
|
+
"@theforeman/vendor-dev": "^8.4.1",
|
32
|
+
"@theforeman/eslint-plugin-foreman": "^8.4.1",
|
33
33
|
"babel-eslint": "^10.0.0",
|
34
34
|
"eslint": "^6.8.0",
|
35
35
|
"eslint-plugin-spellcheck": "^0.0.17",
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import React from 'react';
|
2
|
-
import
|
2
|
+
import ConnectedWebhooksIndexPage from './Webhooks/WebhooksIndexPage';
|
3
3
|
|
4
4
|
const ForemanWebhooksRoutes = [
|
5
5
|
{
|
6
6
|
path: '/webhooks',
|
7
7
|
exact: true,
|
8
|
-
render: props => <
|
8
|
+
render: props => <ConnectedWebhooksIndexPage {...props} />,
|
9
9
|
},
|
10
10
|
];
|
11
11
|
|
data/webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/Components/ForemanFormikField.js
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import PropTypes from 'prop-types';
|
3
|
+
import { Field as FormikField } from 'formik';
|
4
|
+
import { Spinner } from '@patternfly/react-core';
|
5
|
+
import { TypeAheadSelect } from 'patternfly-react';
|
6
|
+
import { filter } from 'lodash';
|
7
|
+
|
8
|
+
import { translate as __ } from 'foremanReact/common/I18n';
|
9
|
+
|
10
|
+
import FormField from 'foremanReact/components/common/forms/FormField';
|
11
|
+
|
12
|
+
const ForemanFormikField = ({
|
13
|
+
name,
|
14
|
+
type,
|
15
|
+
required,
|
16
|
+
label,
|
17
|
+
labelHelp,
|
18
|
+
inputSizeClass,
|
19
|
+
labelSizeClass,
|
20
|
+
rows,
|
21
|
+
placeholder,
|
22
|
+
options,
|
23
|
+
isLoading,
|
24
|
+
}) => (
|
25
|
+
<FormikField name={name}>
|
26
|
+
{({
|
27
|
+
field, // { name, value, onChange, onBlur }
|
28
|
+
form: { touched, errors, setFieldValue, setFieldTouched }, // also values, setXXXX, handleXXXX, dirty, isValid, status, etc.
|
29
|
+
}) => {
|
30
|
+
const defaultSelection = (fieldValue, initialOptions) => {
|
31
|
+
if (!fieldValue) return [];
|
32
|
+
|
33
|
+
return filter(initialOptions, o => o.value === fieldValue);
|
34
|
+
};
|
35
|
+
let content = null;
|
36
|
+
switch (type) {
|
37
|
+
case 'textarea':
|
38
|
+
content = (
|
39
|
+
<textarea
|
40
|
+
{...field}
|
41
|
+
className="form-control"
|
42
|
+
rows={rows}
|
43
|
+
placeholder={placeholder}
|
44
|
+
/>
|
45
|
+
);
|
46
|
+
break;
|
47
|
+
case 'select':
|
48
|
+
content = isLoading ? (
|
49
|
+
<Spinner size="md" aria-label="loading icon" />
|
50
|
+
) : (
|
51
|
+
<TypeAheadSelect
|
52
|
+
id={name}
|
53
|
+
options={options}
|
54
|
+
placeholder={__('Start typing to search')}
|
55
|
+
selected={defaultSelection(field.value, options)}
|
56
|
+
onChange={selected =>
|
57
|
+
setFieldValue(field.name, selected[0]?.value)
|
58
|
+
}
|
59
|
+
// onBlur={e => setFieldTouched(field.name, true)}
|
60
|
+
/>
|
61
|
+
);
|
62
|
+
break;
|
63
|
+
default:
|
64
|
+
content = (
|
65
|
+
<input
|
66
|
+
{...field}
|
67
|
+
type={type}
|
68
|
+
checked={type === 'checkbox' ? field.value || '' : undefined}
|
69
|
+
className={type === 'checkbox' ? '' : 'form-control'}
|
70
|
+
/>
|
71
|
+
);
|
72
|
+
}
|
73
|
+
return (
|
74
|
+
<FormField
|
75
|
+
{...field}
|
76
|
+
error={touched[name] ? errors[name] : undefined}
|
77
|
+
type={type}
|
78
|
+
inputSizeClass={inputSizeClass}
|
79
|
+
labelSizeClass={labelSizeClass}
|
80
|
+
required={required}
|
81
|
+
label={label}
|
82
|
+
labelHelp={labelHelp}
|
83
|
+
options={options}
|
84
|
+
>
|
85
|
+
{content}
|
86
|
+
</FormField>
|
87
|
+
);
|
88
|
+
}}
|
89
|
+
</FormikField>
|
90
|
+
);
|
91
|
+
|
92
|
+
ForemanFormikField.propTypes = {
|
93
|
+
name: PropTypes.string.isRequired,
|
94
|
+
type: PropTypes.string.isRequired,
|
95
|
+
required: PropTypes.bool,
|
96
|
+
label: PropTypes.string.isRequired,
|
97
|
+
labelHelp: PropTypes.string,
|
98
|
+
inputSizeClass: PropTypes.string,
|
99
|
+
labelSizeClass: PropTypes.string,
|
100
|
+
rows: PropTypes.number,
|
101
|
+
placeholder: PropTypes.string,
|
102
|
+
options: PropTypes.array,
|
103
|
+
isLoading: PropTypes.bool,
|
104
|
+
};
|
105
|
+
|
106
|
+
ForemanFormikField.defaultProps = {
|
107
|
+
required: false,
|
108
|
+
labelHelp: null,
|
109
|
+
inputSizeClass: 'col-md-8',
|
110
|
+
labelSizeClass: 'col-md-3',
|
111
|
+
rows: 1,
|
112
|
+
placeholder: '',
|
113
|
+
options: null,
|
114
|
+
isLoading: false,
|
115
|
+
};
|
116
|
+
|
117
|
+
export default ForemanFormikField;
|
data/webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/Components/WebhookFormTabs.js
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import PropTypes from 'prop-types';
|
3
|
+
import { Tabs, Tab, TabTitleText } from '@patternfly/react-core';
|
4
|
+
|
5
|
+
import { translate as __ } from 'foremanReact/common/I18n';
|
6
|
+
|
7
|
+
import ForemanFormikField from './ForemanFormikField';
|
8
|
+
|
9
|
+
import './WebhookFormTabs.css';
|
10
|
+
|
11
|
+
const WebhookFormTabs = ({
|
12
|
+
formProps,
|
13
|
+
disabled,
|
14
|
+
activeTab,
|
15
|
+
handleTabClick,
|
16
|
+
webhookTemplates,
|
17
|
+
httpMethods,
|
18
|
+
availableEvents,
|
19
|
+
isTemplatesLoading,
|
20
|
+
isEventsLoading,
|
21
|
+
}) => (
|
22
|
+
<Tabs activeKey={activeTab} onSelect={handleTabClick} isFilled>
|
23
|
+
<Tab
|
24
|
+
className="webhook-form-tab"
|
25
|
+
eventKey={0}
|
26
|
+
title={<TabTitleText>{__('General')}</TabTitleText>}
|
27
|
+
>
|
28
|
+
<div className="webhook-form-tab-content">
|
29
|
+
<ForemanFormikField
|
30
|
+
name="event"
|
31
|
+
type="select"
|
32
|
+
label={__('Subscribe to')}
|
33
|
+
required
|
34
|
+
allowClear={false}
|
35
|
+
options={availableEvents}
|
36
|
+
isLoading={isEventsLoading}
|
37
|
+
/>
|
38
|
+
<ForemanFormikField
|
39
|
+
name="name"
|
40
|
+
type="text"
|
41
|
+
required
|
42
|
+
label={__('Name')}
|
43
|
+
/>
|
44
|
+
<ForemanFormikField
|
45
|
+
name="target_url"
|
46
|
+
type="text"
|
47
|
+
required
|
48
|
+
label={__('Target URL')}
|
49
|
+
labelHelp={__('Target URL that should be called by Foreman')}
|
50
|
+
/>
|
51
|
+
<ForemanFormikField
|
52
|
+
name="webhook_template_id"
|
53
|
+
type="select"
|
54
|
+
label={__('Template')}
|
55
|
+
required
|
56
|
+
allowClear={false}
|
57
|
+
options={webhookTemplates}
|
58
|
+
isLoading={isTemplatesLoading}
|
59
|
+
/>
|
60
|
+
<ForemanFormikField
|
61
|
+
name="http_method"
|
62
|
+
type="select"
|
63
|
+
label={__('HTTP Method')}
|
64
|
+
required
|
65
|
+
allowClear={false}
|
66
|
+
options={httpMethods}
|
67
|
+
/>
|
68
|
+
<ForemanFormikField
|
69
|
+
name="enabled"
|
70
|
+
type="checkbox"
|
71
|
+
label={__('Enabled')}
|
72
|
+
labelHelp={__('If unchecked, the webhook will be inactive')}
|
73
|
+
/>
|
74
|
+
</div>
|
75
|
+
</Tab>
|
76
|
+
<Tab
|
77
|
+
className="webhook-form-tab"
|
78
|
+
eventKey={1}
|
79
|
+
title={<TabTitleText>{__('Credentials')}</TabTitleText>}
|
80
|
+
>
|
81
|
+
<div className="webhook-form-tab-content">
|
82
|
+
<ForemanFormikField
|
83
|
+
name="user"
|
84
|
+
type="text"
|
85
|
+
label={__('User')}
|
86
|
+
labelHelp={__('Authentication credentials')}
|
87
|
+
/>
|
88
|
+
<ForemanFormikField
|
89
|
+
name="password"
|
90
|
+
type="password"
|
91
|
+
label={__('Password')}
|
92
|
+
labelHelp={__('Authentication credentials')}
|
93
|
+
/>
|
94
|
+
<ForemanFormikField
|
95
|
+
name="verify_ssl"
|
96
|
+
type="checkbox"
|
97
|
+
label={__('Verify SSL')}
|
98
|
+
labelHelp={__(
|
99
|
+
"Uncheck this option to disable validation of the receiver's SSL certificate"
|
100
|
+
)}
|
101
|
+
/>
|
102
|
+
<ForemanFormikField
|
103
|
+
name="proxy_authorization"
|
104
|
+
type="checkbox"
|
105
|
+
label={__('Proxy Authorization')}
|
106
|
+
labelHelp={__(
|
107
|
+
'Authorize with Foreman client certificate and validate smart-proxy CA from Settings'
|
108
|
+
)}
|
109
|
+
/>
|
110
|
+
<ForemanFormikField
|
111
|
+
name="ssl_ca_certs"
|
112
|
+
type="textarea"
|
113
|
+
label={__('X509 Certification Authorities')}
|
114
|
+
placeholder={__(
|
115
|
+
"Optional CAs in PEM format concatenated to verify the receiver's SSL certificate"
|
116
|
+
)}
|
117
|
+
inputSizeClass="col-md-8"
|
118
|
+
rows={8}
|
119
|
+
/>
|
120
|
+
</div>
|
121
|
+
</Tab>
|
122
|
+
<Tab
|
123
|
+
className="webhook-form-tab"
|
124
|
+
eventKey={2}
|
125
|
+
title={<TabTitleText>{__('Additional')}</TabTitleText>}
|
126
|
+
>
|
127
|
+
<div className="webhook-form-tab-content">
|
128
|
+
<ForemanFormikField
|
129
|
+
name="http_content_type"
|
130
|
+
type="text"
|
131
|
+
label={__('HTTP Content Type')}
|
132
|
+
/>
|
133
|
+
<ForemanFormikField
|
134
|
+
name="http_headers"
|
135
|
+
type="textarea"
|
136
|
+
label={__('Optional HTTP headers as JSON (ERB allowed)')}
|
137
|
+
placeholder='{\n"X-Shellhook-Arg-1": "value"\n}'
|
138
|
+
inputSizeClass="col-md-8"
|
139
|
+
rows={8}
|
140
|
+
/>
|
141
|
+
</div>
|
142
|
+
</Tab>
|
143
|
+
</Tabs>
|
144
|
+
);
|
145
|
+
|
146
|
+
WebhookFormTabs.propTypes = {
|
147
|
+
formProps: PropTypes.object,
|
148
|
+
disabled: PropTypes.bool,
|
149
|
+
activeTab: PropTypes.number.isRequired,
|
150
|
+
handleTabClick: PropTypes.func.isRequired,
|
151
|
+
webhookTemplates: PropTypes.array.isRequired,
|
152
|
+
httpMethods: PropTypes.array.isRequired,
|
153
|
+
availableEvents: PropTypes.array.isRequired,
|
154
|
+
isTemplatesLoading: PropTypes.bool.isRequired,
|
155
|
+
isEventsLoading: PropTypes.bool.isRequired,
|
156
|
+
};
|
157
|
+
|
158
|
+
WebhookFormTabs.defaultProps = {
|
159
|
+
disabled: false,
|
160
|
+
formProps: {},
|
161
|
+
};
|
162
|
+
|
163
|
+
export default WebhookFormTabs;
|