Module: Cabal::CLI::Authenticated

Included in:
List, SSH
Defined in:
lib/cabal/cli/authenticated.rb

Instance Method Summary collapse

Instance Method Details

#with_authentication(config, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cabal/cli/authenticated.rb', line 7

def with_authentication(config, &block)
  begin
    unless config[:access_key] && config[:secret_key]
      raise Cabal::CLI::NoPrivateConfig
    end

    block.call

  rescue Cabal::CLI::NoPrivateConfig
    stderr.puts "You must have an access key and a secret key"
  rescue Cabal::Client::UnauthorizedError
    stderr.puts "You are not authorized to use the private API."
    kernel.exit(1)
  rescue Cabal::Client::NotFoundError
    stderr.puts "The cluster '#{option(:cluster_name)}' does not exist."
    kernel.exit(1)
  end
end