foreman_expire_hosts 8.1.0 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/app/helpers/foreman_expire_hosts/hosts_helper.rb +19 -0
- data/{lib → app/lib}/expire_hosts_notifications.rb +3 -2
- data/app/models/concerns/foreman_expire_hosts/host_ext.rb +3 -3
- data/lib/foreman_expire_hosts/engine.rb +55 -60
- data/lib/foreman_expire_hosts/version.rb +1 -1
- data/test/helpers/hosts_helper_test.rb +5 -1
- metadata +4 -8
- data/app/helpers/concerns/foreman_expire_hosts/hosts_helper_extensions.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 278bb558393256952a91c75901f1776bdab5314e43d9b10218ed06f1ac765fc9
|
4
|
+
data.tar.gz: b80fd1acc8b31a12b8be1f2464dd67633364db992a1dd414d06e0d792ede6f57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10c0283b3ecc5974c9faed866002002eef7c2ace0caf6549f0c311161e869bae7bb76f2d99fd8b068a6c8093186981e529feade1ffe3218028faf949b10bc950
|
7
|
+
data.tar.gz: 5251612576cb29e79686379c33029b9594521d89d0fa513912fa9c41361a619d5095c1a08bbdda4adc56104b7731f68d29833109154f72860d626b6fe576cf98
|
data/README.md
CHANGED
@@ -20,6 +20,7 @@ This plugin will send two warning notifications before host expiry (see Settings
|
|
20
20
|
| >= 1.18 | ~> 6.0 |
|
21
21
|
| >= 1.24 | ~> 7.0 |
|
22
22
|
| >= 3.0 | ~> 8.0 |
|
23
|
+
| >= 3.13 | ~> 9.0 |
|
23
24
|
|
24
25
|
# Screenshots
|
25
26
|

|
@@ -12,5 +12,24 @@ module ForemanExpireHosts
|
|
12
12
|
end
|
13
13
|
actions
|
14
14
|
end
|
15
|
+
|
16
|
+
def host_expiry_warning_message(host)
|
17
|
+
return nil unless host.expires?
|
18
|
+
|
19
|
+
if host.expired_past_grace_period?
|
20
|
+
message = _('This host has expired %s ago and needs to be deleted manually.') % time_ago_in_words(host.expired_on)
|
21
|
+
elsif host.expired?
|
22
|
+
message = _('This host has expired %{time_ago} ago and will be deleted on %{delete_date}.') % { :delete_date => l(host.expiration_grace_period_end_date), :time_ago => time_ago_in_words(host.expired_on) }
|
23
|
+
elsif host.expires_today?
|
24
|
+
message = _('This host will expire today.')
|
25
|
+
elsif host.pending_expiration?
|
26
|
+
message = _('This host will expire in %{distance_of_time} (on %{expire_date}).') % { :expire_date => l(host.expired_on), :distance_of_time => future_time_in_words(host.expired_on) }
|
27
|
+
end
|
28
|
+
message
|
29
|
+
end
|
30
|
+
|
31
|
+
def future_time_in_words(to_time, options = {})
|
32
|
+
distance_of_time_in_words(to_time, Time.current, options)
|
33
|
+
end
|
15
34
|
end
|
16
35
|
end
|
@@ -10,11 +10,12 @@ module ExpireHostsNotifications
|
|
10
10
|
ForemanExpireHosts::Action::StopExpiredHosts.new.engage
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
# notify1_days_before_expiry
|
14
|
+
def deliver_expiry_warning_notification(num = 1)
|
14
15
|
return unless [1, 2].include?(num)
|
15
16
|
|
16
17
|
days_before_expiry = Setting["notify#{num}_days_before_host_expiry"].to_i
|
17
|
-
expiry_date = (
|
18
|
+
expiry_date = (Time.zone.today + days_before_expiry)
|
18
19
|
notifiable_hosts = Host.with_expire_date(expiry_date).preload(:owner)
|
19
20
|
|
20
21
|
ForemanExpireHosts::Notification::ExpiryWarning.new(
|
@@ -55,20 +55,20 @@ module ForemanExpireHosts
|
|
55
55
|
def expiration_grace_period_end_date
|
56
56
|
return nil unless expires?
|
57
57
|
|
58
|
-
expired_on.to_date + Setting[:days_to_delete_after_host_expiration].to_i
|
58
|
+
expired_on.to_date + Setting[:days_to_delete_after_host_expiration].to_i.days
|
59
59
|
end
|
60
60
|
|
61
61
|
def expired_past_grace_period?
|
62
62
|
return false unless expires?
|
63
63
|
|
64
|
-
expiration_grace_period_end_date <= Date.today
|
64
|
+
expiration_grace_period_end_date.to_date <= Date.today
|
65
65
|
end
|
66
66
|
|
67
67
|
def pending_expiration?
|
68
68
|
return false unless expires?
|
69
69
|
return false if expired?
|
70
70
|
|
71
|
-
expired_on - Setting['notify1_days_before_host_expiry'].to_i <= Date.today
|
71
|
+
expired_on.to_date - Setting['notify1_days_before_host_expiry'].to_i.days <= Date.today
|
72
72
|
end
|
73
73
|
|
74
74
|
def can_modify_expiry_date?
|
@@ -6,12 +6,6 @@ module ForemanExpireHosts
|
|
6
6
|
class Engine < ::Rails::Engine
|
7
7
|
engine_name 'foreman_expire_hosts'
|
8
8
|
|
9
|
-
config.autoload_paths += Dir["#{config.root}/lib"]
|
10
|
-
config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
|
11
|
-
config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"]
|
12
|
-
config.autoload_paths += Dir["#{config.root}/app/helpers/concerns"]
|
13
|
-
config.autoload_paths += Dir["#{config.root}/app/services"]
|
14
|
-
|
15
9
|
# Add any db migrations
|
16
10
|
initializer 'foreman_plugin_template.load_app_instance_data' do |app|
|
17
11
|
ForemanExpireHosts::Engine.paths['db/migrate'].existent.each do |path|
|
@@ -19,67 +13,69 @@ module ForemanExpireHosts
|
|
19
13
|
end
|
20
14
|
end
|
21
15
|
|
22
|
-
initializer 'foreman_expire_hosts.register_plugin', :before => :finisher_hook do |
|
23
|
-
|
24
|
-
|
25
|
-
|
16
|
+
initializer 'foreman_expire_hosts.register_plugin', :before => :finisher_hook do |app|
|
17
|
+
app.reloader.to_prepare do
|
18
|
+
Foreman::Plugin.register :foreman_expire_hosts do
|
19
|
+
requires_foreman '>= 3.13.0'
|
20
|
+
register_custom_status HostStatus::ExpirationStatus
|
26
21
|
|
27
|
-
|
28
|
-
|
22
|
+
# strong parameters
|
23
|
+
parameter_filter Host::Managed, :expired_on
|
29
24
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
25
|
+
security_block :foreman_expire_hosts do
|
26
|
+
permission :edit_host_expiry,
|
27
|
+
{},
|
28
|
+
:resource_type => 'Host'
|
29
|
+
end
|
35
30
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
31
|
+
# Extend built in permissions
|
32
|
+
Foreman::AccessControl.permission(:edit_hosts).actions.concat [
|
33
|
+
'hosts/select_multiple_expiration',
|
34
|
+
'hosts/update_multiple_expiration'
|
35
|
+
]
|
41
36
|
|
42
|
-
|
37
|
+
Setting::BLANK_ATTRS << 'host_expiry_email_recipients'
|
43
38
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
39
|
+
settings do
|
40
|
+
category(:expire_hosts, N_('Expire Hosts')) do
|
41
|
+
setting('is_host_expiry_date_mandatory',
|
42
|
+
type: :boolean,
|
43
|
+
description: N_('Make expiry date field mandatory on host creation/update'),
|
44
|
+
default: false,
|
45
|
+
full_name: N_('Require host expiry date'))
|
46
|
+
setting('can_owner_modify_host_expiry_date',
|
47
|
+
type: :boolean,
|
48
|
+
description: N_('Allow host owner to modify host expiry date field. If the field is false then admin only can edit expiry field'),
|
49
|
+
default: false,
|
50
|
+
full_name: N_('Host owner can modify host expiry date'))
|
51
|
+
setting('notify1_days_before_host_expiry',
|
52
|
+
type: :integer,
|
53
|
+
description: N_('Send first notification to owner of hosts about his hosts expiring in given days. Must be integer only'),
|
54
|
+
default: 7,
|
55
|
+
full_name: N_('First expiry notification'))
|
56
|
+
setting('notify2_days_before_host_expiry',
|
57
|
+
type: :integer,
|
58
|
+
description: N_('Send second notification to owner of hosts about his hosts expiring in given days. Must be integer only'),
|
59
|
+
default: 1,
|
60
|
+
full_name: N_('Second expiry notification'))
|
61
|
+
setting('days_to_delete_after_host_expiration',
|
62
|
+
type: :integer,
|
63
|
+
description: N_('Delete expired hosts after given days of hosts expiry date. Must be integer only'),
|
64
|
+
default: 3,
|
65
|
+
full_name: N_('Expiry grace period in days'))
|
66
|
+
setting('host_expiry_email_recipients',
|
67
|
+
type: :string,
|
68
|
+
description: N_('All notifications will be delivered to its owner. If any other users/admins need to receive those expiry warning notifications then those emails can be configured comma separated here.'), # rubocop:disable Layout/LineLength
|
69
|
+
default: nil,
|
70
|
+
full_name: N_('Expiry e-mail recipients'))
|
71
|
+
end
|
76
72
|
end
|
77
|
-
end
|
78
73
|
|
79
|
-
|
74
|
+
extend_rabl_template 'api/v2/hosts/main', 'api/v2/hosts/expiration'
|
80
75
|
|
81
|
-
|
82
|
-
|
76
|
+
describe_host do
|
77
|
+
multiple_actions_provider :expire_hosts_host_multiple_actions
|
78
|
+
end
|
83
79
|
end
|
84
80
|
end
|
85
81
|
end
|
@@ -87,7 +83,6 @@ module ForemanExpireHosts
|
|
87
83
|
config.to_prepare do
|
88
84
|
begin
|
89
85
|
::Host::Managed.include ForemanExpireHosts::HostExt
|
90
|
-
::HostsHelper.include ForemanExpireHosts::HostsHelperExtensions
|
91
86
|
::HostsController.prepend ForemanExpireHosts::HostControllerExtensions
|
92
87
|
::AuditsHelper.include ForemanExpireHosts::AuditsHelperExtensions
|
93
88
|
::Api::V2::HostsController.include ForemanExpireHosts::Api::V2::HostsControllerExtensions
|
@@ -5,7 +5,11 @@ require 'test_plugin_helper'
|
|
5
5
|
class HostsHelperTest < ActionView::TestCase
|
6
6
|
include HostsHelper
|
7
7
|
include HostDescriptionHelper
|
8
|
-
|
8
|
+
# Foreman 3.7 dropped this via
|
9
|
+
# https://github.com/theforeman/foreman/commit/6cdb8c7a9ebd790537510213e43537a4a87189d6
|
10
|
+
# Foreman 3.9 bought it back via
|
11
|
+
# https://github.com/theforeman/foreman/commit/37a99c70ebd9e4d6f03af546dfe36e7678e2bcf3
|
12
|
+
include PuppetRelatedHelper if defined?(PuppetRelatedHelper)
|
9
13
|
include ForemanExpireHosts::HostsHelper
|
10
14
|
include ApplicationHelper
|
11
15
|
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_expire_hosts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 9.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nagarjuna Rachaneni
|
8
8
|
- Timo Goebel
|
9
|
-
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2025-06-17 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: deface
|
@@ -54,9 +53,9 @@ files:
|
|
54
53
|
- app/controllers/concerns/foreman_expire_hosts/api/v2/hosts_controller_extensions.rb
|
55
54
|
- app/controllers/concerns/foreman_expire_hosts/host_controller_extensions.rb
|
56
55
|
- app/helpers/concerns/foreman_expire_hosts/audits_helper_extensions.rb
|
57
|
-
- app/helpers/concerns/foreman_expire_hosts/hosts_helper_extensions.rb
|
58
56
|
- app/helpers/expire_hosts_mailer_helper.rb
|
59
57
|
- app/helpers/foreman_expire_hosts/hosts_helper.rb
|
58
|
+
- app/lib/expire_hosts_notifications.rb
|
60
59
|
- app/mailers/expire_hosts_mailer.rb
|
61
60
|
- app/models/concerns/foreman_expire_hosts/host_ext.rb
|
62
61
|
- app/models/host_status/expiration_status.rb
|
@@ -93,7 +92,6 @@ files:
|
|
93
92
|
- db/migrate/20230112104438_change_expired_on_type.rb
|
94
93
|
- db/seeds.d/80_expire_hosts_ui_notification.rb
|
95
94
|
- extra/foreman_expire_hosts.cron
|
96
|
-
- lib/expire_hosts_notifications.rb
|
97
95
|
- lib/foreman_expire_hosts.rb
|
98
96
|
- lib/foreman_expire_hosts/engine.rb
|
99
97
|
- lib/foreman_expire_hosts/version.rb
|
@@ -113,7 +111,6 @@ homepage: https://github.com/theforeman/foreman_expire_hosts
|
|
113
111
|
licenses:
|
114
112
|
- GPL-3.0
|
115
113
|
metadata: {}
|
116
|
-
post_install_message:
|
117
114
|
rdoc_options: []
|
118
115
|
require_paths:
|
119
116
|
- lib
|
@@ -128,8 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
125
|
- !ruby/object:Gem::Version
|
129
126
|
version: '0'
|
130
127
|
requirements: []
|
131
|
-
rubygems_version: 3.
|
132
|
-
signing_key:
|
128
|
+
rubygems_version: 3.6.7
|
133
129
|
specification_version: 4
|
134
130
|
summary: Foreman plugin for limiting host lifetime
|
135
131
|
test_files:
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ForemanExpireHosts
|
4
|
-
module HostsHelperExtensions
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
|
7
|
-
def host_expiry_warning_message(host)
|
8
|
-
return nil unless host.expires?
|
9
|
-
|
10
|
-
if host.expired_past_grace_period?
|
11
|
-
message = _('This host has expired %s ago and needs to be deleted manually.') % time_ago_in_words(host.expired_on)
|
12
|
-
elsif host.expired?
|
13
|
-
message = _('This host has expired %{time_ago} ago and will be deleted on %{delete_date}.') % { :delete_date => l(host.expiration_grace_period_end_date), :time_ago => time_ago_in_words(host.expired_on) }
|
14
|
-
elsif host.expires_today?
|
15
|
-
message = _('This host will expire today.')
|
16
|
-
elsif host.pending_expiration?
|
17
|
-
message = _('This host will expire in %{distance_of_time} (on %{expire_date}).') % { :expire_date => l(host.expired_on), :distance_of_time => future_time_in_words(host.expired_on) }
|
18
|
-
end
|
19
|
-
message
|
20
|
-
end
|
21
|
-
|
22
|
-
def future_time_in_words(to_time, options = {})
|
23
|
-
distance_of_time_in_words(to_time, Time.current, options)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|