foreman_custom_tab 0.1.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/LICENSE +0 -0
- data/README.md +13 -11
- data/Rakefile +2 -2
- data/app/controllers/concerns/foreman_custom_tab/hosts_controller_extensions.rb +2 -2
- data/app/helpers/concerns/foreman_custom_tab/hosts_helper_extensions.rb +8 -3
- data/app/overrides/{add_tab.rb → custom_tab_add_tab.rb} +2 -2
- data/app/overrides/{add_tab_link.rb → custom_tab_add_tab_link.rb} +2 -2
- data/app/views/foreman_custom_tab/hosts/_custom_tab.html.erb +0 -0
- data/config/foreman_custom_tab.yaml.example +0 -0
- data/config/routes.rb +1 -1
- data/lib/foreman_custom_tab.rb +0 -0
- data/lib/foreman_custom_tab/engine.rb +7 -10
- data/lib/foreman_custom_tab/version.rb +1 -1
- data/lib/tasks/foreman_custom_tab_tasks.rake +1 -1
- data/locale/Makefile +0 -0
- data/locale/en/foreman_custom_tab.po +0 -0
- data/locale/foreman_custom_tab.pot +0 -0
- data/locale/gemspec.rb +0 -0
- data/test/functional/concerns/hosts_controller_extensions_test.rb +8 -8
- data/test/helpers/concerns/foreman_custom_tab/hosts_helper_extensions_test.rb +2 -2
- data/test/test_plugin_helper.rb +2 -1
- data/test/unit/foreman_custom_tab_test.rb +0 -0
- data/test/views/foreman_custom_tab/hosts/_custom_tab_test.rb +5 -5
- metadata +22 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fab57529be3fc7afdc27762df54dce297ee7a05de2dbe7442d6928f2c0f46430
|
4
|
+
data.tar.gz: 89cbbe7c14ac0131f2c94b03f5bfcc46b37f4655e7416804276b3ab4be8a7b0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee289ad795f603726360ceec9f617b724dfcac053189206e33b61aa38288083b4402a211d5e64262e114903acbe6dc9cbd4f9d6088bd7ab5ddc80866fb5840b6
|
7
|
+
data.tar.gz: 9c15dc80e341818d98740c7b0b9c3a4b5d4a18a3206b187808359c7e7088d93388fbc6f2fac346361b765bbf5e1384d533a0f7891951d26b523efa51b6e8a8b5
|
data/LICENSE
CHANGED
File without changes
|
data/README.md
CHANGED
@@ -14,7 +14,7 @@ bundle update foreman_custom_tab
|
|
14
14
|
|
15
15
|
## Configuration
|
16
16
|
|
17
|
-
If there is no configuration file then the tab should not appear on the detailed hosts screen, but if
|
17
|
+
If there is no configuration file then the tab should not appear on the detailed hosts screen, but if
|
18
18
|
there is one and it is empty then it will appear without any fields. To setup the configuration file create
|
19
19
|
a new file named 'foreman_custom_tab.yaml' at the location /etc/foreman/plugins/
|
20
20
|
|
@@ -23,16 +23,19 @@ The keys are the display title and the values are the methods that are actually
|
|
23
23
|
Example configuration:
|
24
24
|
|
25
25
|
```
|
26
|
+
---
|
26
27
|
:custom_tab:
|
27
|
-
:fields:
|
28
|
-
'Host Name': name
|
29
|
-
'MAC Address': mac
|
30
|
-
'IP Address': ip
|
31
|
-
'Architecture': arch
|
32
|
-
'Certificate Name': certname
|
33
|
-
'OS Title': operatingsystem.title
|
34
|
-
'OS Type': operatingsystem.type
|
35
28
|
:title: foo
|
29
|
+
:fields:
|
30
|
+
Host Name: name
|
31
|
+
MAC Address: mac
|
32
|
+
IP Address: ip
|
33
|
+
Architecture: arch
|
34
|
+
Certificate Name: certname
|
35
|
+
OS Title: operatingsystem.title
|
36
|
+
OS Type: operatingsystem.type
|
37
|
+
Puppet Version: facts[puppetversion]
|
38
|
+
Ruby Version: facts.fetch(rubyversion)
|
36
39
|
```
|
37
40
|
|
38
41
|
## Verify the Custom Tab is loaded
|
@@ -49,7 +52,7 @@ Note: foreman running locally (i.e not installed via rpm/debian package) does no
|
|
49
52
|
|
50
53
|
## Notes
|
51
54
|
|
52
|
-
This project is still incomplete and in development.
|
55
|
+
This project is still incomplete and in development.
|
53
56
|
|
54
57
|
Copyright (c) 2017 Joe Lyons Stannard III
|
55
58
|
|
@@ -65,4 +68,3 @@ GNU General Public License for more details.
|
|
65
68
|
|
66
69
|
You should have received a copy of the GNU General Public License
|
67
70
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
68
|
-
|
data/Rakefile
CHANGED
@@ -20,7 +20,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
20
20
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
21
|
end
|
22
22
|
|
23
|
-
APP_RAKEFILE = File.expand_path('
|
23
|
+
APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
|
24
24
|
|
25
25
|
Bundler::GemHelper.install_tasks
|
26
26
|
|
@@ -38,7 +38,7 @@ task default: :test
|
|
38
38
|
begin
|
39
39
|
require 'rubocop/rake_task'
|
40
40
|
RuboCop::RakeTask.new
|
41
|
-
rescue StandardError =>
|
41
|
+
rescue StandardError => _e
|
42
42
|
puts 'Rubocop not loaded.'
|
43
43
|
end
|
44
44
|
|
@@ -8,8 +8,8 @@ module ForemanCustomTab
|
|
8
8
|
# it'll override the default find_resource filter.
|
9
9
|
find_resource
|
10
10
|
render :partial => 'foreman_custom_tab/hosts/custom_tab', :locals => { :host => @host }
|
11
|
-
rescue ActionView::Template::Error =>
|
12
|
-
process_ajax_error
|
11
|
+
rescue ActionView::Template::Error => e
|
12
|
+
process_ajax_error e, 'fetch custom tab information'
|
13
13
|
end
|
14
14
|
|
15
15
|
private
|
@@ -6,10 +6,15 @@ module ForemanCustomTab
|
|
6
6
|
fields = []
|
7
7
|
config_fields = SETTINGS[:custom_tab][:fields] || []
|
8
8
|
config_fields.each do |key, value|
|
9
|
-
host_attr_val = nil
|
10
9
|
# chain the method calls for attibutes like operatingsystem.title
|
11
|
-
value.split('.').
|
12
|
-
|
10
|
+
host_attr_val = value.split('.').inject(host) do |memo, method|
|
11
|
+
if (m = method.match(/(.*)\((.*)\)/))
|
12
|
+
memo.try(m[1], *m[2].split(/,\s?/))
|
13
|
+
elsif (m = method.match(/(.*)\[(.*)\]/))
|
14
|
+
memo.try(m[1]).try('[]', m[2])
|
15
|
+
else
|
16
|
+
memo.try(method)
|
17
|
+
end
|
13
18
|
end
|
14
19
|
fields += [[_(key.to_s), host_attr_val]] if host_attr_val.present?
|
15
20
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
if SETTINGS[:custom_tab]
|
2
2
|
Deface::Override.new(:virtual_path => 'hosts/show',
|
3
|
-
:name => '
|
4
|
-
:insert_bottom => 'ul#
|
3
|
+
:name => 'custom_tab_add_tab',
|
4
|
+
:insert_bottom => 'ul#host-show-tabs',
|
5
5
|
:text =>
|
6
6
|
"<li><a href='#custom_tab' data-toggle='tab'><%= _(custom_tab_title) %></a></li>")
|
7
7
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
if SETTINGS[:custom_tab]
|
2
2
|
Deface::Override.new(:virtual_path => 'hosts/show',
|
3
|
-
:name => '
|
4
|
-
:insert_bottom => 'div#
|
3
|
+
:name => 'custom_tab_add_tab_link',
|
4
|
+
:insert_bottom => 'div#host-show-tabs-content',
|
5
5
|
:text =>
|
6
6
|
"\n <div id='custom_tab' class='tab-pane'
|
7
7
|
data-ajax-url='<%= custom_tab_host_path(@host)%>' data-on-complete='onContentLoad'>
|
File without changes
|
File without changes
|
data/config/routes.rb
CHANGED
data/lib/foreman_custom_tab.rb
CHANGED
File without changes
|
@@ -17,10 +17,10 @@ module ForemanCustomTab
|
|
17
17
|
# http://projects.theforeman.org/projects/foreman/wiki/How_to_Create_a_Plugin#Adding-permission
|
18
18
|
initializer('foreman_custom_tab.register_plugin', :before => :finisher_hook) do
|
19
19
|
Foreman::Plugin.register :foreman_custom_tab do
|
20
|
-
requires_foreman '>=
|
20
|
+
requires_foreman '>= 2.3'
|
21
21
|
|
22
22
|
security_block :foreman_custom_tab do
|
23
|
-
permission :
|
23
|
+
permission :view_custom_tab,
|
24
24
|
{ :hosts => [:custom_tab] },
|
25
25
|
:resource_type => 'Host'
|
26
26
|
end
|
@@ -31,17 +31,14 @@ module ForemanCustomTab
|
|
31
31
|
# Include concerns in this config.to_prepare block
|
32
32
|
# http://projects.theforeman.org/projects/foreman/wiki/How_to_Create_a_Plugin#Extending-a-Controller
|
33
33
|
config.to_prepare do
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
rescue StandardError => e
|
39
|
-
Rails.logger.warn "ForemanCustomTab: skipping engine hook (#{e})"
|
40
|
-
end
|
34
|
+
HostsHelper.include ForemanCustomTab::HostsHelperExtensions
|
35
|
+
::HostsController.include ForemanCustomTab::HostsControllerExtensions
|
36
|
+
rescue StandardError => e
|
37
|
+
Rails.logger.warn "ForemanCustomTab: skipping engine hook (#{e})"
|
41
38
|
end
|
42
39
|
|
43
40
|
initializer 'foreman_custom_tab.register_gettext', after: :load_config_initializers do |_app|
|
44
|
-
locale_dir = File.join(File.expand_path('
|
41
|
+
locale_dir = File.join(File.expand_path('../..', __dir__), 'locale')
|
45
42
|
locale_domain = 'foreman_custom_tab'
|
46
43
|
Foreman::Gettext::Support.add_text_domain locale_domain, locale_dir
|
47
44
|
end
|
data/locale/Makefile
CHANGED
File without changes
|
File without changes
|
File without changes
|
data/locale/gemspec.rb
CHANGED
File without changes
|
@@ -4,24 +4,24 @@ class HostsControllerTest < ActionController::TestCase
|
|
4
4
|
let(:os) { FactoryBot.create(:operatingsystem, name: 'CentOS', major: '7', type: 'Redhat') }
|
5
5
|
let(:arch) { FactoryBot.create(:architecture) }
|
6
6
|
let(:host_id) { 'foreman.example.com' }
|
7
|
-
# rubocop:disable
|
7
|
+
# rubocop:disable Layout/LineLength
|
8
8
|
let(:host) { FactoryBot.create(:host, id: host_id, mac: '00:00:00:00:00:00', ip: '127.0.0.1', operatingsystem: os, arch: arch) }
|
9
|
-
# rubocop:enable
|
9
|
+
# rubocop:enable Layout/LineLength
|
10
10
|
let(:custom_tab_title) { SETTINGS[:custom_tab][:title] }
|
11
11
|
|
12
|
-
# rubocop:disable
|
12
|
+
# rubocop:disable Layout/LineLength, Style/StringLiterals, Rails/HttpPositionalArguments
|
13
13
|
test 'GET hosts/:id displays tabs' do
|
14
14
|
get :show, { :id => host.id }, set_session_user
|
15
15
|
assert_includes response.headers['Content-Type'], 'text/html'
|
16
16
|
assert_equal response.status, 200
|
17
|
-
assert_includes response.body, "ul id=\"
|
17
|
+
assert_includes response.body, "ul id=\"host-show-tabs\""
|
18
18
|
end
|
19
19
|
|
20
20
|
test "host overview displays tabs 'Properties', 'Metrics', 'NICs'" do
|
21
21
|
get :show, { :id => host.id }, set_session_user
|
22
22
|
assert_includes response.headers['Content-Type'], 'text/html'
|
23
23
|
assert_equal response.status, 200
|
24
|
-
assert_includes response.body, "<ul id=\"
|
24
|
+
assert_includes response.body, "<ul id=\"host-show-tabs\""
|
25
25
|
assert_includes response.body, "<li class=\"active\"><a href=\"#properties\" data-toggle=\"tab\">Properties</a></li>"
|
26
26
|
assert_includes response.body, "<li><a href=\"#metrics\" data-toggle=\"tab\">Metrics</a></li>"
|
27
27
|
assert_includes response.body, "<li><a href=\"#nics\" data-toggle=\"tab\">NICs</a></li>"
|
@@ -30,7 +30,7 @@ class HostsControllerTest < ActionController::TestCase
|
|
30
30
|
test "host overview displays the Custom Tab" do
|
31
31
|
get :show, { :id => host.id }, set_session_user
|
32
32
|
assert_includes response.headers['Content-Type'], 'text/html'
|
33
|
-
assert_includes response.body, "<ul id=\"
|
33
|
+
assert_includes response.body, "<ul id=\"host-show-tabs\""
|
34
34
|
assert_equal response.status, 200
|
35
35
|
assert_includes response.body, "<li><a href=\"#custom_tab\" data-toggle=\"tab\">#{custom_tab_title}</a></li>"
|
36
36
|
end
|
@@ -40,7 +40,7 @@ class HostsControllerTest < ActionController::TestCase
|
|
40
40
|
|
41
41
|
assert_equal response.status, 200
|
42
42
|
assert_includes response.headers['Content-Type'], 'text/html'
|
43
|
-
assert_includes response.body, "<ul id=\"
|
43
|
+
assert_includes response.body, "<ul id=\"host-show-tabs\""
|
44
44
|
assert_includes response.body, "<li><a href=\"#custom_tab\" data-toggle=\"tab\">#{custom_tab_title}</a></li>"
|
45
45
|
assert_includes response.body, "<div id=\"custom_tab\" class=\"tab-pane\" data-ajax-url=\"/hosts/#{host.name}/custom_tab\" data-on-complete=\"onContentLoad\">"
|
46
46
|
end
|
@@ -70,5 +70,5 @@ class HostsControllerTest < ActionController::TestCase
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
end
|
73
|
-
# rubocop:enable
|
73
|
+
# rubocop:enable Layout/LineLength, Style/StringLiterals, Rails/HttpPositionalArguments
|
74
74
|
end
|
@@ -5,9 +5,9 @@ class HostsHelperExtensionsTest < ActiveSupport::TestCase
|
|
5
5
|
|
6
6
|
let(:os) { FactoryBot.create(:operatingsystem, name: 'CentOS', major: '7', type: 'Redhat') }
|
7
7
|
let(:arch) { FactoryBot.create(:architecture) }
|
8
|
-
# rubocop:disable
|
8
|
+
# rubocop:disable Layout/LineLength
|
9
9
|
let(:host) { FactoryBot.create(:host, id: 'foreman.example.com', mac: '00:00:00:00:00:00', ip: '127.0.0.1', operatingsystem: os, arch: arch) }
|
10
|
-
# rubocop:enable
|
10
|
+
# rubocop:enable Layout/LineLength
|
11
11
|
let(:expected_fields) do
|
12
12
|
fields = []
|
13
13
|
SETTINGS[:custom_tab][:fields].each do |title, host_attr|
|
data/test/test_plugin_helper.rb
CHANGED
@@ -6,7 +6,8 @@ SETTINGS[:custom_tab] = { fields: { 'Host Name' => 'name',
|
|
6
6
|
'Architecture' => 'arch',
|
7
7
|
'Certificate Name' => 'certname',
|
8
8
|
'OS Title' => 'operatingsystem.title',
|
9
|
-
'OS Type' => 'operatingsystem.type'
|
9
|
+
'OS Type' => 'operatingsystem.type',
|
10
|
+
'Puppet Version' => 'facts[puppetversion]' },
|
10
11
|
title: 'foo' }
|
11
12
|
|
12
13
|
# This calls the main test_helper in Foreman-core
|
File without changes
|
@@ -3,20 +3,20 @@ require 'test_plugin_helper'
|
|
3
3
|
class CustomTabTest < ActionView::TestCase
|
4
4
|
let(:os) { FactoryBot.create(:operatingsystem, name: 'CentOS', major: '7', type: 'Redhat') }
|
5
5
|
let(:arch) { FactoryBot.create(:architecture) }
|
6
|
-
# rubocop:disable
|
6
|
+
# rubocop:disable Layout/LineLength
|
7
7
|
let(:host) { FactoryBot.create(:host, id: 'foreman.example.com', mac: '00:00:00:00:00:00', ip: '127.0.0.1', operatingsystem: os, arch: arch) }
|
8
|
-
# rubocop:enable
|
8
|
+
# rubocop:enable Layout/LineLength
|
9
9
|
let(:custom_tab_title) { SETTINGS[:custom_tab][:title] }
|
10
10
|
|
11
|
-
class FakeHostsController <
|
11
|
+
class FakeHostsController < ApplicationController
|
12
12
|
include ForemanCustomTab::HostsHelperExtensions
|
13
13
|
include LayoutHelper
|
14
14
|
|
15
15
|
def index
|
16
16
|
os = FactoryBot.create(:operatingsystem, name: 'CentOS', major: '7', type: 'Redhat')
|
17
|
-
# rubocop:disable
|
17
|
+
# rubocop:disable Layout/LineLength
|
18
18
|
@host = FactoryBot.create(:host, id: 'foreman.example.com', mac: '00:00:00:00:00:00', ip: '127.0.0.1', operatingsystem: os, arch: FactoryBot.create(:architecture))
|
19
|
-
# rubocop:enable
|
19
|
+
# rubocop:enable Layout/LineLength
|
20
20
|
render :partial => 'foreman_custom_tab/hosts/custom_tab', :locals => { :host => @host }
|
21
21
|
end
|
22
22
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_custom_tab
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Stannard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: deface
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description: Foreman Plugin that makes a new tab with different fields depending on
|
42
56
|
the settings file
|
43
57
|
email:
|
@@ -51,8 +65,8 @@ files:
|
|
51
65
|
- Rakefile
|
52
66
|
- app/controllers/concerns/foreman_custom_tab/hosts_controller_extensions.rb
|
53
67
|
- app/helpers/concerns/foreman_custom_tab/hosts_helper_extensions.rb
|
54
|
-
- app/overrides/
|
55
|
-
- app/overrides/
|
68
|
+
- app/overrides/custom_tab_add_tab.rb
|
69
|
+
- app/overrides/custom_tab_add_tab_link.rb
|
56
70
|
- app/views/foreman_custom_tab/hosts/_custom_tab.html.erb
|
57
71
|
- config/foreman_custom_tab.yaml.example
|
58
72
|
- config/routes.rb
|
@@ -81,7 +95,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
95
|
requirements:
|
82
96
|
- - ">="
|
83
97
|
- !ruby/object:Gem::Version
|
84
|
-
version:
|
98
|
+
version: 2.5.0
|
85
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
101
|
- - ">="
|
@@ -89,13 +103,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
103
|
version: '0'
|
90
104
|
requirements: []
|
91
105
|
rubyforge_project:
|
92
|
-
rubygems_version: 2.6
|
106
|
+
rubygems_version: 2.7.6
|
93
107
|
signing_key:
|
94
108
|
specification_version: 4
|
95
109
|
summary: Creates custom tab for hosts in Foreman
|
96
110
|
test_files:
|
97
|
-
- test/test_plugin_helper.rb
|
98
111
|
- test/functional/concerns/hosts_controller_extensions_test.rb
|
112
|
+
- test/helpers/concerns/foreman_custom_tab/hosts_helper_extensions_test.rb
|
113
|
+
- test/test_plugin_helper.rb
|
99
114
|
- test/unit/foreman_custom_tab_test.rb
|
100
115
|
- test/views/foreman_custom_tab/hosts/_custom_tab_test.rb
|
101
|
-
- test/helpers/concerns/foreman_custom_tab/hosts_helper_extensions_test.rb
|