Sha256: a1016ee63ee891acd209f4770cd1145c5caabd7fbc0bc09b7eb86cf29f005e0e

Contents?: true

Size: 703 Bytes

Versions: 1

Compression:

Stored size: 703 Bytes

Contents

require 'diplomat'

module Skalera
  module Services
    class Consul
      def self.configure(service_name)
        consul = ENV['CONSUL'] || 'consul'
        Diplomat.configuration.url = "http://#{consul}:8500"
        token = ENV['CONSUL_ACL_TOKEN']
        Diplomat.configuration.acl_token = token if token

        # force a lookup just to make a connection so we can bail out early if consul id down
        Diplomat.get("services/#{service_name}")
      rescue Diplomat::KeyNotFound
        Diplomat.put("services/#{service_name}", service_name)
      rescue Faraday::ConnectionFailed => e
        STDERR.puts("ERROR: could not lookup host #{consul}")
        raise e
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
skalera-services-0.1.0 lib/skalera/services/consul.rb