require 'grape' require 'cabal/util' require 'cabal/api/cluster' require 'cabal/api/user' require 'cabal/api/common/authenticated' require 'cabal/api/common/mistakes' module Cabal module API module V2 class PrivateKey < Grape::API 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 end end