Class: PuppetcaController

Inherits:
ApplicationController show all
Defined in:
app/controllers/puppetca_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#api_request?, #welcome

Methods included from Foreman::ThreadSession::Cleaner

#clear_thread, included

Instance Method Details

#destroyObject


44
45
46
47
48
49
50
51
# File 'app/controllers/puppetca_controller.rb', line 44

def destroy
  cert = SmartProxies::PuppetCA.find(@proxy, params[:id])
  if cert.destroy
    process_success({ :success_redirect => smart_proxy_puppetca_index_path(@proxy, :state => params[:state]), :object_name => cert.to_s })
  else
    process_error({ :redirect => smart_proxy_puppetca_index_path(@proxy) })
  end
end

#indexObject


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/puppetca_controller.rb', line 4

def index
  # expire cache if forced
  Rails.cache.delete("ca_#{@proxy.id}") if params[:expire_cache] == "true"

  begin
    certs = if params[:state].blank?
              SmartProxies::PuppetCA.find_by_state(@proxy, "valid") + SmartProxies::PuppetCA.find_by_state(@proxy, "pending")
            elsif params[:state] == "all"
              SmartProxies::PuppetCA.all @proxy
            else
              SmartProxies::PuppetCA.find_by_state @proxy, params[:state]
            end
  rescue => e
    certs = []
    error e
    redirect_to :back and return
  end
  respond_to do |format|
    format.html do
      begin
        @certificates = certs.sort.paginate :page => params[:page], :per_page => params[:per_page] || 20
      rescue => e
        error e
      end
    end
    format.json { render :json => certificates }
  end
end

#updateObject


33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/puppetca_controller.rb', line 33

def update
  cert = SmartProxies::PuppetCA.find(@proxy, params[:id])
  if cert.sign
    process_success({ :success_redirect => smart_proxy_puppetca_index_path(@proxy, :state => params[:state]), :object_name => cert.to_s })
  else
    process_error({ :redirect => smart_proxy_puppetca_index_path(@proxy) })
  end
rescue
  process_error({ :redirect => smart_proxy_puppetca_index_path(@proxy) })
end