Method: SkullIsland::CLI#export

Defined in:
lib/skull_island/cli.rb

#export(output_file = '-') ⇒ Object



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
48
49
50
# File 'lib/skull_island/cli.rb', line 20

def export(output_file = '-')
  if output_file == '-'
    warn '[INFO] Outputting to STDOUT' if options['verbose']
  else
    full_filename = File.expand_path(output_file)
    dirname = File.dirname(full_filename)
    unless File.exist?(dirname) && File.ftype(dirname) == 'directory'
      raise Exceptions::InvalidArguments, "#{full_filename} is invalid"
    end
  end

  validate_server_version

  output = { 'version' => '2.3' }
  output['project'] = options['project'] if options['project']

  [
    Resources::CACertificate,
    Resources::Certificate,
    Resources::Consumer,
    Resources::Upstream,
    Resources::Service,
    Resources::Plugin
  ].each { |clname| export_class(clname, output) }

  if output_file == '-'
    $stdout.puts output.to_yaml
  else
    File.write(full_filename, output.to_yaml)
  end
end