12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/cabal/api/common/private_key.rb', line 12
def self.included(base)
base.class_eval do
include Cabal::API::Common::Authenticated
include Cabal::API::Common::Mistakes
include Cabal::API::Common::Services
formatter :txt, ->(object, env) {
object[:private_ssh_key]
}
helpers do
def error_if_not_found!(cluster, name)
unless cluster
error!(
messagify("The cluster '#{name}' could not be found."),
404
)
end
end
end
get '/private-key/:name' do
authenticate!
cluster_name = Cabal::Util.normalize(params[:name])
key = cluster_service.private_key(cluster_name)
error_if_not_found!(key, cluster_name)
{
name: cluster_name,
private_ssh_key: key
}
end
end
end
|