Class: ForemanPuppet::Api::V2::PuppetLookupsCommonController
- Inherits:
-
Api::V2::BaseController
- Object
- Api::V2::BaseController
- ForemanPuppet::Api::V2::PuppetLookupsCommonController
show all
- Defined in:
- app/controllers/foreman_puppet/api/v2/puppet_lookups_common_controller.rb
Instance Method Summary
collapse
Instance Method Details
#cast_default_value ⇒ Object
93
94
95
|
# File 'app/controllers/foreman_puppet/api/v2/puppet_lookups_common_controller.rb', line 93
def cast_default_value
cast_value(:smart_class_parameter, :default_value)
end
|
#cast_value(obj = :override_value, value = :value) ⇒ Object
97
98
99
100
101
102
|
# File 'app/controllers/foreman_puppet/api/v2/puppet_lookups_common_controller.rb', line 97
def cast_value(obj = :override_value, value = :value)
return unless params[obj]&.key?(value)
param_value = params[obj][value]
return if param_value.is_a?(Hash)
params[obj][value] = param_value.to_s
end
|
#create ⇒ Object
22
23
|
# File 'app/controllers/foreman_puppet/api/v2/puppet_lookups_common_controller.rb', line 22
def create
end
|
#destroy ⇒ Object
28
29
|
# File 'app/controllers/foreman_puppet/api/v2/puppet_lookups_common_controller.rb', line 28
def destroy
end
|
#find_smart_class_parameter ⇒ Object
50
51
52
53
54
55
56
57
58
59
|
# File 'app/controllers/foreman_puppet/api/v2/puppet_lookups_common_controller.rb', line 50
def find_smart_class_parameter
id = params.key?('smart_class_parameter_id') ? params['smart_class_parameter_id'] : params['id']
@smart_class_parameter = PuppetclassLookupKey.authorized(:view_external_parameters).smart_class_parameters.find_by(id: id.to_i) if id.to_i.positive?
@smart_class_parameter ||= begin
puppet_cond = { 'environment_classes.puppetclass_id' => @puppetclass.id } if @puppetclass
env_cond = { 'environment_classes.environment_id' => @environment.id } if @environment
PuppetclassLookupKey.authorized(:view_external_parameters).smart_class_parameters.where(puppet_cond).where(env_cond).where(key: id).first
end
@smart_class_parameter
end
|
#find_smart_class_parameters ⇒ Object
61
62
63
|
# File 'app/controllers/foreman_puppet/api/v2/puppet_lookups_common_controller.rb', line 61
def find_smart_class_parameters
@smart_class_parameters = smart_class_parameters_resource_scope.search_for(*search_options).paginate(paginate_options)
end
|
#return_if_smart_mismatch ⇒ Object
87
88
89
90
91
|
# File 'app/controllers/foreman_puppet/api/v2/puppet_lookups_common_controller.rb', line 87
def return_if_smart_mismatch
return unless @smart_class_parameters && (!smart_param_exists? || !@smart_class_parameter)
id = params.key?('smart_class_parameter_id') ? params['smart_variable_id'] : params['id']
not_found "Smart class parameter not found by id '#{id}''"
end
|
#show ⇒ Object
19
20
|
# File 'app/controllers/foreman_puppet/api/v2/puppet_lookups_common_controller.rb', line 19
def show
end
|
#smart_class_parameters_resource_scope ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'app/controllers/foreman_puppet/api/v2/puppet_lookups_common_controller.rb', line 65
def smart_class_parameters_resource_scope
base = PuppetclassLookupKey.authorized(:view_external_parameters)
params = if !@puppetclass && !@environment && !@host && !@hostgroup
base.smart_class_parameters
elsif @puppetclass && @environment
base.smart_class_parameters_for_class(@puppetclass.id, @environment.id)
elsif @puppetclass && !@environment
environment_ids = @puppetclass.environment_classes.pluck(:environment_id).uniq
base.smart_class_parameters_for_class(@puppetclass.id, environment_ids)
elsif !@puppetclass && @environment
puppetclass_ids = @environment.environment_classes.pluck(:puppetclass_id).uniq
base.smart_class_parameters_for_class(puppetclass_ids, @environment.id)
elsif @host || @hostgroup
puppet_facet = (@host || @hostgroup).puppet || (@host || @hostgroup).build_puppet
puppetclass_ids = puppet_facet.all_puppetclasses.map(&:id)
environment_id = puppet_facet.environment_id
base.parameters_for_class(puppetclass_ids, environment_id)
end
params.distinct
end
|
#update ⇒ Object
25
26
|
# File 'app/controllers/foreman_puppet/api/v2/puppet_lookups_common_controller.rb', line 25
def update
end
|