lib/cabal/api/v2/private_key.rb in cabal-api-0.1.1 vs lib/cabal/api/v2/private_key.rb in cabal-api-0.2.0

- old
+ new

@@ -1,46 +1,12 @@ require 'grape' -require 'cabal/util' -require 'cabal/api/cluster' -require 'cabal/api/user' -require 'cabal/api/common/authenticated' -require 'cabal/api/common/mistakes' +require 'cabal/api/common/private_key' 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 + include Cabal::API::Common::PrivateKey end end end end