diplomat 0.13.2 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +7 -0
- data/lib/diplomat.rb +1 -1
- data/lib/diplomat/kv.rb +6 -2
- data/lib/diplomat/nodes.rb +15 -0
- data/lib/diplomat/rest_client.rb +4 -3
- data/lib/diplomat/service.rb +14 -1
- data/lib/diplomat/version.rb +1 -1
- metadata +4 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: dd8fd2de1577af47ba483ec661d17065898e0347
         | 
| 4 | 
            +
              data.tar.gz: 67472f8f9b059e34acb2da7565416545a16a4150
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: fc1c47f0f2a6fd0ef1d8d368ff476c2943b7ac28d0ea8baa69cedd18e22ba78131196b8b6867c0ab8debfcd6b5ee84d5e26b9065a994bb11148e17c6bc91d435
         | 
| 7 | 
            +
              data.tar.gz: c6c453c1bebd64a5354304820e3946abb3f98ff3974e0ba15cb9c4c9939b5016a2dcc6bda78bbaf17f7d2c3d547f1db1ac0b3de1d07d3e04304256645137f45f
         | 
    
        data/README.md
    CHANGED
    
    | @@ -106,6 +106,13 @@ foo_service = Diplomat::Service.get('foo', :all, { :dc => 'My_Datacenter'}) | |
| 106 106 | 
             
            # => [#<OpenStruct Node="hotel", Address="1.2.3.4", ServiceID="hotel_foo", ServiceName="foo", ServiceTags=["foo"], ServicePort=5432>,#<OpenStruct Node="indigo", Address="1.2.3.5", ServiceID="indigo_foo", ServiceName="foo", ServiceTags=["foo"], ServicePort=5432>]
         | 
| 107 107 | 
             
            ```
         | 
| 108 108 |  | 
| 109 | 
            +
            If you wish to list all the services on consul:
         | 
| 110 | 
            +
             | 
| 111 | 
            +
            ```ruby
         | 
| 112 | 
            +
            services = Diplomat::Service.get_all
         | 
| 113 | 
            +
            # => #<OpenStruct consul=[], foo=[], bar=[]>
         | 
