Revision e3256834
Added by Julian Todt almost 6 years ago
modules/puppetca/puppetca_api.rb | ||
---|---|---|
require 'puppetca/puppetca_main'
|
||
|
||
module Proxy::PuppetCa
|
||
class Api < ::Sinatra::Base
|
||
extend Proxy::PuppetCa::DependencyInjection
|
||
inject_attr :puppet_cert, :puppet_cert
|
||
inject_attr :autosigner, :autosigner
|
||
|
||
helpers ::Proxy::Helpers
|
||
authorize_with_trusted_hosts
|
||
authorize_with_ssl_client
|
||
... | ... | |
get "/?" do
|
||
content_type :json
|
||
begin
|
||
Proxy::PuppetCa.list.to_json
|
||
puppet_cert.list.to_json
|
||
rescue => e
|
||
log_halt 406, "Failed to list certificates: #{e}"
|
||
end
|
||
... | ... | |
get "/autosign" do
|
||
content_type :json
|
||
begin
|
||
Proxy::PuppetCa.autosign_list.to_json
|
||
autosigner.autosign_list.to_json
|
||
rescue => e
|
||
log_halt 406, "Failed to list autosign entries: #{e}"
|
||
end
|
||
... | ... | |
content_type :json
|
||
certname = params[:certname]
|
||
begin
|
||
Proxy::PuppetCa.autosign(certname)
|
||
autosigner.autosign(certname)
|
||
rescue => e
|
||
log_halt 406, "Failed to enable autosign for #{certname}: #{e}"
|
||
end
|
||
... | ... | |
content_type :json
|
||
certname = params[:certname]
|
||
begin
|
||
Proxy::PuppetCa.disable(certname)
|
||
autosigner.disable(certname)
|
||
rescue Proxy::PuppetCa::NotPresent => e
|
||
log_halt 404, e.to_s
|
||
rescue => e
|
||
... | ... | |
content_type :json
|
||
certname = params[:certname]
|
||
begin
|
||
Proxy::PuppetCa.sign(certname)
|
||
puppet_cert.sign(certname)
|
||
rescue => e
|
||
log_halt 406, "Failed to sign certificate(s) for #{certname}: #{e}"
|
||
end
|
||
... | ... | |
begin
|
||
content_type :json
|
||
certname = params[:certname]
|
||
Proxy::PuppetCa.clean(certname)
|
||
puppet_cert.clean(certname)
|
||
rescue Proxy::PuppetCa::NotPresent => e
|
||
log_halt 404, e.to_s
|
||
rescue => e
|
Also available in: Unified diff
Fixes #23799 - Refactor: Make PuppetCa pluggable