capistrano-consul_kv_lock 0.2.2 → 0.3.1
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
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 4bf44fabccbfc651c90fe736d86d43482637988a
         | 
| 4 | 
            +
              data.tar.gz: 9fb2c1d41f8fe68929dbb66cd066235cca84c6dc
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: e859f7cb88484826a2a9ef6ca1aef7f7fc892fe6d9ea63f76e6c2943f65fb150e9f20667a8c80d400546ccdfd9ab267977a1239704f4f54850dace59c9fb83f1
         | 
| 7 | 
            +
              data.tar.gz: 1ae576c9efddb295121b622333e39ca82ea0beddc41abcaeba3ba3b386be65633841dfb79cc15bcff3359de5e46055a3f1ee3b21fbcd5a61b429aa5d6f03ef33
         | 
| @@ -19,7 +19,7 @@ Gem::Specification.new do |spec| | |
| 19 19 | 
             
              spec.require_paths = ["lib"]
         | 
| 20 20 |  | 
| 21 21 | 
             
              spec.add_dependency "capistrano", ">= 3"
         | 
| 22 | 
            -
              spec.add_dependency " | 
| 22 | 
            +
              spec.add_dependency "diplomat"
         | 
| 23 23 |  | 
| 24 24 | 
             
              spec.add_development_dependency "bundler", "~> 1.7"
         | 
| 25 25 | 
             
              spec.add_development_dependency "rake", "~> 10.0"
         | 
| @@ -1,3 +1,5 @@ | |
| 1 | 
            +
            require 'diplomat'
         | 
| 2 | 
            +
             | 
| 1 3 | 
             
            module Capistrano
         | 
| 2 4 | 
             
              module ConsulKvLock
         | 
| 3 5 | 
             
                class SSHKittyLogger
         | 
| @@ -30,14 +32,11 @@ module Capistrano | |
| 30 32 | 
             
                  end
         | 
| 31 33 |  | 
| 32 34 | 
             
                  def initialize(consul_url, options={})
         | 
| 33 | 
            -
                     | 
| 34 | 
            -
                               consul = URI.parse(consul_url)
         | 
| 35 | 
            -
                               Consul::Client.v1.http(host: consul.host, port: consul.port, logger: logger)
         | 
| 36 | 
            -
                              end
         | 
| 35 | 
            +
                    Diplomat.configuration.url = consul_url
         | 
| 37 36 | 
             
                    @lock_key = options[:consul_lock_key] || 'deployment/locked'
         | 
| 38 37 | 
             
                    @session_id = nil
         | 
| 39 38 | 
             
                  end
         | 
| 40 | 
            -
                  attr_reader : | 
| 39 | 
            +
                  attr_reader :lock_key
         | 
| 41 40 |  | 
| 42 41 | 
             
                  def logger
         | 
| 43 42 | 
             
                    self.class.logger
         | 
| @@ -51,9 +50,8 @@ module Capistrano | |
| 51 50 | 
             
                  end
         | 
| 52 51 |  | 
| 53 52 | 
             
                  def locked?
         | 
| 54 | 
            -
                     | 
| 55 | 
            -
             | 
| 56 | 
            -
                  rescue Consul::Client::ResponseException => e
         | 
| 53 | 
            +
                    !!(Diplomat::Kv.get(lock_key) =~ /\A["'](t(rue)?|1|y(es)?)["']\z/)
         | 
| 54 | 
            +
                  rescue => e
         | 
| 57 55 | 
             
                    # in case of 404
         | 
| 58 56 | 
             
                    if e.message.include?('404')
         | 
| 59 57 | 
             
                      return false
         | 
| @@ -64,23 +62,22 @@ module Capistrano | |
| 64 62 |  | 
| 65 63 | 
             
                  def create_session
         | 
| 66 64 | 
             
                    logger.debug "Session request: #{session_request.inspect}"
         | 
| 67 | 
            -
                     | 
| 68 | 
            -
                    @session_id = r['ID']
         | 
| 65 | 
            +
                    @session_id = Diplomat::Session.create(session_request)
         | 
| 69 66 | 
             
                  end
         | 
| 70 67 |  | 
| 71 68 | 
             
                  def delete_session
         | 
| 72 69 | 
             
                    with_session {
         | 
| 73 | 
            -
                       | 
| 70 | 
            +
                      Diplomat::Session.destroy(@session_id)
         | 
| 74 71 | 
             
                    }
         | 
| 75 72 | 
             
                    @session_id = nil
         | 
| 76 73 | 
             
                  end
         | 
| 77 74 |  | 
| 78 75 | 
             
                  def lock
         | 
| 79 | 
            -
                    with_session {  | 
| 76 | 
            +
                    with_session { Diplomat::Lock.acquire(lock_key, @session_id, "true") }
         | 
| 80 77 | 
             
                  end
         | 
| 81 78 |  | 
| 82 79 | 
             
                  def unlock
         | 
| 83 | 
            -
                    with_session {  | 
| 80 | 
            +
                    with_session { Diplomat::Lock.release(lock_key, @session_id) }
         | 
| 84 81 | 
             
                  end
         | 
| 85 82 |  | 
| 86 83 | 
             
                  private
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: capistrano-consul_kv_lock
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.3.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Uchio KONDO
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2016-04-22 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: capistrano
         | 
| @@ -25,7 +25,7 @@ dependencies: | |
| 25 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| 26 26 | 
             
                    version: '3'
         | 
| 27 27 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            -
              name:  | 
| 28 | 
            +
              name: diplomat
         | 
| 29 29 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 30 | 
             
                requirements:
         | 
| 31 31 | 
             
                - - ">="
         | 
| @@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 105 105 | 
             
                  version: '0'
         | 
| 106 106 | 
             
            requirements: []
         | 
| 107 107 | 
             
            rubyforge_project: 
         | 
| 108 | 
            -
            rubygems_version: 2. | 
| 108 | 
            +
            rubygems_version: 2.4.5.1
         | 
| 109 109 | 
             
            signing_key: 
         | 
| 110 110 | 
             
            specification_version: 4
         | 
| 111 111 | 
             
            summary: Introduces deployment lock using consul KVS
         |