foreman/app/controllers/api/v2/parameters_controller.rb @ 9d43fc71
57526a20 | Joseph Mitchell Magen | module Api
|
|
module V2
|
|||
class ParametersController < V2::BaseController
|
|||
include Api::Version2
|
|||
12612809 | Dominic Cleal | include Foreman::Controller::Parameters::Parameter
|
|
57526a20 | Joseph Mitchell Magen | ||
df6a9f34 | Dominic Cleal | before_action :find_required_nested_object
|
|
before_action :find_parameter, :only => [:show, :update, :destroy]
|
|||
57526a20 | Joseph Mitchell Magen | ||
resource_description do
|
|||
desc <<-DOC
|
|||
03261ebb | Sean O'Keeffe | These API calls are related to <b>nested parameters for a host, domain, subnet, host group, operating system</b>. If you are looking for
|
|
57526a20 | Joseph Mitchell Magen | <a href="common_parameters.html">global parameters</a>, go to <a href="common_parameters.html">this link</a>.
|
|
DOC
|
|||
end
|
|||
2656873b | Martin Bačovský | api :GET, "/hosts/:host_id/parameters", N_("List all parameters for a host")
|
|
api :GET, "/hostgroups/:hostgroup_id/parameters", N_("List all parameters for a host group")
|
|||
api :GET, "/domains/:domain_id/parameters", N_("List all parameters for a domain")
|
|||
api :GET, "/operatingsystems/:operatingsystem_id/parameters", N_("List all parameters for an operating system")
|
|||
api :GET, "/locations/:location_id/parameters", N_("List all parameters for a location")
|
|||
api :GET, "/organizations/:organization_id/parameters", N_("List all parameters for an organization")
|
|||
03261ebb | Sean O'Keeffe | api :GET, "/subnets/:subnet_id/parameters", N_("List all parameters for a subnet")
|
|
2656873b | Martin Bačovský | param :host_id, String, :desc => N_("ID of host")
|
|
453dc693 | Joseph Magen | param :hostgroup_id, String, :desc => N_("ID of host group")
|
|
2656873b | Martin Bačovský | param :domain_id, String, :desc => N_("ID of domain")
|
|
param :operatingsystem_id, String, :desc => N_("ID of operating system")
|
|||
param :location_id, String, :desc => N_("ID of location")
|
|||
param :organization_id, String, :desc => N_("ID of organization")
|
|||
03261ebb | Sean O'Keeffe | param :subnet_id, String, :desc => N_("ID of subnet")
|
|
3b9d7933 | Ori Rabin | param :show_hidden, :bool, :desc => N_("Display hidden values")
|
|
915b2918 | Tomas Strachota | param_group :search_and_pagination, ::Api::V2::BaseController
|
|
6330baae | Tomas Strachota | add_scoped_search_description_for(Parameter)
|
|
1eaa44ca | Martin Bačovský | ||
57526a20 | Joseph Mitchell Magen | def index
|
|
4e6d2262 | Marek Hulan | base = nested_obj.send(parameters_method).authorized(current_permission)
|
|
@parameters = base.search_for(*search_options).paginate(paginate_options)
|
|||
@total = base.count
|
|||
57526a20 | Joseph Mitchell Magen | end
|
|
2656873b | Martin Bačovský | api :GET, "/hosts/:host_id/parameters/:id", N_("Show a nested parameter for a host")
|
|
api :GET, "/hostgroups/:hostgroup_id/parameters/:id", N_("Show a nested parameter for a host group")
|
|||
api :GET, "/domains/:domain_id/parameters/:id", N_("Show a nested parameter for a domain")
|
|||
api :GET, "/operatingsystems/:operatingsystem_id/parameters/:id", N_("Show a nested parameter for an operating system")
|
|||
api :GET, "/locations/:location_id/parameters/:id", N_("Show a nested parameter for a location")
|
|||
api :GET, "/organizations/:organization_id/parameters/:id", N_("Show a nested parameter for an organization")
|
|||
03261ebb | Sean O'Keeffe | api :GET, "/subnets/:subnet_id/parameters/:id", N_("Show a nested parameter for a subnet")
|
|
2656873b | Martin Bačovský | param :host_id, String, :desc => N_("ID of host")
|
|
453dc693 | Joseph Magen | param :hostgroup_id, String, :desc => N_("ID of host group")
|
|
2656873b | Martin Bačovský | param :domain_id, String, :desc => N_("ID of domain")
|
|
param :operatingsystem_id, String, :desc => N_("ID of operating system")
|
|||
param :location_id, String, :desc => N_("ID of location")
|
|||
param :organization_id, String, :desc => N_("ID of organization")
|
|||
03261ebb | Sean O'Keeffe | param :subnet_id, String, :desc => N_("ID of subnet")
|
|
2656873b | Martin Bačovský | param :id, String, :required => true, :desc => N_("ID of parameter")
|
|
3b9d7933 | Ori Rabin | param :show_hidden, :bool, :desc => N_("Display hidden values")
|
|
57526a20 | Joseph Mitchell Magen | ||
def show
|
|||
end
|
|||
2be84f3d | Joseph Magen | def_param_group :parameter do
|
|
fb5ac616 | Joseph Magen | param :parameter, Hash, :required => true, :action_aware => true do
|
|
2be84f3d | Joseph Magen | param :name, String, :required => true
|
|
param :value, String, :required => true
|
|||
end
|
|||
end
|
|||
2656873b | Martin Bačovský | api :POST, "/hosts/:host_id/parameters/", N_("Create a nested parameter for a host")
|
|
api :POST, "/hostgroups/:hostgroup_id/parameters/", N_("Create a nested parameter for a host group")
|
|||
api :POST, "/domains/:domain_id/parameters/", N_("Create a nested parameter for a domain")
|
|||
api :POST, "/operatingsystems/:operatingsystem_id/parameters/", N_("Create a nested parameter for an operating system")
|
|||
api :POST, "/locations/:location_id/parameters/", N_("Create a nested parameter for a location")
|
|||
api :POST, "/organizations/:organization_id/parameters/", N_("Create a nested parameter for an organization")
|
|||
03261ebb | Sean O'Keeffe | api :POST, "/subnets/:subnet_id/parameters/", N_("Create a nested parameter for a subnet")
|
|
2656873b | Martin Bačovský | param :host_id, String, :desc => N_("ID of host")
|
|
453dc693 | Joseph Magen | param :hostgroup_id, String, :desc => N_("ID of host group")
|
|
2656873b | Martin Bačovský | param :domain_id, String, :desc => N_("ID of domain")
|
|
param :operatingsystem_id, String, :desc => N_("ID of operating system")
|
|||
param :location_id, String, :desc => N_("ID of location")
|
|||
param :organization_id, String, :desc => N_("ID of organization")
|
|||
03261ebb | Sean O'Keeffe | param :subnet_id, String, :desc => N_("ID of subnet")
|
|
2be84f3d | Joseph Magen | param_group :parameter, :as => :create
|
|
57526a20 | Joseph Mitchell Magen | ||
def create
|
|||
12612809 | Dominic Cleal | @parameter = nested_obj.send(parameters_method).new(parameter_params(::Parameter))
|
|
57526a20 | Joseph Mitchell Magen | process_response @parameter.save
|
|
end
|
|||
2656873b | Martin Bačovský | api :PUT, "/hosts/:host_id/parameters/:id", N_("Update a nested parameter for a host")
|
|
api :PUT, "/hostgroups/:hostgroup_id/parameters/:id", N_("Update a nested parameter for a host group")
|
|||
api :PUT, "/domains/:domain_id/parameters/:id", N_("Update a nested parameter for a domain")
|
|||
api :PUT, "/operatingsystems/:operatingsystem_id/parameters/:id", N_("Update a nested parameter for an operating system")
|
|||
api :PUT, "/locations/:location_id/parameters/:id", N_("Update a nested parameter for a location")
|
|||
api :PUT, "/organizations/:organization_id/parameters/:id", N_("Update a nested parameter for an organization")
|
|||
03261ebb | Sean O'Keeffe | api :PUT, "/subnets/:subnet_id/parameters/:id", N_("Update a nested parameter for a subnet")
|
|
2656873b | Martin Bačovský | param :host_id, String, :desc => N_("ID of host")
|
|
453dc693 | Joseph Magen | param :hostgroup_id, String, :desc => N_("ID of host group")
|
|
2656873b | Martin Bačovský | param :domain_id, String, :desc => N_("ID of domain")
|
|
param :operatingsystem_id, String, :desc => N_("ID of operating system")
|
|||
param :location_id, String, :desc => N_("ID of location")
|
|||
param :organization_id, String, :desc => N_("ID of organization")
|
|||
param :id, String, :required => true, :desc => N_("ID of parameter")
|
|||
03261ebb | Sean O'Keeffe | param :subnet_id, String, :desc => N_("ID of subnet")
|
|
2be84f3d | Joseph Magen | param_group :parameter
|
|
57526a20 | Joseph Mitchell Magen | ||
def update
|
|||
9ae8fa19 | Michael Moll | process_response @parameter.update(parameter_params(::Parameter))
|
|
57526a20 | Joseph Mitchell Magen | end
|
|
2656873b | Martin Bačovský | api :DELETE, "/hosts/:host_id/parameters/:id", N_("Delete a nested parameter for a host")
|
|
api :DELETE, "/hostgroups/:hostgroup_id/parameters/:id", N_("Delete a nested parameter for a host group")
|
|||
api :DELETE, "/domains/:domain_id/parameters/:id", N_("Delete a nested parameter for a domain")
|
|||
api :DELETE, "/operatingsystems/:operatingsystem_id/parameters/:id", N_("Delete a nested parameter for an operating system")
|
|||
api :DELETE, "/locations/:location_id/parameters/:id", N_("Delete a nested parameter for a location")
|
|||
api :DELETE, "/organizations/:organization_id/parameters/:id", N_("Delete a nested parameter for an organization")
|
|||
03261ebb | Sean O'Keeffe | api :DELETE, "/subnets/:subnet_id/parameters/:id", N_("Delete a nested parameter for a subnet")
|
|
2656873b | Martin Bačovský | param :host_id, String, :desc => N_("ID of host")
|
|
453dc693 | Joseph Magen | param :hostgroup_id, String, :desc => N_("ID of host group")
|
|
2656873b | Martin Bačovský | param :domain_id, String, :desc => N_("ID of domain")
|
|
param :operatingsystem_id, String, :desc => N_("ID of operating system")
|
|||
param :location_id, String, :desc => N_("ID of location")
|
|||
param :organization_id, String, :desc => N_("ID of organization")
|
|||
param :id, String, :required => true, :desc => N_("ID of parameter")
|
|||
03261ebb | Sean O'Keeffe | param :subnet_id, String, :desc => N_("ID of subnet")
|
|
57526a20 | Joseph Mitchell Magen | ||
def destroy
|
|||
process_response @parameter.destroy
|
|||
end
|
|||
2656873b | Martin Bačovský | api :DELETE, "/hosts/:host_id/parameters", N_("Delete all nested parameters for a host")
|
|
api :DELETE, "/hostgroups/:hostgroup_id/parameters", N_("Delete all nested parameters for a host group")
|
|||
api :DELETE, "/domains/:domain_id/parameters", N_("Delete all nested parameters for a domain")
|
|||
api :DELETE, "/operatingsystems/:operatingsystem_id/parameters", N_("Delete all nested parameters for an operating system")
|
|||
api :DELETE, "/locations/:location_id/parameters", N_("Delete all nested parameter for a location")
|
|||
api :DELETE, "/organizations/:organization_id/parameters", N_("Delete all nested parameter for an organization")
|
|||
03261ebb | Sean O'Keeffe | api :DELETE, "/subnets/:subnet_id/parameters", N_("Delete all nested parameters for a subnet")
|
|
2656873b | Martin Bačovský | param :host_id, String, :desc => N_("ID of host")
|
|
453dc693 | Joseph Magen | param :hostgroup_id, String, :desc => N_("ID of host group")
|
|
2656873b | Martin Bačovský | param :domain_id, String, :desc => N_("ID of domain")
|
|
param :operatingsystem_id, String, :desc => N_("ID of operating system")
|
|||
param :location_id, String, :desc => N_("ID of location")
|
|||
param :organization_id, String, :desc => N_("ID of organization")
|
|||
03261ebb | Sean O'Keeffe | param :subnet_id, String, :desc => N_("ID of subnet")
|
|
4ab67d21 | Daniel Lobato | ||
def reset
|
|||
@parameter = nested_obj.send(parameters_method)
|
|||
process_response @parameter.destroy_all
|
|||
end
|
|||
57526a20 | Joseph Mitchell Magen | private
|
|
acfbc458 | Marek Hulan | def action_permission
|
|
case params[:action]
|
|||
when 'reset'
|
|||
:destroy
|
|||
else
|
|||
super
|
|||
end
|
|||
end
|
|||
4e6d2262 | Marek Hulan | def controller_permission
|
|
'params'
|
|||
end
|
|||
57526a20 | Joseph Mitchell Magen | def parameters_method
|
|
# hostgroup.rb has a method def parameters, so I didn't create has_many :parameters like Host, Domain, Os
|
|||
08e86bf5 | Ondrej Prazak | # locations and organizations inherit def parameters from taxonomies
|
|
case nested_obj
|
|||
when Hostgroup
|
|||
:group_parameters
|
|||
when Location
|
|||
:location_parameters
|
|||
when Organization
|
|||
:organization_parameters
|
|||
else
|
|||
:parameters
|
|||
end
|
|||
57526a20 | Joseph Mitchell Magen | end
|
|
c1a23d77 | Joseph Mitchell Magen | def allowed_nested_id
|
|
03261ebb | Sean O'Keeffe | %w(host_id hostgroup_id domain_id subnet_id operatingsystem_id location_id organization_id)
|
|
c1a23d77 | Joseph Mitchell Magen | end
|
|
9d743410 | Joseph Magen | def find_parameter
|
|
# nested_obj is required, so no need to check here
|
|||
9d43fc71 | Michael Moll | @parameters = nested_obj.send(parameters_method).authorized(current_permission)
|
|
fb9f45e8 | Daniel Lobato | @parameter = @parameters.from_param(params[:id])
|
|
@parameter ||= @parameters.friendly.find(params[:id])
|
|||
return @parameter if @parameter.present?
|
|||
46338cd7 | Daniel Lobato | not_found
|
|
9d743410 | Joseph Magen | end
|
|
57526a20 | Joseph Mitchell Magen | end
|
|
end
|
|||
end
|