foreman_remote_execution 1.6.3 → 1.6.4

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.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/foreman_remote_execution/template_input.js +0 -10
  3. data/app/assets/javascripts/foreman_remote_execution/template_invocation.js +1 -12
  4. data/app/assets/stylesheets/foreman_remote_execution/template_invocation.css.scss +1 -0
  5. data/app/controllers/api/v2/job_invocations_controller.rb +5 -1
  6. data/app/helpers/job_invocation_output_helper.rb +5 -4
  7. data/app/helpers/job_invocations_helper.rb +0 -29
  8. data/app/helpers/remote_execution_helper.rb +1 -24
  9. data/app/lib/foreman_remote_execution/renderer/scope/input.rb +28 -8
  10. data/app/models/concerns/foreman_remote_execution/template_extensions.rb +0 -12
  11. data/app/models/concerns/foreman_remote_execution/template_input_extensions.rb +9 -0
  12. data/app/models/concerns/foreman_remote_execution/template_overrides.rb +11 -0
  13. data/app/models/input_template_renderer.rb +16 -17
  14. data/app/models/job_invocation.rb +14 -4
  15. data/app/models/job_invocation_composer.rb +2 -6
  16. data/app/models/job_template.rb +23 -52
  17. data/app/models/template_invocation_input_value.rb +12 -1
  18. data/app/views/api/v2/smart_proxies/pubkey.json.rabl +1 -0
  19. data/app/views/job_invocations/_form.html.erb +1 -7
  20. data/app/views/job_templates/_custom_tabs.html.erb +0 -7
  21. data/app/views/template_invocations/_output_line_set.html.erb +2 -2
  22. data/app/views/templates/ssh/module_action.erb +67 -0
  23. data/app/views/templates/ssh/package_action.erb +39 -7
  24. data/app/views/templates/ssh/power_action.erb +2 -1
  25. data/app/views/templates/ssh/puppet_run_once.erb +1 -0
  26. data/app/views/templates/ssh/run_command.erb +1 -0
  27. data/app/views/templates/ssh/service_action.erb +9 -1
  28. data/config/routes.rb +0 -1
  29. data/lib/foreman_remote_execution/engine.rb +4 -0
  30. data/lib/foreman_remote_execution/version.rb +1 -1
  31. data/locale/de/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  32. data/locale/de/foreman_remote_execution.po +3 -72
  33. data/locale/en/foreman_remote_execution.po +3 -72
  34. data/locale/en_GB/foreman_remote_execution.po +3 -72
  35. data/locale/es/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  36. data/locale/es/foreman_remote_execution.po +3 -72
  37. data/locale/foreman_remote_execution.pot +124 -225
  38. data/locale/fr/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  39. data/locale/fr/foreman_remote_execution.po +3 -72
  40. data/locale/ja/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  41. data/locale/ja/foreman_remote_execution.po +3 -72
  42. data/locale/ko/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  43. data/locale/ko/foreman_remote_execution.po +3 -72
  44. data/locale/pt_BR/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  45. data/locale/pt_BR/foreman_remote_execution.po +3 -72
  46. data/locale/ru/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  47. data/locale/ru/foreman_remote_execution.po +3 -72
  48. data/locale/zh_CN/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  49. data/locale/zh_CN/foreman_remote_execution.po +3 -72
  50. data/locale/zh_TW/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  51. data/locale/zh_TW/foreman_remote_execution.po +3 -72
  52. data/test/factories/foreman_remote_execution_factories.rb +6 -5
  53. data/test/functional/api/v2/job_invocations_controller_test.rb +10 -0
  54. data/test/unit/input_template_renderer_test.rb +52 -21
  55. data/test/unit/job_invocation_composer_test.rb +2 -2
  56. data/test/unit/job_invocation_test.rb +36 -0
  57. metadata +6 -19
  58. data/app/controllers/api/v2/template_inputs_controller.rb +0 -92
  59. data/app/controllers/concerns/foreman/controller/parameters/template_input.rb +0 -17
  60. data/app/models/template_input.rb +0 -179
  61. data/app/views/api/v2/template_inputs/base.json.rabl +0 -3
  62. data/app/views/api/v2/template_inputs/create.json.rabl +0 -3
  63. data/app/views/api/v2/template_inputs/index.json.rabl +0 -3
  64. data/app/views/api/v2/template_inputs/main.json.rabl +0 -10
  65. data/app/views/api/v2/template_inputs/show.json.rabl +0 -3
  66. data/app/views/template_inputs/_form.html.erb +0 -25
  67. data/app/views/template_inputs/_invocation_form.html.erb +0 -7
  68. data/db/migrate/20150616080015_create_template_input.rb +0 -19
  69. data/db/migrate/20150827152730_add_options_to_template_input.rb +0 -5
  70. data/db/migrate/20160127134031_add_advanced_to_template_input.rb +0 -11
  71. data/test/functional/api/v2/template_inputs_controller_test.rb +0 -56
  72. data/test/unit/template_input_test.rb +0 -40
