class Kongfigure::Kong

Constants

SYNCHRONIZER_MODULES

Public Class Methods

new(parser, http_client) click to toggle source
# File lib/kongfigure/kong.rb, line 11
def initialize(parser, http_client)
  @parser        = parser
  @http_client   = http_client
  @synchronizers = {}
  @configuration = @parser.parse!
  load_synchronizers
  display_information
end

Public Instance Methods

apply!() click to toggle source
# File lib/kongfigure/kong.rb, line 20
def apply!
  puts @configuration.to_s
  puts "Fetching actual configuration..."
  puts "Do you want to apply this configuration to '#{@configuration.url}' (yes/no)".colorize(:color => :white, :background => :red)
  exit 1 unless gets.strip.downcase == "yes"
  puts "Applying configuration...".colorize(:color => :white, :background => :red)
  SYNCHRONIZER_MODULES.each do |synchronizer_module|
    apply_all(@synchronizers[synchronizer_module])
  end
  puts "Done.".colorize(:color => :white, :background => :red)
end
apply_all(synchronizer) click to toggle source
# File lib/kongfigure/kong.rb, line 32
def apply_all(synchronizer)
  puts "<- Applying #{synchronizer.resource_api_name}..."
  synchronizer.synchronize_all
end
display_information() click to toggle source
# File lib/kongfigure/kong.rb, line 37
def display_information
  data = @http_client.get("/")
  puts "Kong information:".colorize(:color => :white, :background => :red)
  puts "* hostname: \t#{data['version']}"
  puts "* version: \t#{data['hostname']}"
  puts "* lua_version: \t#{data['lua_version']}"
end

Private Instance Methods

load_synchronizers() click to toggle source
# File lib/kongfigure/kong.rb, line 46
def load_synchronizers
  SYNCHRONIZER_MODULES.each do |synchronizer_module|
    resources = case synchronizer_module.to_s
    when Kongfigure::Synchronizers::Upstream.to_s
      @configuration.upstreams
    when Kongfigure::Synchronizers::Service.to_s
      @configuration.services
    when Kongfigure::Synchronizers::Consumer.to_s
      @configuration.consumers
    when Kongfigure::Synchronizers::Plugin.to_s
      @configuration.plugins
    end
    @synchronizers[synchronizer_module] = synchronizer_module.new(@http_client, resources || [])
  end
end