foreman_expire_hosts 8.0.0 → 8.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/app/controllers/concerns/foreman_expire_hosts/host_controller_extensions.rb +2 -7
- data/app/helpers/concerns/foreman_expire_hosts/hosts_helper_extensions.rb +0 -7
- data/app/models/concerns/foreman_expire_hosts/host_ext.rb +1 -1
- data/app/models/host_status/expiration_status.rb +4 -4
- data/app/services/foreman_expire_hosts/safe_destroy.rb +1 -1
- data/app/views/expire_hosts_mailer/_hosts_table.html.erb +0 -6
- data/app/views/hosts/_expired_on_field.html.erb +12 -13
- data/app/views/hosts/select_multiple_expiration.html.erb +6 -15
- data/db/migrate/20220923181700_fix_settings_category_to_dsl.rb +1 -1
- data/db/migrate/20230112104438_change_expired_on_type.rb +11 -0
- data/lib/foreman_expire_hosts/engine.rb +2 -0
- data/lib/foreman_expire_hosts/version.rb +1 -1
- data/lib/tasks/expired_hosts.rake +3 -18
- data/test/functional/concerns/hosts_controller_extensions_test.rb +3 -5
- data/test/lib/expire_hosts_notifications_test.rb +0 -1
- data/test/test_plugin_helper.rb +0 -4
- data/test/unit/concerns/host_extensions_test.rb +0 -1
- data/test/unit/expire_hosts_mailer_test.rb +1 -5
- data/test/unit/expiry_edit_authorizer_test.rb +0 -1
- metadata +4 -59
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74607c8b578a2549b16b8858c186dec33519fbec2f21c946e30d3b01b8c8ee13
|
4
|
+
data.tar.gz: d07c8068f7a85eb297d95c461abf65c1951409ba483c6bc5329c8abee318def5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c214dc0b884be13b4195ef443079db7a524839279aee288addace26dbd61e3d170e984f3468377dfba59cb89bb8521f4c18fa8667ad133bbb6b364e4514f1ab
|
7
|
+
data.tar.gz: 1e68621e1fb15baa5a94d40f080daecc55ad2fcbec4aedfd97b70fc5ec750c3198a3ff4e227743fe03e5cb95c603189dee628de2b265da8cb4d8ac7627643b07
|
data/README.md
CHANGED
@@ -19,6 +19,7 @@ This plugin will send two warning notifications before host expiry (see Settings
|
|
19
19
|
| >= 1.17 | ~> 5.0 |
|
20
20
|
| >= 1.18 | ~> 6.0 |
|
21
21
|
| >= 1.24 | ~> 7.0 |
|
22
|
+
| >= 3.0 | ~> 8.0 |
|
22
23
|
|
23
24
|
# Screenshots
|
24
25
|
![Expiry date field in host form](https://raw.githubusercontent.com/ingenico-group/screenshots/master/foreman_host_expiry/expiry-date-field-in-host-form.png)
|
@@ -55,13 +55,8 @@ module ForemanExpireHosts
|
|
55
55
|
|
56
56
|
def expiration_date
|
57
57
|
@expiration_date ||= begin
|
58
|
-
|
59
|
-
|
60
|
-
day = params['host']['expired_on(3i)']
|
61
|
-
|
62
|
-
return if year.empty? && month.empty? && day.empty?
|
63
|
-
|
64
|
-
Date.parse("#{year}-#{month}-#{day}")
|
58
|
+
expired_on = params[:host][:expired_on]
|
59
|
+
expired_on.present? ? Date.parse(expired_on) : nil
|
65
60
|
end
|
66
61
|
end
|
67
62
|
|
@@ -22,12 +22,5 @@ module ForemanExpireHosts
|
|
22
22
|
def future_time_in_words(to_time, options = {})
|
23
23
|
distance_of_time_in_words(to_time, Time.current, options)
|
24
24
|
end
|
25
|
-
|
26
|
-
def datepicker_f(form, attr, options = {}, html_options = {})
|
27
|
-
field(form, attr, options) do
|
28
|
-
addClass options, 'form-control'
|
29
|
-
form.date_select(attr, options, html_options)
|
30
|
-
end
|
31
|
-
end
|
32
25
|
end
|
33
26
|
end
|
@@ -55,7 +55,7 @@ module ForemanExpireHosts
|
|
55
55
|
def expiration_grace_period_end_date
|
56
56
|
return nil unless expires?
|
57
57
|
|
58
|
-
expired_on + Setting[:days_to_delete_after_host_expiration].to_i
|
58
|
+
expired_on.to_date + Setting[:days_to_delete_after_host_expiration].to_i
|
59
59
|
end
|
60
60
|
|
61
61
|
def expired_past_grace_period?
|
@@ -41,15 +41,15 @@ module HostStatus
|
|
41
41
|
def to_label(_options = {})
|
42
42
|
case to_status
|
43
43
|
when OK
|
44
|
-
N_('Expires on %s') % I18n.l(host.expired_on)
|
44
|
+
N_('Expires on %s') % I18n.l(host.expired_on.to_date)
|
45
45
|
when EXPIRES_TODAY
|
46
46
|
N_('Expires today')
|
47
47
|
when IN_GRACE_PERIOD
|
48
|
-
N_('Expired on %s, in grace period') % I18n.l(host.expired_on)
|
48
|
+
N_('Expired on %s, in grace period') % I18n.l(host.expired_on.to_date)
|
49
49
|
when EXPIRED
|
50
|
-
N_('Expired on %s') % I18n.l(host.expired_on)
|
50
|
+
N_('Expired on %s') % I18n.l(host.expired_on.to_date)
|
51
51
|
else
|
52
|
-
N_('Pending expiration on %s') % I18n.l(host.expired_on)
|
52
|
+
N_('Pending expiration on %s') % I18n.l(host.expired_on.to_date)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
@@ -7,9 +7,6 @@
|
|
7
7
|
<th>
|
8
8
|
<%= _('Host group') %>
|
9
9
|
</th>
|
10
|
-
<th>
|
11
|
-
<%= _('Environment') %>
|
12
|
-
</th>
|
13
10
|
<th>
|
14
11
|
<%= _('Expiration Date') %>
|
15
12
|
</th>
|
@@ -28,9 +25,6 @@
|
|
28
25
|
<td class="hosts-rows">
|
29
26
|
<%= host.hostgroup %>
|
30
27
|
</td>
|
31
|
-
<td class="hosts-rows">
|
32
|
-
<%= host.environment %>
|
33
|
-
</td>
|
34
28
|
<td class="hosts-rows">
|
35
29
|
<%= "#{l(host.expired_on)} (#{relative_date(host.expired_on)})" if host.expires? %>
|
36
30
|
</td>
|
@@ -1,13 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
%>
|
1
|
+
<div class="form-group">
|
2
|
+
<label class="col-md-2 control-label"><%= _('Expires on') %></label>
|
3
|
+
<% if @host.can_modify_expiry_date? %>
|
4
|
+
<div class="col-md-4">
|
5
|
+
<%= react_component('DatePicker', { value: @host.expired_on, name: 'host[expired_on]', placement: 'bottom' }.to_json) %>
|
6
|
+
<%= content_tag(:span, _('Expired hosts will be deleted automatically after the grace period has passed. If you do not want this host to expire and do not want it to be deleted automatically, do not specify an expiry date.'), class: 'help-block help-inline') %>
|
7
|
+
</div>
|
8
|
+
<% else %>
|
9
|
+
<%= content_tag(:span, @host.expired_on&.to_s(:long), class: 'col-md-4') %>
|
10
|
+
<%= content_tag(:span, _('You are not allowed to change the expiry date of this host.'), class: 'help-block help-inline') %>
|
11
|
+
<% end %>
|
12
|
+
</div>
|
@@ -1,18 +1,9 @@
|
|
1
1
|
<%= render 'selected_hosts', :hosts => @hosts %>
|
2
2
|
|
3
|
-
<%= form_for :host, :url => update_multiple_expiration_hosts_path(:host_ids => params[:host_ids]) do |f| %>
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
:autocomplete => false,
|
10
|
-
:include_blank => true,
|
11
|
-
:use_month_numbers => false,
|
12
|
-
:start_year => Date.today.year
|
13
|
-
},
|
14
|
-
{
|
15
|
-
:onchange => 'tfm.hosts.table.toggleMultipleOkButton(this);'
|
16
|
-
}
|
17
|
-
%>
|
3
|
+
<%= form_for :host, html: { style: 'padding-bottom: 250px;' }, :url => update_multiple_expiration_hosts_path(:host_ids => params[:host_ids]) do |f| %>
|
4
|
+
<%= date_local_f f, :expired_on,
|
5
|
+
label: _('Expired on'),
|
6
|
+
label_help: _('Hosts will be deleted automatically on the given expiry date. Leave blank to clear expiration date.'),
|
7
|
+
placement: 'bottom'
|
8
|
+
%>
|
18
9
|
<% end %>
|
@@ -2,6 +2,6 @@
|
|
2
2
|
|
3
3
|
class FixSettingsCategoryToDsl < ActiveRecord::Migration[6.0]
|
4
4
|
def up
|
5
|
-
Setting.where(category: 'Setting::ExpireHost').update_all(category: 'Setting')
|
5
|
+
Setting.where(category: 'Setting::ExpireHost').update_all(category: 'Setting') if column_exists?(:settings, :category)
|
6
6
|
end
|
7
7
|
end
|
@@ -25,24 +25,9 @@ namespace :test do
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
namespace :foreman_expire_hosts do
|
29
|
-
task :rubocop => :environment do
|
30
|
-
begin
|
31
|
-
require 'rubocop/rake_task'
|
32
|
-
RuboCop::RakeTask.new(:rubocop_foreman_expire_hosts) do |task|
|
33
|
-
task.patterns = ["#{ForemanExpireHosts::Engine.root}/app/**/*.rb",
|
34
|
-
"#{ForemanExpireHosts::Engine.root}/lib/**/*.rb",
|
35
|
-
"#{ForemanExpireHosts::Engine.root}/test/**/*.rb"]
|
36
|
-
end
|
37
|
-
rescue StandardError
|
38
|
-
puts 'Rubocop not loaded.'
|
39
|
-
end
|
40
|
-
|
41
|
-
Rake::Task['rubocop_foreman_expire_hosts'].invoke
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
28
|
Rake::Task[:test].enhance ['test:foreman_expire_hosts']
|
46
29
|
|
47
30
|
load 'tasks/jenkins.rake'
|
48
|
-
|
31
|
+
if Rake::Task.task_defined?(:'jenkins:unit')
|
32
|
+
Rake::Task['jenkins:unit'].enhance ['test:foreman_expire_hosts']
|
33
|
+
end
|
@@ -4,9 +4,9 @@ require 'test_plugin_helper'
|
|
4
4
|
|
5
5
|
class HostsControllerTest < ActionController::TestCase
|
6
6
|
setup do
|
7
|
+
Setting['host_details_ui'] = false if Setting['host_details_ui']
|
7
8
|
User.current = users(:admin)
|
8
9
|
disable_orchestration
|
9
|
-
setup_settings
|
10
10
|
end
|
11
11
|
|
12
12
|
describe 'host creation' do
|
@@ -20,13 +20,11 @@ class HostsControllerTest < ActionController::TestCase
|
|
20
20
|
:domain_id => domains(:mydomain).id,
|
21
21
|
:operatingsystem_id => operatingsystems(:redhat).id,
|
22
22
|
:architecture_id => architectures(:x86_64).id,
|
23
|
-
:environment_id => environments(:production).id,
|
24
23
|
:subnet_id => subnets(:one).id,
|
25
24
|
:medium_id => media(:one).id,
|
26
25
|
:pxe_loader => 'Grub2 UEFI',
|
27
26
|
:realm_id => realms(:myrealm).id,
|
28
27
|
:disk => 'empty partition',
|
29
|
-
:puppet_proxy_id => smart_proxies(:puppetmaster).id,
|
30
28
|
:root_pass => 'xybxa6JUkz63w',
|
31
29
|
:location_id => taxonomies(:location1).id,
|
32
30
|
:organization_id => taxonomies(:organization1).id,
|
@@ -53,7 +51,7 @@ class HostsControllerTest < ActionController::TestCase
|
|
53
51
|
describe 'setting expiration date on multiple hosts' do
|
54
52
|
before do
|
55
53
|
as_admin do
|
56
|
-
@hosts = FactoryBot.create_list(:host, 2
|
54
|
+
@hosts = FactoryBot.create_list(:host, 2)
|
57
55
|
end
|
58
56
|
@request.env['HTTP_REFERER'] = hosts_path
|
59
57
|
end
|
@@ -70,7 +68,7 @@ class HostsControllerTest < ActionController::TestCase
|
|
70
68
|
test 'should set expiration date' do
|
71
69
|
expiration_date = Date.today + 14
|
72
70
|
params = { :host_ids => @hosts.map(&:id),
|
73
|
-
:host => { 'expired_on
|
71
|
+
:host => { 'expired_on' => expiration_date.strftime('%Y-%m-%d') } }
|
74
72
|
|
75
73
|
post :update_multiple_expiration, params: params, session: set_session_user.merge(:user => users(:admin).id)
|
76
74
|
|
data/test/test_plugin_helper.rb
CHANGED
@@ -16,10 +16,6 @@ require File.join(
|
|
16
16
|
# Foreman's setup doesn't handle cleaning up for Minitest::Spec
|
17
17
|
DatabaseCleaner.strategy = :transaction
|
18
18
|
|
19
|
-
def setup_settings
|
20
|
-
Setting::ExpireHosts.load_defaults
|
21
|
-
end
|
22
|
-
|
23
19
|
class Minitest::Spec
|
24
20
|
before :each do
|
25
21
|
DatabaseCleaner.start
|
@@ -3,10 +3,6 @@
|
|
3
3
|
require 'test_plugin_helper'
|
4
4
|
|
5
5
|
class ExpireHostMailerTest < ActionMailer::TestCase
|
6
|
-
setup do
|
7
|
-
setup_settings
|
8
|
-
end
|
9
|
-
|
10
6
|
let(:recipient) { FactoryBot.create(:user, :with_mail) }
|
11
7
|
let(:hosts) { FactoryBot.create_list(:host, 2, :managed) }
|
12
8
|
|
@@ -84,7 +80,7 @@ class ExpireHostMailerTest < ActionMailer::TestCase
|
|
84
80
|
|
85
81
|
test 'mail is delivered to admin address' do
|
86
82
|
assert_nil recipient.mail
|
87
|
-
assert_equal [
|
83
|
+
assert_equal [Setting[:administrator]], mail.to
|
88
84
|
end
|
89
85
|
end
|
90
86
|
end
|
@@ -30,7 +30,6 @@ module ForemanExpireHosts
|
|
30
30
|
|
31
31
|
context 'with edit_hosts and owner permission' do
|
32
32
|
setup do
|
33
|
-
setup_settings
|
34
33
|
FactoryBot.create(:filter, :role => role, :permissions => [edit_permission])
|
35
34
|
end
|
36
35
|
let(:hosts) { FactoryBot.create_list(:host, 2, :owner => user) }
|
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: 8.
|
4
|
+
version: 8.1.0
|
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:
|
12
|
+
date: 2023-03-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: deface
|
@@ -39,62 +39,6 @@ dependencies:
|
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
|
-
- !ruby/object:Gem::Dependency
|
43
|
-
name: rubocop
|
44
|
-
requirement: !ruby/object:Gem::Requirement
|
45
|
-
requirements:
|
46
|
-
- - "~>"
|
47
|
-
- !ruby/object:Gem::Version
|
48
|
-
version: 0.80.0
|
49
|
-
type: :development
|
50
|
-
prerelease: false
|
51
|
-
version_requirements: !ruby/object:Gem::Requirement
|
52
|
-
requirements:
|
53
|
-
- - "~>"
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: 0.80.0
|
56
|
-
- !ruby/object:Gem::Dependency
|
57
|
-
name: rubocop-minitest
|
58
|
-
requirement: !ruby/object:Gem::Requirement
|
59
|
-
requirements:
|
60
|
-
- - "~>"
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: 0.7.0
|
63
|
-
type: :development
|
64
|
-
prerelease: false
|
65
|
-
version_requirements: !ruby/object:Gem::Requirement
|
66
|
-
requirements:
|
67
|
-
- - "~>"
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: 0.7.0
|
70
|
-
- !ruby/object:Gem::Dependency
|
71
|
-
name: rubocop-performance
|
72
|
-
requirement: !ruby/object:Gem::Requirement
|
73
|
-
requirements:
|
74
|
-
- - "~>"
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: 1.5.2
|
77
|
-
type: :development
|
78
|
-
prerelease: false
|
79
|
-
version_requirements: !ruby/object:Gem::Requirement
|
80
|
-
requirements:
|
81
|
-
- - "~>"
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
version: 1.5.2
|
84
|
-
- !ruby/object:Gem::Dependency
|
85
|
-
name: rubocop-rails
|
86
|
-
requirement: !ruby/object:Gem::Requirement
|
87
|
-
requirements:
|
88
|
-
- - "~>"
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
version: 2.4.2
|
91
|
-
type: :development
|
92
|
-
prerelease: false
|
93
|
-
version_requirements: !ruby/object:Gem::Requirement
|
94
|
-
requirements:
|
95
|
-
- - "~>"
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
version: 2.4.2
|
98
42
|
description: |
|
99
43
|
A Foreman plugin that allows hosts to expire at a configurable date.
|
100
44
|
Hosts will be shut down and automatically deleted after a grace period.
|
@@ -146,6 +90,7 @@ files:
|
|
146
90
|
- config/routes.rb
|
147
91
|
- db/migrate/20150427101516_add_expiry_on_to_hosts.rb
|
148
92
|
- db/migrate/20220923181700_fix_settings_category_to_dsl.rb
|
93
|
+
- db/migrate/20230112104438_change_expired_on_type.rb
|
149
94
|
- db/seeds.d/80_expire_hosts_ui_notification.rb
|
150
95
|
- extra/foreman_expire_hosts.cron
|
151
96
|
- lib/expire_hosts_notifications.rb
|
@@ -183,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
183
128
|
- !ruby/object:Gem::Version
|
184
129
|
version: '0'
|
185
130
|
requirements: []
|
186
|
-
rubygems_version: 3.
|
131
|
+
rubygems_version: 3.3.26
|
187
132
|
signing_key:
|
188
133
|
specification_version: 4
|
189
134
|
summary: Foreman plugin for limiting host lifetime
|