Sha256: 59249b107d4d3c2dd07e228a899b1769842d1beffcaa47d7d46a98162a5757a6
Contents?: true
Size: 742 Bytes
Versions: 13
Compression:
Stored size: 742 Bytes
Contents
require 'open-uri' require 'json' require 'dply/error' module Dplyr class Consul def hosts(app_name, service: "app") uri = "http://127.0.0.1:8500/v1/catalog/service/#{service}?tag=#{app_name}" response = JSON.parse(open(uri).read) hosts = [] response.each do |i| host = {} metadata_tag = i["ServiceTags"].find {|t| t =~ /\Ametadata:/} metadata = metadata_tag ? JSON.parse(metadata_tag.partition(":")[2]) : {} host[:user] = metadata["user"] host[:dir] = metadata["dir"] host[:addr] = i["Address"] host[:id] = i["Node"] hosts << host end hosts rescue raise ::Dply::Error, "failed to load hosts from consul" end end end
Version data entries
13 entries across 13 versions & 1 rubygems