@@ -1,92 +0,0 @@
1
- module Api
2
- module V2
3
- class TemplateInputsController < ::Api::V2::BaseController
4
- include ::Api::Version2
5
- include ::Foreman::Renderer
6
- include ::Foreman::Controller::Parameters::TemplateInput
7
-
8
- before_action :find_required_nested_object
9
- before_action :find_resource, :only => %w{show update destroy}
10
- before_action :normalize_options, :only => %w{create update}
11
-
12
- api :GET, '/templates/:template_id/template_inputs', N_('List template inputs')
13
- param :template_id, :identifier, :required => true
14
- param_group :search_and_pagination, ::Api::V2::BaseController
15
- def index
16
- @template_inputs = nested_obj.template_inputs.search_for(*search_options).paginate(paginate_options)
17
- end
18
-
19
- api :GET, '/templates/:template_id/template_inputs/:id', N_('Show template input details')
20
- param :template_id, :identifier, :required => true
21
- param :id, :identifier, :required => true
22
- def show; end
23
-
24
- def_param_group :template_input do
25
- param :template_input, Hash, :required => true, :action_aware => true do
26
- param :name, String, :required => true, :desc => N_('Input name')
27
- param :description, String, :required => false, :desc => N_('Input description')
28
- param :required, :bool, :allow_nil => true, :desc => N_('Input is required')
29
- param :advanced, :bool, :allow_nil => true, :desc => N_('Input is advanced')
30
- param :input_type, TemplateInput::TYPES.keys.map(&:to_s), :required => true, :desc => N_('Input type')
31
- param :fact_name, String, :required => false, :desc => N_('Fact name, used when input type is fact')
32
- param :variable_name, String, :required => false, :desc => N_('Variable name, used when input type is variable')
33
- param :puppet_class_name, String, :required => false, :desc => N_('Puppet class name, used when input type is puppet_parameter')
34
- param :puppet_parameter_name, String, :required => false, :desc => N_('Puppet parameter name, used when input type is puppet_parameter')
35
- param :options, Array, :required => false, :desc => N_('Selectable values for user inputs')
36
- end
37
- end
38
-
39
- api :POST, '/templates/:template_id/template_inputs/', N_('Create a template input')
40
- param :template_id, :identifier, :required => true
41
- param_group :template_input, :as => :create
42
- def create
43
- @template_input = resource_class.new(template_input_params.merge(:template_id => @nested_obj.id))
44
- process_response @template_input.save
45
- end
46
-
47
- api :DELETE, '/templates/:template_id/template_inputs/:id', N_('Delete a template input')
48
- param :template_id, :identifier, :required => true
49
- param :id, :identifier, :required => true
50
- def destroy
51
- process_response @template_input.destroy
52
- end
53
-
54
- api :PUT, '/templates/:template_id/template_inputs/:id', N_('Update a template input')
55
- param :template_id, :identifier, :required => true
56
- param :id, :identifier, :required => true
57
- param_group :template_input
58
- def update
59
- process_response @template_input.update_attributes(template_input_params)
60
- end
61
-
62
- def resource_name(nested_resource = nil)
63
- nested_resource || 'template_input'
64
- end
65
-
66
- def controller_permission
67
- 'templates'
68
- end
69
-
70
- def action_permission
71
- case params[:action]
72
- when :create, :edit, :destroy
73
- 'edit'
74
- else
75
- super
76
- end
77
- end
78
-
79
- private
80
-
81
- def normalize_options
82
- if params[:template_input][:options].is_a?(Array)
83
- params[:template_input][:options] = params[:template_input][:options].join("\n")
84
- end
85
- end
86
-
87
- def resource_class
88
- TemplateInput
89
- end
90
- end
91
- end
92
- end
@@ -1,17 +0,0 @@
1
- module Foreman::Controller::Parameters::TemplateInput
2
- extend ActiveSupport::Concern
3
-
4
- class_methods do
5
- def template_input_params_filter
6
- Foreman::ParameterFilter.new(::TemplateInput).tap do |filter|
7
- filter.permit_by_context :id, :_destroy, :name, :required, :input_type, :fact_name,
8
- :variable_name, :puppet_class_name, :puppet_parameter_name, :description, :template_id,
9
- :options, :advanced, :nested => true
10
- end
11
- end
12
- end
13
-
14
- def template_input_params
15
- self.class.template_input_params_filter.filter_params(params, parameter_filter_context, :template_input)
16
- end
17
- end
@@ -1,179 +0,0 @@
1
- class TemplateInput < ApplicationRecord
2
- include ::Exportable
3
-
4
- class ValueNotReady < ::Foreman::Exception
5
- end
6
- class UnsatisfiedRequiredInput < ::Foreman::Exception
7
- end
8
-
9
- TYPES = { :user => N_('User input'), :fact => N_('Fact value'), :variable => N_('Variable'),
10
- :puppet_parameter => N_('Puppet parameter') }.with_indifferent_access
11
-
12
- attr_exportable(:name, :required, :input_type, :fact_name, :variable_name, :puppet_class_name,
13
- :puppet_parameter_name, :description, :options, :advanced)
14
-
15
- belongs_to :template
16
- has_many :template_invocation_input_values, :dependent => :destroy
17
-
18
- scoped_search :on => :name, :complete_value => true
19
- scoped_search :on => :input_type, :complete_value => true
20
-
21
- validates :name, :presence => true, :uniqueness => { :scope => 'template_id' }
22
- validates :input_type, :presence => true, :inclusion => TemplateInput::TYPES.keys
23
-
24
- validates :fact_name, :presence => { :if => :fact_template_input? }
25
- validates :variable_name, :presence => { :if => :variable_template_input? }
26
- validates :puppet_parameter_name, :puppet_class_name, :presence => { :if => :puppet_parameter_template_input? }
27
-
28
- def user_template_input?
29
- input_type == 'user'
30
- end
31
-
32
- def fact_template_input?
33
- input_type == 'fact'
34
- end
35
-
36
- def variable_template_input?
37
- input_type == 'variable'
38
- end
39
-
40
- def puppet_parameter_template_input?
41
- input_type == 'puppet_parameter'
42
- end
43
-
44
- def preview(renderer)
45
- get_resolver(renderer).preview
46
- end
47
-
48
- def value(renderer)
49
- get_resolver(renderer).value
50
- end
51
-
52
- def options_array
53
- self.options.blank? ? [] : self.options.split(/\r?\n/).map(&:strip)
54
- end
55
-
56
- def basic?
57
- !advanced
58
- end
59
-
60
- private
61
-
62
- def get_resolver(renderer)
63
- resolver_class = case input_type
64
- when 'user'
65
- UserInputResolver
66
- when 'fact'
67
- FactInputResolver
68
- when 'variable'
69
- VariableInputResolver
70
- when 'puppet_parameter'
71
- PuppetParameterInputResolver
72
- else
73
- raise "unknown template input type #{input_type.inspect}"
74
- end
75
- resolver_class.new(self, renderer)
76
- end
77
-
78
- class InputResolver
79
- def initialize(input, renderer)
80
- @input = input
81
- @renderer = renderer
82
- end
83
-
84
- def preview
85
- ready? ? resolved_value : preview_value
86
- end
87
-
88
- def value
89
- ready? ? resolved_value : raise(ValueNotReady, "Input '#{@input.name}' is not ready for rendering")
90
- end
91
-
92
- def preview_value
93
- "$#{@input.input_type.upcase}_INPUT[#{@input.name}]"
94
- end
95
-
96
- # should be defined in descendants
97
- def ready?
98
- raise NotImplementedError
99
- end
100
-
101
- # should be defined in descendants
102
- def resolved_value
103
- raise NotImplementedError
104
- end
105
- end
106
-
107
- class UserInputResolver < InputResolver
108
-
109
- def value
110
- raise(UnsatisfiedRequiredInput, _("Value for required input '%s' was not specified") % @input.name) if required_value_needed?
111
- super
112
- end
113
-
114
- def ready?
115
- @renderer.invocation
116
- end
117
-
118
- def resolved_value
119
- input_value.try(:value)
120
- end
121
-
122
- private
123
-
124
- def required_value_needed?
125
- @input.required? && input_value.try(:value).blank?
126
- end
127
-
128
- def input_value
129
- return unless @renderer.invocation
130
- @renderer.invocation.input_values.find { |value| value.template_input_name == @input.name }
131
- end
132
- end
133
-
134
- class FactInputResolver < InputResolver
135
- # fact might not be present if it hasn't been uploaded yet, there's typo in name
136
- def ready?
137
- @renderer.host && get_fact.present?
138
- end
139
-
140
- def resolved_value
141
- get_fact.value
142
- end
143
-
144
- private
145
-
146
- def get_fact
147
- @fact ||= @renderer.host.fact_values.includes(:fact_name).find_by(:'fact_names.name' => @input.fact_name)
148
- end
149
- end
150
-
151
- class VariableInputResolver < InputResolver
152
- def ready?
153
- @renderer.host && @renderer.host.params.key?(@input.variable_name)
154
- end
155
-
156
- def resolved_value
157
- @renderer.host.params[@input.variable_name]
158
- end
159
- end
160
-
161
- class PuppetParameterInputResolver < InputResolver
162
- def ready?
163
- @renderer.host &&
164
- get_enc.key?(@input.puppet_class_name) &&
165
- get_enc[@input.puppet_class_name].is_a?(Hash) &&
166
- get_enc[@input.puppet_class_name].key?(@input.puppet_parameter_name)
167
- end
168
-
169
- def resolved_value
170
- get_enc[@input.puppet_class_name][@input.puppet_parameter_name]
171
- end
172
-
173
- private
174
-
175
- def get_enc
176
- @enc ||= HostInfoProviders::PuppetInfo.new(@renderer.host).puppetclass_parameters
177
- end
178
- end
179
- end
@@ -1,3 +0,0 @@
1
- object @template_input
2
-
3
- attributes :id, :name, :input_type
@@ -1,3 +0,0 @@
1
- object @template_input
2
-
3
- extends 'api/v2/template_inputs/show'
@@ -1,3 +0,0 @@
1
- collection @template_inputs
2
-
3
- extends 'api/v2/template_inputs/main'
@@ -1,10 +0,0 @@
1
- object @template_input
2
-
3
- extends 'api/v2/template_inputs/base'
4
-
5
- attributes :template_id, :fact_name, :variable_name, :puppet_parameter_name, :puppet_class_name,
6
- :description, :required
7
-
8
- node :options do |input|
9
- input.options.split(/\r?\n/) if input.options.present?
10
- end
@@ -1,3 +0,0 @@
1
- object @template_input
2
-
3
- extends 'api/v2/template_inputs/main'
@@ -1,25 +0,0 @@
1
- <div class="fields">
2
- <div class="form-group">
3
- <%= field_set_tag template_input_header(f, @template) do %>
4
- <%= text_f f, :name, :disabled => @template.locked? %>
5
- <%= checkbox_f f, :required, :disabled => @template.locked? %>
6
- <%= selectable_f f, :input_type, template_input_types_options, {}, :class => 'input_type_selector without_select2', :disabled => @template.locked? %>
7
- <div class="fact_input_type custom_input_type_fields" style="<%= f.object.fact_template_input? ? '' : 'display:none' %>">
8
- <%= text_f f, :fact_name, :class => 'fact_input_type', :required => true, :disabled => @template.locked? %>
9
- </div>
10
- <div class="variable_input_type custom_input_type_fields" style="<%= f.object.variable_template_input? ? '' : 'display:none' %>">
11
- <%= text_f f, :variable_name, :class => 'variable_input_type', :required => true, :disabled => @template.locked? %>
12
- </div>
13
- <div class="puppet_parameter_input_type custom_input_type_fields" style="<%= f.object.puppet_parameter_template_input? ? '' : 'display:none' %>">
14
- <%= text_f f, :puppet_class_name, :class => 'puppet_parameter_input_type', :required => true, :disabled => @template.locked? %>
15
- <%= text_f f, :puppet_parameter_name, :class => 'puppet_parameter_input_type', :required => true, :disabled => @template.locked? %>
16
- </div>
17
- <div class="user_input_type custom_input_type_fields" style="<%= (f.object.user_template_input? || f.object.new_record?) ? '' : 'display:none' %>">
18
- <%= checkbox_f f, :advanced, :disabled => @template.locked? %>
19
- <%= textarea_f f, :options, :rows => 3, :class => 'user_input_type', :help_inline => _("A list of options the user can select from. If not provided, the user will be given a free-form field"),
20
- :disabled => @template.locked? %>
21
- </div>
22
- <%= textarea_f f, :description, :rows => 3, :disabled => @template.locked? %>
23
- <% end %>
24
- </div>
25
- </div>
@@ -1,7 +0,0 @@
1
- <%= input_values_fields.fields_for input.id.to_s, composer.template_invocation_input_value_for(job_template, input) do |input_fields| %>
2
- <% unless input.options.blank? %>
3
- <%= selectable_f input_fields, :value, input.options_array, { :include_blank => !input.required }, :label_help => input.description, :require => input.required, :label => input.name, :id => input.name, :onchange => "regenerate_description(this);" %>
4
- <% else %>
5
- <%= textarea_f input_fields, :value, :label => input.name, :label_help => input.description, :required => input.required, :rows => 2, :onchange => "regenerate_description(this);", :id => input.name %>
6
- <% end %>
7
- <% end %>
@@ -1,19 +0,0 @@
1
- class CreateTemplateInput < ActiveRecord::Migration[4.2]
2
- def change
3
- create_table :template_inputs do |t|
4
- t.string :name, :null => false, :limit => 255
5
- t.boolean :required, :null => false, :default => false
6
- t.string :input_type, :null => false, :limit => 255
7
- t.string :fact_name, :limit => 255
8
- t.string :variable_name, :limit => 255
9
- t.string :puppet_class_name, :limit => 255
10
- t.string :puppet_parameter_name, :limit => 255
11
- t.text :description
12
- t.integer :template_id
13
-
14
- t.timestamps :null => true
15
- end
16
-
17
- add_foreign_key :template_inputs, :templates, :name => 'templates_template_id_fk', :column => 'template_id'
18
- end
19
- end
@@ -1,5 +0,0 @@
1
- class AddOptionsToTemplateInput < ActiveRecord::Migration[4.2]
2
- def change
3
- add_column :template_inputs, :options, :text
4
- end
5
- end
@@ -1,11 +0,0 @@
1
- class AddAdvancedToTemplateInput < ActiveRecord::Migration[4.2]
2
- def up
3
- add_column :template_inputs, :advanced, :boolean, :default => false, :null => false
4
- template = JobTemplate.find_by(name: 'Package Action - SSH Default')
5
- TemplateInput.where(:name => ['pre_script', 'post_script'], :template_id => template.try(:id)).update_all(:advanced => true)
6
- end
7
-
8
- def down
9
- remove_column :template_inputs, :advanced
10
- end
11
- end
@@ -1,56 +0,0 @@
1
- require 'test_plugin_helper'
2
-
3
- module Api
4
- module V2
5
- class TemplateInputsControllerTest < ActionController::TestCase
6
- setup do
7
- @template = FactoryBot.create(:job_template, :with_input)
8
- @input = @template.template_inputs.first
9
- end
10
-
11
- test 'should get index' do
12
- get :index, params: { :template_id => @template.id }
13
- inputs = ActiveSupport::JSON.decode(@response.body)
14
- assert !inputs.empty?, 'Should respond with inputs'
15
- assert_response :success
16
- end
17
-
18
- test 'should get input detail' do
19
- get :show, params: { :template_id => @template.to_param, :id => @input.to_param }
20
- assert_response :success
21
- input = ActiveSupport::JSON.decode(@response.body)
22
- assert !input.empty?
23
- assert_equal input['name'], @input.name
24
- end
25
-
26
- test 'should create valid' do
27
- valid_attrs = { :name => 'is_potato', :input_type => 'user', :options => ['true', 'false'] }
28
- post :create, params: { :template_input => valid_attrs, :template_id => @template.to_param }
29
- input = ActiveSupport::JSON.decode(@response.body)
30
- assert input['name'] == 'is_potato'
31
- assert_response :success
32
- end
33
-
34
- test 'should not create invalid' do
35
- post :create, params: { :template_id => @template.to_param }
36
- assert_response :unprocessable_entity
37
- end
38
-
39
- test 'should update valid' do
40
- put :update, params: { :template_id => @template.to_param, :id => @input.to_param, :template_input => { :name => 'blah' } }
41
- assert_response :ok
42
- end
43
-
44
- test 'should not update invalid' do
45
- put :update, params: { :template_id => @template.to_param, :id => @input.to_param, :template_input => { :name => '' } }
46
- assert_response :unprocessable_entity
47
- end
48
-
49
- test 'should destroy' do
50
- delete :destroy, params: { :template_id => @template.to_param, :id => @input.to_param }
51
- assert_response :ok
52
- refute TemplateInput.exists?(@input.id)
53
- end
54
- end
55
- end
56
- end