hammer_cli_foreman_webhooks 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +5 -0
- data/README.md +32 -0
- data/config/foreman_webhooks.yml +2 -0
- data/lib/hammer_cli_foreman_webhooks.rb +24 -0
- data/lib/hammer_cli_foreman_webhooks/command_extensions.rb +3 -0
- data/lib/hammer_cli_foreman_webhooks/command_extensions/webhook.rb +43 -0
- data/lib/hammer_cli_foreman_webhooks/version.rb +7 -0
- data/lib/hammer_cli_foreman_webhooks/webhook.rb +65 -0
- data/lib/hammer_cli_foreman_webhooks/webhook_template.rb +100 -0
- metadata +73 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0feb157669e6b414e8b3a9ac20b2a6f02bd1c070cf8e8c29a57c8e80e7c7420d
|
4
|
+
data.tar.gz: 51b5e1e238c9218dac0968f1127eb45ce2e1b52c51e08babda53d69241237efb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 25f6a72ed3e8d8b5c6ed21b2d5da48bdf49c2f2d56a35b479167832a88191a03d81e51f29d83f384c2b0e8fdda185a7d70033be397b3a78e5639a027e7b1c0bc
|
7
|
+
data.tar.gz: 5133fc734abaef5a43a5690b4929817c5e2c49cd606108966590c78d526824d606bb7b44ae809636b27633147de5abba57aac720f499549735ba9d68f80398d6
|
data/LICENSE
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
This program and entire repository is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.
|
2
|
+
|
3
|
+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
4
|
+
|
5
|
+
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Hammer CLI Foreman Webhooks
|
2
|
+
|
3
|
+
This Hammer CLI plugin contains set of commands for [foreman_webhooks](
|
4
|
+
https://github.com/theforeman/foreman_webhooks
|
5
|
+
), a plugin to Foreman for Webhooks management.
|
6
|
+
|
7
|
+
## Versions
|
8
|
+
|
9
|
+
This is the list of which version of Foreman Webhooks is needed to which version of this plugin.
|
10
|
+
|
11
|
+
| hammer_cli_foreman_webhooks | v0.0.1 |
|
12
|
+
|-----------------------------|--------|
|
13
|
+
| foreman_webhooks | v0.0.1 |
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
$ gem install hammer_cli_foreman_webhooks
|
18
|
+
|
19
|
+
$ mkdir -p ~/.hammer/cli.modules.d/
|
20
|
+
|
21
|
+
$ cat <<EOQ > ~/.hammer/cli.modules.d/foreman_webhooks.yml
|
22
|
+
:foreman_webhooks:
|
23
|
+
:enable_module: true
|
24
|
+
EOQ
|
25
|
+
|
26
|
+
# to confirm things work, this should return useful output
|
27
|
+
hammer webhooks --help
|
28
|
+
|
29
|
+
## More info
|
30
|
+
|
31
|
+
See our [Hammer CLI installation and configuration instuctions](
|
32
|
+
https://github.com/theforeman/hammer-cli/blob/master/doc/installation.md#installation).
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HammerCLIForemanWebhooks
|
4
|
+
require 'hammer_cli'
|
5
|
+
require 'hammer_cli_foreman'
|
6
|
+
|
7
|
+
require 'hammer_cli_foreman_webhooks/version'
|
8
|
+
require 'hammer_cli_foreman_webhooks/command_extensions'
|
9
|
+
require 'hammer_cli_foreman_webhooks/webhook'
|
10
|
+
require 'hammer_cli_foreman_webhooks/webhook_template'
|
11
|
+
|
12
|
+
HammerCLI::MainCommand.lazy_subcommand(
|
13
|
+
'webhook',
|
14
|
+
'Manage webhooks',
|
15
|
+
'HammerCLIForemanWebhooks::Webhook',
|
16
|
+
'hammer_cli_foreman_webhooks/webhook'
|
17
|
+
)
|
18
|
+
HammerCLI::MainCommand.lazy_subcommand(
|
19
|
+
'webhook-template',
|
20
|
+
'Manipulate webhook templates',
|
21
|
+
'HammerCLIForemanWebhooks::WebhookTemplate',
|
22
|
+
'hammer_cli_foreman_webhooks/webhook_template'
|
23
|
+
)
|
24
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HammerCLIForemanWebhooks
|
4
|
+
module CommandExtensions
|
5
|
+
class Webhook < HammerCLI::CommandExtensions
|
6
|
+
option '--ssl-ca-certs', 'PATH_TO_CA_FILE',
|
7
|
+
_('File containing X509 Certification Authorities concatenated in PEM format'),
|
8
|
+
format: HammerCLI::Options::Normalizers::File.new
|
9
|
+
option '--http-headers', 'HTTP_HEADERS', '',
|
10
|
+
format: HammerCLI::Options::Normalizers::KeyValueList.new
|
11
|
+
|
12
|
+
before_print do |data|
|
13
|
+
data['http_headers'] = http_headers_from_json(data['http_headers'])
|
14
|
+
end
|
15
|
+
|
16
|
+
request_params do |params|
|
17
|
+
if params['webhook']['http_headers']
|
18
|
+
params['webhook']['http_headers'] = http_headers_to_json(params['webhook']['http_headers'])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.http_headers_to_json(headers)
|
23
|
+
return headers unless headers.is_a?(Hash)
|
24
|
+
|
25
|
+
require 'json'
|
26
|
+
JSON.dump(headers)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.http_headers_from_json(data)
|
30
|
+
return data unless data.is_a?(String)
|
31
|
+
|
32
|
+
require 'json'
|
33
|
+
begin
|
34
|
+
JSON.parse(data).each_pair.each_with_object([]) do |(key, value), result|
|
35
|
+
result << { name: key, value: value }
|
36
|
+
end
|
37
|
+
rescue JSON::ParserError
|
38
|
+
[{}]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HammerCLIForemanWebhooks
|
4
|
+
class Webhook < HammerCLIForeman::Command
|
5
|
+
resource :webhooks
|
6
|
+
|
7
|
+
class ListCommand < HammerCLIForeman::ListCommand
|
8
|
+
output do
|
9
|
+
field :id, _('Id')
|
10
|
+
field :name, _('Name')
|
11
|
+
field :target_url, _('Target URL')
|
12
|
+
field :enabled, _('Enabled'), Fields::Boolean
|
13
|
+
end
|
14
|
+
|
15
|
+
build_options
|
16
|
+
end
|
17
|
+
|
18
|
+
class InfoCommand < HammerCLIForeman::InfoCommand
|
19
|
+
output Webhook::ListCommand.output_definition do
|
20
|
+
field :event, _('Event')
|
21
|
+
field :http_method, _('HTTP Method')
|
22
|
+
field :http_content_type, _('HTTP Content Type')
|
23
|
+
custom_field Fields::Reference, label: _('Webhook Template'), path: [:webhook_template]
|
24
|
+
field :user, _('User'), Fields::Field, sets: %w[ADDITIONAL ALL]
|
25
|
+
field :verify_sll, _('Verify SSL'), Fields::Boolean, sets: %w[ADDITIONAL ALL]
|
26
|
+
field :ssl_ca_certs, _('X509 Certification Authorities'), Fields::Text, sets: %w[ADDITIONAL ALL]
|
27
|
+
collection :http_headers, _('HTTP Headers'), sets: %w[ADDITIONAL ALL] do
|
28
|
+
custom_field Fields::KeyValue
|
29
|
+
end
|
30
|
+
HammerCLIForeman::References.timestamps(self)
|
31
|
+
end
|
32
|
+
|
33
|
+
build_options
|
34
|
+
|
35
|
+
extend_with(HammerCLIForemanWebhooks::CommandExtensions::Webhook.new(only: :before_print))
|
36
|
+
end
|
37
|
+
|
38
|
+
class CreateCommand < HammerCLIForeman::CreateCommand
|
39
|
+
success_message _('Webhook [%{name}] created.')
|
40
|
+
failure_message _('Could not create the webhook')
|
41
|
+
|
42
|
+
build_options without: %i[ssl_ca_certs http_headers]
|
43
|
+
|
44
|
+
extend_with(HammerCLIForemanWebhooks::CommandExtensions::Webhook.new(only: :options))
|
45
|
+
end
|
46
|
+
|
47
|
+
class UpdateCommand < HammerCLIForeman::UpdateCommand
|
48
|
+
success_message _('Webhook [%{name}] updated.')
|
49
|
+
failure_message _('Could not update the webhook')
|
50
|
+
|
51
|
+
build_options without: %i[ssl_ca_certs http_headers]
|
52
|
+
|
53
|
+
extend_with(HammerCLIForemanWebhooks::CommandExtensions::Webhook.new(only: :options))
|
54
|
+
end
|
55
|
+
|
56
|
+
class DeleteCommand < HammerCLIForeman::DeleteCommand
|
57
|
+
success_message _('Webhook [%{name}] deleted.')
|
58
|
+
failure_message _('Could not delete the webhook')
|
59
|
+
|
60
|
+
build_options
|
61
|
+
end
|
62
|
+
|
63
|
+
autoload_subcommands
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HammerCLIForemanWebhooks
|
4
|
+
class WebhookTemplate < HammerCLIForeman::Command
|
5
|
+
resource :webhook_templates
|
6
|
+
|
7
|
+
class ListCommand < HammerCLIForeman::ListCommand
|
8
|
+
output do
|
9
|
+
field :id, _('Id')
|
10
|
+
field :name, _('Name')
|
11
|
+
end
|
12
|
+
|
13
|
+
build_options
|
14
|
+
end
|
15
|
+
|
16
|
+
class InfoCommand < HammerCLIForeman::InfoCommand
|
17
|
+
output WebhookTemplate::ListCommand.output_definition do
|
18
|
+
field :description, _('Description'), Fields::Text
|
19
|
+
field :locked, _('Locked'), Fields::Boolean
|
20
|
+
field :default, _('Default'), Fields::Boolean
|
21
|
+
HammerCLIForeman::References.timestamps(self)
|
22
|
+
HammerCLIForeman::References.taxonomies(self)
|
23
|
+
collection :inputs, _('Template inputs') do
|
24
|
+
field :id, _('Id'), Fields::Id
|
25
|
+
field :name, _('Name')
|
26
|
+
field :description, _('Description')
|
27
|
+
field :required, _('Required'), Fields::Boolean
|
28
|
+
field :options, _('Options'), Fields::List, hide_blank: true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
build_options
|
33
|
+
end
|
34
|
+
|
35
|
+
class CloneCommand < HammerCLIForeman::UpdateCommand
|
36
|
+
action :clone
|
37
|
+
command_name 'clone'
|
38
|
+
|
39
|
+
success_message _('Webhook template cloned.')
|
40
|
+
failure_message _('Could not clone the webhook template')
|
41
|
+
|
42
|
+
validate_options do
|
43
|
+
option(:option_new_name).required
|
44
|
+
end
|
45
|
+
|
46
|
+
build_options
|
47
|
+
end
|
48
|
+
|
49
|
+
class ImportCommand < HammerCLIForeman::Command
|
50
|
+
command_name 'import'
|
51
|
+
action :import
|
52
|
+
|
53
|
+
option '--file', 'PATH', _('Path to a file that contains the webhook template content including metadata'),
|
54
|
+
attribute_name: :option_template, format: HammerCLI::Options::Normalizers::File.new
|
55
|
+
|
56
|
+
validate_options do
|
57
|
+
all(:option_name, :option_template).required
|
58
|
+
end
|
59
|
+
|
60
|
+
success_message _('Imported webhook template successfully.')
|
61
|
+
failure_message _('Could not import the webhook template')
|
62
|
+
|
63
|
+
build_options without: %i[template]
|
64
|
+
end
|
65
|
+
|
66
|
+
class DumpCommand < HammerCLIForeman::InfoCommand
|
67
|
+
command_name 'dump'
|
68
|
+
desc _('View webhook template content')
|
69
|
+
|
70
|
+
def print_data(webhook_template)
|
71
|
+
puts webhook_template['template']
|
72
|
+
end
|
73
|
+
|
74
|
+
build_options
|
75
|
+
end
|
76
|
+
|
77
|
+
class CreateCommand < HammerCLIForeman::CreateCommand
|
78
|
+
success_message _('Webhook template [%{name}] created.')
|
79
|
+
failure_message _('Could not create the webhook template')
|
80
|
+
|
81
|
+
build_options
|
82
|
+
end
|
83
|
+
|
84
|
+
class UpdateCommand < HammerCLIForeman::UpdateCommand
|
85
|
+
success_message _('Webhook template [%{name}] updated.')
|
86
|
+
failure_message _('Could not update the webhook template')
|
87
|
+
|
88
|
+
build_options
|
89
|
+
end
|
90
|
+
|
91
|
+
class DeleteCommand < HammerCLIForeman::DeleteCommand
|
92
|
+
success_message _('Webhook template [%{name}] deleted.')
|
93
|
+
failure_message _('Could not delete the webhook template')
|
94
|
+
|
95
|
+
build_options
|
96
|
+
end
|
97
|
+
|
98
|
+
autoload_subcommands
|
99
|
+
end
|
100
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hammer_cli_foreman_webhooks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Oleh Fedorenko
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-02-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: hammer_cli_foreman
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.0.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.0.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.0.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.0.0
|
33
|
+
description:
|
34
|
+
email:
|
35
|
+
- ofedoren@redhat.com
|
36
|
+
executables: []
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files: []
|
39
|
+
files:
|
40
|
+
- LICENSE
|
41
|
+
- README.md
|
42
|
+
- config/foreman_webhooks.yml
|
43
|
+
- lib/hammer_cli_foreman_webhooks.rb
|
44
|
+
- lib/hammer_cli_foreman_webhooks/command_extensions.rb
|
45
|
+
- lib/hammer_cli_foreman_webhooks/command_extensions/webhook.rb
|
46
|
+
- lib/hammer_cli_foreman_webhooks/version.rb
|
47
|
+
- lib/hammer_cli_foreman_webhooks/webhook.rb
|
48
|
+
- lib/hammer_cli_foreman_webhooks/webhook_template.rb
|
49
|
+
homepage: https://github.com/theforeman/hammer-cli-foreman-webhooks
|
50
|
+
licenses:
|
51
|
+
- GPL-3.0
|
52
|
+
metadata: {}
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.5'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 2.7.6.2
|
70
|
+
signing_key:
|
71
|
+
specification_version: 4
|
72
|
+
summary: Foreman Webhooks plugin for Hammer CLI
|
73
|
+
test_files: []
|