11
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
|
# File 'lib/cabal/api/common/private_key.rb', line 11
def self.included(base)
base.class_eval do
include Cabal::API::Common::Authenticated
include Cabal::API::Common::Mistakes
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])
cluster = Cabal::API::Cluster.find(name: cluster_name).first
error_if_not_found!(cluster, cluster_name)
{
name: cluster.name,
private_ssh_key: cluster.private_key
}
end
end
end
|