Sha256: 341d5c8cafa7fbada6302ff32f8fcff1ee03964444f440f46ba5319b918f4130

Contents?: true

Size: 1017 Bytes

Versions: 2

Compression:

Stored size: 1017 Bytes

Contents

module ForemanXen
  class CacheController < ::ApplicationController
    before_action :load_compute_resource

    # POST = foreman_xen/cache/refresh
    def refresh
      type = params[:type]

      unless cache_attribute_whitelist.include?(type)
        process_error(:error_msg => "Error refreshing cache. #{type} is not a white listed attribute")
      end

      unless @compute_resource.respond_to?("#{type}!")
        process_error(:error_msg => "Error refreshing cache. Method '#{type}!' not found for compute resource" +
            @compute_resource.name)
      end

      respond_to do |format|
        format.json { render :json => @compute_resource.public_send("#{type}!") }
      end
    end

    private

    # List of methods to permit
    def cache_attribute_whitelist
      %w(networks hypervisors templates custom_templates builtin_templates storage_pools)
    end

    def load_compute_resource
      @compute_resource = ComputeResource.find_by(id: params['compute_resource_id'])
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
foreman_xen-0.5.1 app/controllers/foreman_xen/cache_controller.rb
foreman_xen-0.5.0 app/controllers/foreman_xen/cache_controller.rb