| 114 | 
            +
            ```
         | 
| 115 | 
            +
             | 
| 109 116 | 
             
            ### Datacenters
         | 
| 110 117 |  | 
| 111 118 | 
             
            Getting a list of datacenters is quite simple and gives you the option to extract all services out of
         | 
    
        data/lib/diplomat.rb
    CHANGED
    
    | @@ -21,7 +21,7 @@ module Diplomat | |
| 21 21 | 
             
              self.root_path = File.expand_path "..", __FILE__
         | 
| 22 22 | 
             
              self.lib_path = File.expand_path "../diplomat", __FILE__
         | 
| 23 23 |  | 
| 24 | 
            -
              require_libs "configuration", "rest_client", "kv", "datacenter", "service", "members", "check", "health", "session", "lock", "error", "event"
         | 
| 24 | 
            +
              require_libs "configuration", "rest_client", "kv", "datacenter", "service", "members", "nodes", "check", "health", "session", "lock", "error", "event"
         | 
| 25 25 | 
             
              self.configuration ||= Diplomat::Configuration.new
         | 
| 26 26 |  | 
| 27 27 | 
             
              class << self
         | 
    
        data/lib/diplomat/kv.rb
    CHANGED
    
    | @@ -9,8 +9,10 @@ module Diplomat | |
| 9 9 | 
             
                # Get a value by its key, potentially blocking for the first or next value
         | 
| 10 10 | 
             
                # @param key [String] the key
         | 
| 11 11 | 
             
                # @param options [Hash] the query params
         | 
| 12 | 
            +
                # @option options [Boolean] :recurse If to make recursive get or not
         | 
| 12 13 | 
             
                # @option options [String] :consistency The read consistency type
         | 
| 13 14 | 
             
                # @option options [String] :dc Target datacenter
         | 
| 15 | 
            +
                # @option options [Boolean] :nil_values If to return keys/dirs with nil values
         | 
| 14 16 | 
             
                # @param not_found [Symbol] behaviour if the key doesn't exist;
         | 
| 15 17 | 
             
                #   :reject with exception, :return degenerate value, or :wait for it to appear
         | 
| 16 18 | 
             
                # @param found [Symbol] behaviour if the key does exist;
         | 
| @@ -42,6 +44,8 @@ module Diplomat | |
| 42 44 | 
             
                  url += use_consistency(@options)
         | 
| 43 45 | 
             
                  url += dc(@options)
         | 
| 44 46 |  | 
| 47 | 
            +
                  return_nil_values = (@options and @options[:nil_values])
         | 
| 48 | 
            +
             | 
| 45 49 | 
             
                  # 404s OK using this connection
         | 
| 46 50 | 
             
                  raw = @conn_no_err.get concat_url url
         | 
| 47 51 | 
             
                  if raw.status == 404
         | 
| @@ -60,7 +64,7 @@ module Diplomat | |
| 60 64 | 
             
                      when :return
         | 
| 61 65 | 
             
                        @raw = raw
         | 
| 62 66 | 
             
                        parse_body
         | 
| 63 | 
            -
                        return return_value
         | 
| 67 | 
            +
                        return return_value(return_nil_values)
         | 
| 64 68 | 
             
                      when :wait
         | 
| 65 69 | 
             
                        index = raw.headers["x-consul-index"]
         | 
| 66 70 | 
             
                    end
         | 
| @@ -75,7 +79,7 @@ module Diplomat | |
| 75 79 | 
             
                    req.options.timeout = 86400
         | 
| 76 80 | 
             
                  end
         | 
| 77 81 | 
             
                  parse_body
         | 
| 78 | 
            -
                  return_value
         | 
| 82 | 
            +
                  return_value(return_nil_values)
         | 
| 79 83 | 
             
                end
         | 
| 80 84 |  | 
| 81 85 | 
             
                # Associate a value with a key
         | 
| @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            require 'base64'
         | 
| 2 | 
            +
            require 'faraday'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module Diplomat
         | 
| 5 | 
            +
              class Nodes < Diplomat::RestClient
         | 
| 6 | 
            +
                @access_methods = [ :get ]
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                # Get all nodes
         | 
| 9 | 
            +
                # @return [OpenStruct] all data associated with the nodes in catalog
         | 
| 10 | 
            +
                def get
         | 
| 11 | 
            +
                  ret = @conn.get "/v1/catalog/nodes"
         | 
| 12 | 
            +
                  return JSON.parse(ret.body)
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
            end
         | 
    
        data/lib/diplomat/rest_client.rb
    CHANGED
    
    | @@ -75,16 +75,17 @@ module Diplomat | |
| 75 75 | 
             
                end
         | 
| 76 76 |  | 
| 77 77 | 
             
                # Get the key/value(s) from the raw output
         | 
| 78 | 
            -
                def return_value
         | 
| 78 | 
            +
                def return_value(nil_values=false)
         | 
| 79 79 | 
             
                  if @raw.count == 1
         | 
| 80 80 | 
             
                    @value = @raw.first["Value"]
         | 
| 81 81 | 
             
                    @value = Base64.decode64(@value) unless @value.nil?
         | 
| 82 82 | 
             
                  else
         | 
| 83 83 | 
             
                    @value = @raw.reduce([]) do |acc, e|
         | 
| 84 | 
            +
                      val = e["Value"].nil? ? nil : Base64.decode64(e["Value"])
         | 
| 84 85 | 
             
                      acc << {
         | 
| 85 86 | 
             
                        :key => e["Key"],
         | 
| 86 | 
            -
                        :value =>  | 
| 87 | 
            -
                      }  | 
| 87 | 
            +
                        :value => val
         | 
| 88 | 
            +
                      } if val or nil_values
         | 
| 88 89 | 
             
                      acc
         | 
| 89 90 | 
             
                    end
         | 
| 90 91 | 
             
                  end
         | 
    
        data/lib/diplomat/service.rb
    CHANGED
    
    | @@ -4,7 +4,7 @@ require 'faraday' | |
| 4 4 | 
             
            module Diplomat
         | 
| 5 5 | 
             
              class Service < Diplomat::RestClient
         | 
| 6 6 |  | 
| 7 | 
            -
                @access_methods = [ :get, :register, :deregister ]
         | 
| 7 | 
            +
                @access_methods = [ :get, :get_all, :register, :deregister ]
         | 
| 8 8 |  | 
| 9 9 | 
             
                # Get a service by it's key
         | 
| 10 10 | 
             
                # @param key [String] the key
         | 
| @@ -41,6 +41,19 @@ module Diplomat | |
| 41 41 | 
             
                  return OpenStruct.new JSON.parse(ret.body).first
         | 
| 42 42 | 
             
                end
         | 
| 43 43 |  | 
| 44 | 
            +
                # Get all the services
         | 
| 45 | 
            +
                # @return [OpenStruct] the list of all services
         | 
| 46 | 
            +
                def get_all
         | 
| 47 | 
            +
                  url = "/v1/catalog/services"
         | 
| 48 | 
            +
                  begin
         | 
| 49 | 
            +
                    ret = @conn.get url
         | 
| 50 | 
            +
                  rescue Faraday::ClientError
         | 
| 51 | 
            +
                    raise Diplomat::PathNotFound
         | 
| 52 | 
            +
                  end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                  return OpenStruct.new JSON.parse(ret.body)
         | 
| 55 | 
            +
                end
         | 
| 56 | 
            +
             | 
| 44 57 | 
             
                # Register a service
         | 
| 45 58 | 
             
                # @param definition [Hash] Hash containing definition of service
         | 
| 46 59 | 
             
                # @return [Boolean]
         | 
    
        data/lib/diplomat/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: diplomat
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.14.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - John Hamelink
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2015- | 
| 11 | 
            +
            date: 2015-10-05 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -186,6 +186,7 @@ files: | |
| 186 186 | 
             
            - lib/diplomat/kv.rb
         | 
| 187 187 | 
             
            - lib/diplomat/lock.rb
         | 
| 188 188 | 
             
            - lib/diplomat/members.rb
         | 
| 189 | 
            +
            - lib/diplomat/nodes.rb
         | 
| 189 190 | 
             
            - lib/diplomat/rest_client.rb
         | 
| 190 191 | 
             
            - lib/diplomat/service.rb
         | 
| 191 192 | 
             
            - lib/diplomat/session.rb
         | 
| @@ -210,7 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 210 211 | 
             
                  version: '0'
         | 
| 211 212 | 
             
            requirements: []
         | 
| 212 213 | 
             
            rubyforge_project: 
         | 
| 213 | 
            -
            rubygems_version: 2.4. | 
| 214 | 
            +
            rubygems_version: 2.4.5.1
         | 
| 214 215 | 
             
            signing_key: 
         | 
| 215 216 | 
             
            specification_version: 4
         | 
| 216 217 | 
             
            summary: Diplomat is a simple wrapper for Consul
         |