foreman_expire_hosts 6.0.1 → 6.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/Gemfile +2 -0
- data/app/controllers/concerns/foreman_expire_hosts/api/v2/hosts_controller_extensions.rb +2 -0
- data/app/controllers/concerns/foreman_expire_hosts/host_controller_extensions.rb +5 -3
- data/app/helpers/concerns/foreman_expire_hosts/audits_helper_extensions.rb +2 -0
- data/app/helpers/concerns/foreman_expire_hosts/hosts_helper_extensions.rb +2 -0
- data/app/helpers/expire_hosts_mailer_helper.rb +2 -0
- data/app/mailers/expire_hosts_mailer.rb +2 -0
- data/app/models/concerns/foreman_expire_hosts/host_ext.rb +3 -1
- data/app/models/host_status/expiration_status.rb +2 -0
- data/app/models/setting/expire_hosts.rb +2 -0
- data/app/overrides/add_expired_on_field_to_host_form.rb +2 -0
- data/app/overrides/add_expired_on_field_to_host_show.rb +2 -0
- data/app/overrides/add_js_to_host_index.rb +2 -0
- data/app/overrides/deleted_expired_host_comment_in_audits.rb +2 -0
- data/app/services/foreman_expire_hosts/action/base.rb +2 -0
- data/app/services/foreman_expire_hosts/action/delete_expired_hosts.rb +2 -0
- data/app/services/foreman_expire_hosts/action/stop_expired_hosts.rb +2 -0
- data/app/services/foreman_expire_hosts/expiry_edit_authorizer.rb +2 -0
- data/app/services/foreman_expire_hosts/notification/base.rb +4 -2
- data/app/services/foreman_expire_hosts/notification/deleted_hosts.rb +2 -0
- data/app/services/foreman_expire_hosts/notification/expiry_warning.rb +2 -0
- data/app/services/foreman_expire_hosts/notification/failed_deleted_hosts.rb +2 -0
- data/app/services/foreman_expire_hosts/notification/failed_stopped_hosts.rb +2 -0
- data/app/services/foreman_expire_hosts/notification/stopped_hosts.rb +2 -0
- data/app/services/foreman_expire_hosts/safe_destroy.rb +6 -4
- data/app/services/foreman_expire_hosts/ui_notifications/hosts/base.rb +2 -0
- data/app/services/foreman_expire_hosts/ui_notifications/hosts/expiry_warning.rb +2 -0
- data/app/services/foreman_expire_hosts/ui_notifications/hosts/stopped_host.rb +2 -0
- data/app/views/api/v2/hosts/expiration.json.rabl +2 -0
- data/config/routes.rb +2 -0
- data/db/migrate/20150427101516_add_expiry_on_to_hosts.rb +2 -0
- data/db/seeds.d/80_expire_hosts_ui_notification.rb +2 -0
- data/foreman_expire_hosts.gemspec +3 -1
- data/lib/expire_hosts_notifications.rb +2 -0
- data/lib/foreman_expire_hosts.rb +2 -0
- data/lib/foreman_expire_hosts/engine.rb +8 -3
- data/lib/foreman_expire_hosts/version.rb +3 -1
- data/lib/tasks/expired_hosts.rake +2 -0
- data/test/factories/foreman_expire_hosts_factories.rb +2 -0
- data/test/functional/api/v2/hosts_controller_test.rb +2 -0
- data/test/functional/concerns/hosts_controller_extensions_test.rb +2 -0
- data/test/helpers/hosts_helper_test.rb +2 -0
- data/test/lib/expire_hosts_notifications_test.rb +19 -0
- data/test/test_plugin_helper.rb +2 -0
- data/test/unit/concerns/host_extensions_test.rb +3 -1
- data/test/unit/expire_hosts_mailer_test.rb +6 -0
- data/test/unit/expiry_edit_authorizer_test.rb +2 -0
- data/test/unit/host_status/expiration_status_test.rb +2 -0
- data/test/unit/safe_destroy_test.rb +2 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa01a7018582689c460e28a5e27dff4e4372ff655399ee622bf45532ece9abc6
|
4
|
+
data.tar.gz: fb08933cd67d1b5b9bf322431e322812a189498407e23b2203322d2bc4072006
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02c674e4fd329fe84e740fc752ae0db2ac5e1a0619ef3d2ab4fd4001bba6c94a9c03d5854a206a81a638a3bf1ce27210a123c1e70d32da573124e93d73a7cfeb
|
7
|
+
data.tar.gz: 0c046cf84b6d6b2b6045b941f714f847d1903703d4c8a1f3988b94ffa3363804bf89faf8ffc6c5d63b3a1369ee56f25d3dedeee97f9ec0d7f297b73f9d92b2ca
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ForemanExpireHosts
|
2
4
|
module HostControllerExtensions
|
3
5
|
def self.prepended(base)
|
@@ -20,14 +22,14 @@ module ForemanExpireHosts
|
|
20
22
|
begin
|
21
23
|
host.expired_on = expiration_date
|
22
24
|
host.save!
|
23
|
-
rescue StandardError =>
|
24
|
-
failed_hosts[host.name] =
|
25
|
+
rescue StandardError => e
|
26
|
+
failed_hosts[host.name] = e
|
25
27
|
message = if expiration_date.present?
|
26
28
|
_('Failed to set expiration date for %{host} to %{expiration_date}.') % { :host => host, :expiration_date => l(expiration_date) }
|
27
29
|
else
|
28
30
|
_('Failed to clear expiration date for %s.') % host
|
29
31
|
end
|
30
|
-
Foreman::Logging.exception(message,
|
32
|
+
Foreman::Logging.exception(message, e)
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ForemanExpireHosts
|
2
4
|
module HostExt
|
3
5
|
extend ActiveSupport::Concern
|
@@ -13,7 +15,7 @@ module ForemanExpireHosts
|
|
13
15
|
|
14
16
|
scope :expiring, -> { where('expired_on IS NOT NULL') }
|
15
17
|
scope :with_expire_date, ->(date) { expiring.where('expired_on = ?', date) }
|
16
|
-
scope :expired, -> { expiring.where('expired_on
|
18
|
+
scope :expired, -> { expiring.where('expired_on <= ?', Date.today) }
|
17
19
|
scope :expiring_today, -> { expiring.with_expire_date(Date.today) }
|
18
20
|
scope :expired_past_grace_period, -> { expiring.where('expired_on <= ?', Date.today - Setting[:days_to_delete_after_host_expiration].to_i) }
|
19
21
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ForemanExpireHosts
|
2
4
|
module Notification
|
3
5
|
class Base
|
@@ -27,12 +29,12 @@ module ForemanExpireHosts
|
|
27
29
|
return true if hosts.empty?
|
28
30
|
|
29
31
|
build_mail_notification(recipient, hosts).deliver_now
|
30
|
-
rescue SocketError, Net::SMTPError =>
|
32
|
+
rescue SocketError, Net::SMTPError => e
|
31
33
|
message = _('Failed to deliver %{notification_name} for Hosts %{hosts}') % {
|
32
34
|
:notification_name => humanized_name,
|
33
35
|
:hosts => hosts.map(&:name).to_sentence
|
34
36
|
}
|
35
|
-
Foreman::Logging.exception(message,
|
37
|
+
Foreman::Logging.exception(message, e)
|
36
38
|
end
|
37
39
|
|
38
40
|
def deliver_ui_notifications
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ForemanExpireHosts
|
2
4
|
class SafeDestroy
|
3
5
|
# See http://projects.theforeman.org/issues/14702 for reasoning.
|
@@ -17,14 +19,14 @@ module ForemanExpireHosts
|
|
17
19
|
else
|
18
20
|
subject.destroy!
|
19
21
|
end
|
20
|
-
rescue ActiveRecord::RecordNotDestroyed =>
|
22
|
+
rescue ActiveRecord::RecordNotDestroyed => e
|
21
23
|
message = _('Failed to delete %{class_name} %{subject}: %{message} - Errors: %{errors}') % {
|
22
24
|
:class_name => subject.class.name,
|
23
25
|
:subject => subject,
|
24
|
-
:message =>
|
25
|
-
:errors =>
|
26
|
+
:message => e.message,
|
27
|
+
:errors => e.record.errors.full_messages.to_sentence
|
26
28
|
}
|
27
|
-
Foreman::Logging.exception(message,
|
29
|
+
Foreman::Logging.exception(message, e)
|
28
30
|
false
|
29
31
|
end
|
30
32
|
|
data/config/routes.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
Foreman::Application.routes.draw do
|
2
4
|
post 'expired_hosts/select_multiple_expiration' => 'hosts#select_multiple_expiration', as: 'select_multiple_expiration_hosts'
|
3
5
|
post 'expired_hosts/update_multiple_expiration' => 'hosts#update_multiple_expiration', as: 'update_multiple_expiration_hosts'
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require File.expand_path('lib/foreman_expire_hosts/version', __dir__)
|
2
4
|
require 'date'
|
3
5
|
|
@@ -22,5 +24,5 @@ Gem::Specification.new do |s|
|
|
22
24
|
s.add_dependency 'deface'
|
23
25
|
|
24
26
|
s.add_development_dependency 'rdoc'
|
25
|
-
s.add_development_dependency 'rubocop', '0.
|
27
|
+
s.add_development_dependency 'rubocop', '0.71.0'
|
26
28
|
end
|
data/lib/foreman_expire_hosts.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'deface'
|
2
4
|
require 'bootstrap-datepicker-rails'
|
3
5
|
|
@@ -34,11 +36,14 @@ module ForemanExpireHosts
|
|
34
36
|
permission :edit_host_expiry,
|
35
37
|
{},
|
36
38
|
:resource_type => 'Host'
|
37
|
-
permission :edit_hosts,
|
38
|
-
{ :hosts => [:select_multiple_expiration, :update_multiple_expiration] },
|
39
|
-
:resource_type => 'Host'
|
40
39
|
end
|
41
40
|
|
41
|
+
# Extend built in permissions
|
42
|
+
Foreman::AccessControl.permission(:edit_hosts).actions.concat [
|
43
|
+
'hosts/select_multiple_expiration',
|
44
|
+
'hosts/update_multiple_expiration'
|
45
|
+
]
|
46
|
+
|
42
47
|
extend_rabl_template 'api/v2/hosts/main', 'api/v2/hosts/expiration'
|
43
48
|
end
|
44
49
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_plugin_helper'
|
2
4
|
require 'notifications_test_helper'
|
3
5
|
|
@@ -117,6 +119,23 @@ class ExpireHostsNotificationsTest < ActiveSupport::TestCase
|
|
117
119
|
assert_equal 1, ActionMailer::Base.deliveries.count
|
118
120
|
assert_includes ActionMailer::Base.deliveries.first.subject, 'Failed to stop expired hosts'
|
119
121
|
end
|
122
|
+
|
123
|
+
context 'with a host expiring today' do
|
124
|
+
let(:host) { FactoryBot.create(:host, :expires_today, :on_compute_resource, :owner => user) }
|
125
|
+
let(:delete_date) { Date.today + Setting[:days_to_delete_after_host_expiration].to_i }
|
126
|
+
|
127
|
+
it 'should stop the host and show the correct delete date' do
|
128
|
+
power_mock.expects(:stop).returns(true)
|
129
|
+
ExpireHostsNotifications.stop_expired_hosts
|
130
|
+
assert_equal 1, ActionMailer::Base.deliveries.count
|
131
|
+
assert_includes ActionMailer::Base.deliveries.first.subject, 'Stopped expired hosts'
|
132
|
+
assert_includes ActionMailer::Base.deliveries.first.body, "These hosts will be destroyed on #{delete_date}."
|
133
|
+
|
134
|
+
travel_to delete_date do
|
135
|
+
assert_includes Host.expired_past_grace_period, host
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
120
139
|
end
|
121
140
|
|
122
141
|
context '#deliver_expiry_warning_notification' do
|
data/test/test_plugin_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_plugin_helper'
|
2
4
|
|
3
5
|
class ForemanExpireHostsHostExtTest < ActiveSupport::TestCase
|
@@ -180,7 +182,7 @@ class ForemanExpireHostsHostExtTest < ActiveSupport::TestCase
|
|
180
182
|
end
|
181
183
|
|
182
184
|
test 'should only exist in correct scopes' do
|
183
|
-
exists_only_in_scopes(@host, ['expiring', 'expiring_today'])
|
185
|
+
exists_only_in_scopes(@host, ['expiring', 'expired', 'expiring_today'])
|
184
186
|
end
|
185
187
|
end
|
186
188
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_plugin_helper'
|
2
4
|
|
3
5
|
class ExpireHostMailerTest < ActionMailer::TestCase
|
@@ -35,6 +37,10 @@ class ExpireHostMailerTest < ActionMailer::TestCase
|
|
35
37
|
assert_includes mail.subject, 'Stopped expired hosts in Foreman'
|
36
38
|
end
|
37
39
|
|
40
|
+
test 'should include a deletion date' do
|
41
|
+
assert_includes mail.body, "These hosts will be destroyed on #{Date.today}."
|
42
|
+
end
|
43
|
+
|
38
44
|
test 'should show mitigation text if authorized' do
|
39
45
|
ForemanExpireHosts::ExpiryEditAuthorizer.any_instance.stubs(:authorized?).returns(true)
|
40
46
|
assert_includes mail.body.to_s, 'Please change their expiry date'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_expire_hosts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.0.
|
4
|
+
version: 6.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nagarjuna Rachaneni
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-08-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bootstrap-datepicker-rails
|
@@ -59,14 +59,14 @@ dependencies:
|
|
59
59
|
requirements:
|
60
60
|
- - '='
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: 0.
|
62
|
+
version: 0.71.0
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - '='
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: 0.
|
69
|
+
version: 0.71.0
|
70
70
|
description: This Plugin will add new column expired_on to hosts to limit the lifetime
|
71
71
|
of a host.
|
72
72
|
email:
|