foreman_teamdynamix 1.0.0 → 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 +0 -0
- data/Rakefile +1 -1
- data/app/controllers/concerns/foreman_teamdynamix/hosts_controller_extensions.rb +2 -2
- data/app/helpers/concerns/foreman_teamdynamix/hosts_helper_extensions.rb +4 -1
- data/app/models/concerns/foreman_teamdynamix/host_extensions.rb +0 -0
- data/app/overrides/teamdynamix_add_tab.rb +0 -0
- data/app/overrides/teamdynamix_add_tab_link.rb +0 -0
- data/app/services/teamdynamix_api.rb +5 -1
- data/app/views/foreman_teamdynamix/hosts/_teamdynamix.html.erb +0 -0
- data/config/routes.rb +1 -1
- data/db/migrate/20171228033228_add_teamdynamix_asset_uid_to_hosts.rb +0 -0
- data/lib/foreman_teamdynamix.rb +0 -0
- data/lib/foreman_teamdynamix/engine.rb +6 -8
- data/lib/foreman_teamdynamix/version.rb +1 -1
- data/lib/tasks/foreman_teamdynamix_tasks.rake +1 -1
- data/lib/tasks/teamdynamix.rake +1 -1
- data/locale/Makefile +0 -0
- data/locale/en/foreman_teamdynamix.po +0 -0
- data/locale/foreman_teamdynamix.pot +0 -0
- data/locale/gemspec.rb +0 -0
- data/test/fake_teamdynamix_api.rb +0 -0
- data/test/functional/concerns/hosts_controller_extensions_test.rb +5 -4
- data/test/helpers/concerns/foreman_teamdynamix/hosts_helper_extensions_test.rb +4 -2
- data/test/models/host_extensions_test.rb +0 -0
- data/test/sample_asset.json +0 -0
- data/test/services/teamdynamix_api_test.rb +13 -11
- data/test/test_plugin_helper.rb +1 -1
- data/test/unit/foreman_teamdynamix_test.rb +0 -0
- 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: 794c51b66dd0d644686457e879f7afdac549631887c3992ff7fb3e0f605c75b6
|
4
|
+
data.tar.gz: 643df4d3a0afa76409a95bea74a9d1827ba52ccb34de79d1beef8100c9ecc21d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43388c4a90d67990cafa869640227c28dcc11d16ec9a404aca967c4e06ef44ee1637c9d95fb381cc398eca99f40a1e713799c11b0432510061da40286b6f14a6
|
7
|
+
data.tar.gz: a197a8ec8140d1d076b5173529d1bde01c8c3145708f701bf7ba3088fcb0f2d142b4c95eee03269ccbe4925a4ae0e10716f849b08bd1b442879f376e8f4c1ae1
|
data/LICENSE
CHANGED
File without changes
|
data/README.md
CHANGED
File without changes
|
data/Rakefile
CHANGED
@@ -6,8 +6,8 @@ module ForemanTeamdynamix
|
|
6
6
|
def teamdynamix
|
7
7
|
find_resource
|
8
8
|
render partial: 'foreman_teamdynamix/hosts/teamdynamix', :locals => { :host => @host }
|
9
|
-
rescue ActionView::Template::Error =>
|
10
|
-
process_ajax_error
|
9
|
+
rescue ActionView::Template::Error => e
|
10
|
+
process_ajax_error e, 'fetch teamdynamix tab information'
|
11
11
|
end
|
12
12
|
|
13
13
|
private
|
@@ -32,7 +32,7 @@ module ForemanTeamdynamix
|
|
32
32
|
def asset_uri(td_pane_fields)
|
33
33
|
if td_pane_fields[:url]
|
34
34
|
uri = "#{td_pane_fields[:url]}/#{@asset['AppID']}/Assets/AssetDet?AssetID=#{@asset['ID']}"
|
35
|
-
[[_('URI'), link_to(@asset['SerialNumber'], uri, target: '_blank')]]
|
35
|
+
[[_('URI'), link_to(@asset['SerialNumber'], uri, target: '_blank', rel: 'noopener')]]
|
36
36
|
else
|
37
37
|
[]
|
38
38
|
end
|
@@ -43,11 +43,14 @@ module ForemanTeamdynamix
|
|
43
43
|
parent_attrib = nested_attrib_tokens.first
|
44
44
|
child_attrib = nested_attrib_tokens[1..nested_attrib_tokens.length].join('.')
|
45
45
|
return '' if parent_attrib.blank? || child_attrib.blank?
|
46
|
+
|
46
47
|
child_attrib.delete!("'")
|
47
48
|
parent_attrib_val = @asset[parent_attrib]
|
48
49
|
return '' if parent_attrib_val.blank?
|
50
|
+
|
49
51
|
nested_attrib_val = parent_attrib_val.find { |attrib| attrib['Name'] == child_attrib }
|
50
52
|
return '' if nested_attrib_val.blank?
|
53
|
+
|
51
54
|
nested_attrib_val['Value']
|
52
55
|
end
|
53
56
|
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -5,12 +5,15 @@ class TeamdynamixApi
|
|
5
5
|
if SETTINGS[:teamdynamix].blank?
|
6
6
|
raise('Missing configurations for the plugin see https://github.com/MiamiOH/foreman_teamdynamix')
|
7
7
|
end
|
8
|
+
|
8
9
|
API_CONFIG = SETTINGS[:teamdynamix][:api]
|
9
10
|
|
10
11
|
raise('Missing Team Dynamix Api ID in plugin settings') if API_CONFIG[:appId].blank?
|
12
|
+
|
11
13
|
APP_ID = API_CONFIG[:appId]
|
12
14
|
|
13
15
|
raise('Missing Team Dynamix API URL in plugin settings') if API_CONFIG[:url].blank?
|
16
|
+
|
14
17
|
API_URL = API_CONFIG[:url]
|
15
18
|
|
16
19
|
def initialize
|
@@ -21,6 +24,7 @@ class TeamdynamixApi
|
|
21
24
|
# returns TeamDynamix.Api.Assets.Asset
|
22
25
|
def get_asset(asset_id)
|
23
26
|
return nil unless asset_id
|
27
|
+
|
24
28
|
uri = URI.parse("#{API_URL}/#{APP_ID}/assets/#{asset_id}")
|
25
29
|
rest(:get, uri)
|
26
30
|
rescue RuntimeError
|
@@ -153,7 +157,7 @@ class TeamdynamixApi
|
|
153
157
|
end
|
154
158
|
|
155
159
|
def valid_auth_token?(token)
|
156
|
-
token.match(/^[a-zA-Z0-9
|
160
|
+
token.match(/^[a-zA-Z0-9.\-_]*$/)
|
157
161
|
end
|
158
162
|
|
159
163
|
def ensure_configured_create_params
|
File without changes
|
data/config/routes.rb
CHANGED
File without changes
|
data/lib/foreman_teamdynamix.rb
CHANGED
File without changes
|
@@ -16,7 +16,7 @@ module ForemanTeamdynamix
|
|
16
16
|
|
17
17
|
initializer 'foreman_teamdynamix.register_plugin', :before => :finisher_hook do |_app|
|
18
18
|
Foreman::Plugin.register :foreman_teamdynamix do
|
19
|
-
requires_foreman '>=
|
19
|
+
requires_foreman '>= 2.3'
|
20
20
|
|
21
21
|
# Add permissions
|
22
22
|
security_block :foreman_teamdynamix do
|
@@ -29,13 +29,11 @@ module ForemanTeamdynamix
|
|
29
29
|
|
30
30
|
# Include concerns in this config.to_prepare block
|
31
31
|
config.to_prepare do
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
Rails.logger.warn "ForemanTeamdynamix: skipping engine hook (#{e})"
|
38
|
-
end
|
32
|
+
HostsHelper.include ForemanTeamdynamix::HostsHelperExtensions
|
33
|
+
::HostsController.include ForemanTeamdynamix::HostsControllerExtensions
|
34
|
+
::Host::Managed.include ForemanTeamdynamix::HostExtensions
|
35
|
+
rescue StandardError => e
|
36
|
+
Rails.logger.warn "ForemanTeamdynamix: skipping engine hook (#{e})"
|
39
37
|
end
|
40
38
|
|
41
39
|
initializer 'foreman_teamdynamix.register_gettext', after: :load_config_initializers do |_app|
|
data/lib/tasks/teamdynamix.rake
CHANGED
data/locale/Makefile
CHANGED
File without changes
|
File without changes
|
File without changes
|
data/locale/gemspec.rb
CHANGED
File without changes
|
File without changes
|
@@ -7,7 +7,7 @@ class HostsControllerTest < ActionController::TestCase
|
|
7
7
|
before do
|
8
8
|
Host::Managed.any_instance.stubs(:td_api).returns(td_api)
|
9
9
|
end
|
10
|
-
# rubocop:disable Style/StringLiterals, HttpPositionalArguments
|
10
|
+
# rubocop:disable Style/StringLiterals, Rails/HttpPositionalArguments
|
11
11
|
describe 'Given host exist as an asset in TeamDynamix' do
|
12
12
|
describe 'when TeamDynamix asset attributes are configured' do
|
13
13
|
describe 'GET hosts/show' do
|
@@ -15,9 +15,10 @@ class HostsControllerTest < ActionController::TestCase
|
|
15
15
|
get :show, { :id => host.name }, set_session_user
|
16
16
|
assert_includes response.headers['Content-Type'], 'text/html'
|
17
17
|
assert_includes response.body, "<ul id=\"myTab\""
|
18
|
-
assert_equal response.status
|
18
|
+
assert_equal(200, response.status)
|
19
19
|
assert_includes response.body, "<li><a href=\"#teamdynamix\" data-toggle=\"tab\">#{td_tab_title}</a></li>"
|
20
|
-
assert_includes response.body,
|
20
|
+
assert_includes response.body,
|
21
|
+
"<div id=\"teamdynamix\" class=\"tab-pane\" data-ajax-url=\"/hosts/#{host.name}/teamdynamix\" data-on-complete=\"onContentLoad\">"
|
21
22
|
end
|
22
23
|
test 'TeamDynamix tab contains configured asset attributes' do
|
23
24
|
skip
|
@@ -27,5 +28,5 @@ class HostsControllerTest < ActionController::TestCase
|
|
27
28
|
end
|
28
29
|
end
|
29
30
|
end
|
30
|
-
# rubocop:enable Style/StringLiterals, HttpPositionalArguments
|
31
|
+
# rubocop:enable Style/StringLiterals, Rails/HttpPositionalArguments
|
31
32
|
end
|
@@ -13,7 +13,9 @@ class HostsHelperExtensionsTest < ActiveSupport::TestCase
|
|
13
13
|
describe '#teamdynamix_fields' do
|
14
14
|
let(:sample_asset) { td_api.get_asset }
|
15
15
|
let(:default_fields) { [sample_asset_uri] }
|
16
|
-
let(:direct_attribs_config)
|
16
|
+
let(:direct_attribs_config) do
|
17
|
+
{ 'Asset ID' => 'ID', 'Owner' => 'OwningCustomerName', 'Parent Asset' => 'ParentID' }
|
18
|
+
end
|
17
19
|
let(:direct_attribs_fields) { get_direct_asset_attribs_val(direct_attribs_config) }
|
18
20
|
let(:expected_fields) { default_fields + direct_attribs_fields }
|
19
21
|
before do
|
@@ -56,7 +58,7 @@ class HostsHelperExtensionsTest < ActiveSupport::TestCase
|
|
56
58
|
|
57
59
|
test 'settings title is not present: return default title' do
|
58
60
|
SETTINGS[:teamdynamix][:title] = nil
|
59
|
-
assert_equal
|
61
|
+
assert_equal('Team Dynamix', teamdynamix_title)
|
60
62
|
SETTINGS[:teamdynamix][:title] = title_orig
|
61
63
|
end
|
62
64
|
end
|
File without changes
|
data/test/sample_asset.json
CHANGED
File without changes
|
@@ -8,17 +8,19 @@ class TeamdynamixApiTest < ActiveSupport::TestCase
|
|
8
8
|
let(:api_url) { api_config[:url] }
|
9
9
|
let(:host) { FactoryBot.build(:host, :managed) }
|
10
10
|
let(:auth_payload) { { username: api_config[:username], password: api_config[:password] }.to_json }
|
11
|
-
let(:dummy_token)
|
11
|
+
let(:dummy_token) do
|
12
|
+
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1bmlxdWVfbmFtZSI6InR5YWdpbkBtaWFtaW9oLmVkdSIsImlzcyI6IlREIiwiYXVkIjoiaHR0cHM6Ly93d3cudGVhbWR5bmFtaXguY29tLyIsImV4cCI6MTUxNzA2OTU1OSwibmJmIjoxNTE2OTgzMTU5fQ.PkvKbYQCV-hY7_ni4-Zg3qJARBagSzz99fclBYyxxas'
|
13
|
+
end
|
12
14
|
let(:sample_asset) { FakeTeamdynamixApi.new.get_asset }
|
13
15
|
let(:sample_asset_id) { sample_asset['ID'].to_s }
|
14
16
|
let(:host_name) { 'delete.foreman_teamdynamix.com' }
|
15
|
-
let(:get_asset_path) { api_url
|
17
|
+
let(:get_asset_path) { "#{api_url}/#{app_id}/assets/#{sample_asset_id}" }
|
16
18
|
let(:create_status_id) { 641 }
|
17
19
|
let(:custom_attributes) do
|
18
20
|
[{ 'name' => 'mu.ci.Lifecycle Status', 'id' => 11_634, 'value' => '26193' },
|
19
21
|
{ 'name' => 'mu.ci.Description', 'id' => 11_632, 'value' => 'Foreman host created by ForemanTeamdynamix plugin' }]
|
20
22
|
end
|
21
|
-
let(:create_path) { api_url
|
23
|
+
let(:create_path) { "#{api_url}/#{app_id}/assets" }
|
22
24
|
let(:create_payload) do
|
23
25
|
{ AppID: app_id,
|
24
26
|
SerialNumber: host_name,
|
@@ -27,7 +29,7 @@ class TeamdynamixApiTest < ActiveSupport::TestCase
|
|
27
29
|
Attributes: custom_attributes }
|
28
30
|
end
|
29
31
|
before do
|
30
|
-
stub_request(:post, api_url
|
32
|
+
stub_request(:post, "#{api_url}/auth")
|
31
33
|
.with(body: auth_payload,
|
32
34
|
headers: { 'Content-Type' => 'application/json' })
|
33
35
|
.to_return(status: 200, body: dummy_token)
|
@@ -45,7 +47,7 @@ class TeamdynamixApiTest < ActiveSupport::TestCase
|
|
45
47
|
context 'Valid Request' do
|
46
48
|
before do
|
47
49
|
stub_request(:post, update_path)
|
48
|
-
.with(headers: { 'Authorization' =>
|
50
|
+
.with(headers: { 'Authorization' => "Bearer #{dummy_token}",
|
49
51
|
'Content-Type' => 'application/json' },
|
50
52
|
body: update_payload)
|
51
53
|
.to_return(status: 200, body: sample_asset.to_json)
|
@@ -67,10 +69,10 @@ class TeamdynamixApiTest < ActiveSupport::TestCase
|
|
67
69
|
end
|
68
70
|
describe 'valid request' do
|
69
71
|
let(:retired_asset) { sample_asset.merge('StatusID' => retire_status_id) }
|
70
|
-
let(:retire_path) { api_url
|
72
|
+
let(:retire_path) { "#{api_url}/#{app_id}/assets/#{sample_asset_id}" }
|
71
73
|
before do
|
72
74
|
stub_request(:post, retire_path)
|
73
|
-
.with(headers: { 'Authorization' =>
|
75
|
+
.with(headers: { 'Authorization' => "Bearer #{dummy_token}",
|
74
76
|
'Content-Type' => 'application/json' })
|
75
77
|
.to_return(status: 200, body: retired_asset.to_json)
|
76
78
|
end
|
@@ -91,7 +93,7 @@ class TeamdynamixApiTest < ActiveSupport::TestCase
|
|
91
93
|
context 'Valid Request' do
|
92
94
|
before do
|
93
95
|
stub_request(:post, create_path)
|
94
|
-
.with(headers: { 'Authorization' =>
|
96
|
+
.with(headers: { 'Authorization' => "Bearer #{dummy_token}",
|
95
97
|
'Content-Type' => 'application/json' },
|
96
98
|
body: create_payload)
|
97
99
|
.to_return(status: 200, body: sample_asset.to_json)
|
@@ -112,7 +114,7 @@ class TeamdynamixApiTest < ActiveSupport::TestCase
|
|
112
114
|
# rubocop:enable Style/StringLiterals
|
113
115
|
before do
|
114
116
|
stub_request(:post, create_path)
|
115
|
-
.with(headers: { 'Authorization' =>
|
117
|
+
.with(headers: { 'Authorization' => "Bearer #{dummy_token}",
|
116
118
|
'Content-Type' => 'application/json' },
|
117
119
|
body: create_payload)
|
118
120
|
.to_return(status: 400, body: error_body)
|
@@ -138,7 +140,7 @@ class TeamdynamixApiTest < ActiveSupport::TestCase
|
|
138
140
|
let(:error) { { status: "403", msg: "", body: error_body }.to_json }
|
139
141
|
# rubocop:enable Style/StringLiterals
|
140
142
|
before do
|
141
|
-
stub_request(:post, api_url
|
143
|
+
stub_request(:post, "#{api_url}/auth")
|
142
144
|
.with(body: auth_payload)
|
143
145
|
.to_return(status: 403, body: error_body)
|
144
146
|
end
|
@@ -154,7 +156,7 @@ class TeamdynamixApiTest < ActiveSupport::TestCase
|
|
154
156
|
context 'Valid Request' do
|
155
157
|
before do
|
156
158
|
stub_request(:get, get_asset_path)
|
157
|
-
.with(headers: { 'Authorization' =>
|
159
|
+
.with(headers: { 'Authorization' => "Bearer #{dummy_token}" })
|
158
160
|
.to_return(status: 200, body: sample_asset.to_json)
|
159
161
|
end
|
160
162
|
it 'returns asset json' do
|
data/test/test_plugin_helper.rb
CHANGED
@@ -28,7 +28,7 @@ end
|
|
28
28
|
def sample_asset_uri
|
29
29
|
api_url = SETTINGS[:teamdynamix][:api][:url]
|
30
30
|
asset_uri = api_url.split('api').first + sample_asset['Uri']
|
31
|
-
[_('URI'), link_to(sample_asset['Uri'], asset_uri, target: '_blank')]
|
31
|
+
[_('URI'), link_to(sample_asset['Uri'], asset_uri, target: '_blank', rel: 'noopener')]
|
32
32
|
end
|
33
33
|
|
34
34
|
require 'webmock/minitest'
|
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_teamdynamix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nipendar Tyagi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-08 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
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: webmock
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
115
|
requirements:
|
102
116
|
- - ">="
|
103
117
|
- !ruby/object:Gem::Version
|
104
|
-
version:
|
118
|
+
version: 2.5.0
|
105
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
120
|
requirements:
|
107
121
|
- - ">="
|
@@ -109,16 +123,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
123
|
version: '0'
|
110
124
|
requirements: []
|
111
125
|
rubyforge_project:
|
112
|
-
rubygems_version: 2.6
|
126
|
+
rubygems_version: 2.7.6
|
113
127
|
signing_key:
|
114
128
|
specification_version: 4
|
115
129
|
summary: Creates TeamDynamix Asset when a host is created in Foreman
|
116
130
|
test_files:
|
117
|
-
- test/models/host_extensions_test.rb
|
118
131
|
- test/fake_teamdynamix_api.rb
|
119
|
-
- test/test_plugin_helper.rb
|
120
|
-
- test/sample_asset.json
|
121
132
|
- test/functional/concerns/hosts_controller_extensions_test.rb
|
133
|
+
- test/helpers/concerns/foreman_teamdynamix/hosts_helper_extensions_test.rb
|
134
|
+
- test/models/host_extensions_test.rb
|
135
|
+
- test/sample_asset.json
|
122
136
|
- test/services/teamdynamix_api_test.rb
|
137
|
+
- test/test_plugin_helper.rb
|
123
138
|
- test/unit/foreman_teamdynamix_test.rb
|
124
|
-
- test/helpers/concerns/foreman_teamdynamix/hosts_helper_extensions_test.rb
|