vault 0.1.3 → 0.1.4
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/.travis.yml +4 -1
 - data/CHANGELOG.md +17 -0
 - data/Gemfile.lock +12 -1
 - data/README.md +14 -0
 - data/lib/vault.rb +28 -21
 - data/lib/vault/api.rb +1 -0
 - data/lib/vault/api/auth.rb +102 -0
 - data/lib/vault/api/logical.rb +5 -1
 - data/lib/vault/client.rb +80 -31
 - data/lib/vault/configurable.rb +7 -12
 - data/lib/vault/defaults.rb +69 -2
 - data/lib/vault/errors.rb +19 -3
 - data/lib/vault/version.rb +1 -1
 - data/vault.gemspec +1 -0
 - metadata +17 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 4e65904a28c46a6472dbbf09106bf0a195f9d291
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 6ffa1d55b773e146db6292da052a8a05aa6e6ba4
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: ea8558f0ffc17e853c0042555add482dfbc4c43a8061df636dd8441602d5e2610ffe2c7c241074108eb6c8aae84ecd9e3175417fc636e5071a9f978771d292f4
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: d87e2b3784fc0c9ee8d701d8fbbebaa5ddd319ba907452bf4e44ecf0eb1137d32e48adaed433a93dff38fcbb427d2c7d43be4f958d220d679c4b8e128a670cef
         
     | 
    
        data/.travis.yml
    CHANGED
    
    | 
         @@ -3,7 +3,7 @@ cache: bundler 
     | 
|
| 
       3 
3 
     | 
    
         
             
            sudo: false
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
            before_install: |-
         
     | 
| 
       6 
     | 
    
         
            -
              wget -O vault.zip -q https://dl.bintray.com/mitchellh/vault/vault_0. 
     | 
| 
      
 6 
     | 
    
         
            +
              wget -O vault.zip -q https://dl.bintray.com/mitchellh/vault/vault_0.2.0_linux_amd64.zip
         
     | 
| 
       7 
7 
     | 
    
         
             
              unzip vault.zip
         
     | 
| 
       8 
8 
     | 
    
         
             
              mkdir ~/bin
         
     | 
| 
       9 
9 
     | 
    
         
             
              mv vault ~/bin
         
     | 
| 
         @@ -14,4 +14,7 @@ branches: 
     | 
|
| 
       14 
14 
     | 
    
         
             
                - master
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
            rvm:
         
     | 
| 
      
 17 
     | 
    
         
            +
              - 1.9.3
         
     | 
| 
      
 18 
     | 
    
         
            +
              - 2.0
         
     | 
| 
      
 19 
     | 
    
         
            +
              - 2.1
         
     | 
| 
       17 
20 
     | 
    
         
             
              - 2.2
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    | 
         @@ -1,5 +1,22 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # Vault Ruby Changelog
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
      
 3 
     | 
    
         
            +
            ## v0.1.4 (August 15, 2015)
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            IMPROVEMENTS
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            - Add support for using a custom CA cert [GH-8]
         
     | 
| 
      
 8 
     | 
    
         
            +
            - Allow clients to specify timeouts [GH-12, GH-14]
         
     | 
| 
      
 9 
     | 
    
         
            +
            - Show which error caused the HTTPConnectionError [GH-30]
         
     | 
| 
      
 10 
     | 
    
         
            +
            - Allow clients to specify which SSL cipher suites to use [GH-29]
         
     | 
| 
      
 11 
     | 
    
         
            +
            - Allow clients to specify the SSL pem password [GH-22, GH-31]
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            BUG FIXES
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            - Read local token (`~/.vault-token`) for token if present [GH-13]
         
     | 
| 
      
 16 
     | 
    
         
            +
            - Disable bad SSL cipher suites and force TLSv1.2 [GH-16]
         
     | 
| 
      
 17 
     | 
    
         
            +
            - Update to test against Vault 0.2.0 [GH-20]
         
     | 
| 
      
 18 
     | 
    
         
            +
            - Do not attempt a read on logical path write [GH-11, GH-32]
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
       3 
20 
     | 
    
         
             
            ## v0.1.3 (May 14, 2015)
         
     | 
| 
       4 
21 
     | 
    
         | 
| 
       5 
22 
     | 
    
         
             
            BUG FIXES
         
     | 
    
        data/Gemfile.lock
    CHANGED
    
    | 
         @@ -1,12 +1,18 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            PATH
         
     | 
| 
       2 
2 
     | 
    
         
             
              remote: .
         
     | 
| 
       3 
3 
     | 
    
         
             
              specs:
         
     | 
| 
       4 
     | 
    
         
            -
                vault (0.1. 
     | 
| 
      
 4 
     | 
    
         
            +
                vault (0.1.4)
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            GEM
         
     | 
| 
       7 
7 
     | 
    
         
             
              remote: https://rubygems.org/
         
     | 
| 
       8 
8 
     | 
    
         
             
              specs:
         
     | 
| 
      
 9 
     | 
    
         
            +
                coderay (1.1.0)
         
     | 
| 
       9 
10 
     | 
    
         
             
                diff-lcs (1.2.5)
         
     | 
| 
      
 11 
     | 
    
         
            +
                method_source (0.8.2)
         
     | 
| 
      
 12 
     | 
    
         
            +
                pry (0.10.1)
         
     | 
| 
      
 13 
     | 
    
         
            +
                  coderay (~> 1.1.0)
         
     | 
| 
      
 14 
     | 
    
         
            +
                  method_source (~> 0.8.1)
         
     | 
| 
      
 15 
     | 
    
         
            +
                  slop (~> 3.4)
         
     | 
| 
       10 
16 
     | 
    
         
             
                rake (10.4.2)
         
     | 
| 
       11 
17 
     | 
    
         
             
                rspec (3.2.0)
         
     | 
| 
       12 
18 
     | 
    
         
             
                  rspec-core (~> 3.2.0)
         
     | 
| 
         @@ -21,12 +27,17 @@ GEM 
     | 
|
| 
       21 
27 
     | 
    
         
             
                  diff-lcs (>= 1.2.0, < 2.0)
         
     | 
| 
       22 
28 
     | 
    
         
             
                  rspec-support (~> 3.2.0)
         
     | 
| 
       23 
29 
     | 
    
         
             
                rspec-support (3.2.2)
         
     | 
| 
      
 30 
     | 
    
         
            +
                slop (3.6.0)
         
     | 
| 
       24 
31 
     | 
    
         | 
| 
       25 
32 
     | 
    
         
             
            PLATFORMS
         
     | 
| 
       26 
33 
     | 
    
         
             
              ruby
         
     | 
| 
       27 
34 
     | 
    
         | 
| 
       28 
35 
     | 
    
         
             
            DEPENDENCIES
         
     | 
| 
       29 
36 
     | 
    
         
             
              bundler (~> 1.9)
         
     | 
| 
      
 37 
     | 
    
         
            +
              pry
         
     | 
| 
       30 
38 
     | 
    
         
             
              rake (~> 10.0)
         
     | 
| 
       31 
39 
     | 
    
         
             
              rspec (~> 3.2)
         
     | 
| 
       32 
40 
     | 
    
         
             
              vault!
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
            BUNDLED WITH
         
     | 
| 
      
 43 
     | 
    
         
            +
               1.10.6
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -5,6 +5,10 @@ Vault is the official Ruby client for interacting with [Vault](https://vaultproj 
     | 
|
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            Quick Start
         
     | 
| 
       7 
7 
     | 
    
         
             
            -----------
         
     | 
| 
      
 8 
     | 
    
         
            +
            Install Ruby 2.0+: [Guide](https://www.ruby-lang.org/en/documentation/installation/).
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            > Please note that Vault Ruby may work on older Ruby installations like Ruby 1.9, but you **should not** use these versions of Ruby when communicating with a Vault server. Ruby 1.9 has [reached EOL](https://www.ruby-lang.org/en/news/2014/01/10/ruby-1-9-3-will-end-on-2015/) and will no longer receive important security patches or maintenance updates. There _are known security vulnerabilities_ specifically around SSL ciphers, which this library uses to communicate with a Vault server. While many distros still ship with Ruby 1.9 as the default, you are **highly discouraged** from using this library on any version of Ruby lower than Ruby 2.0.
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
       8 
12 
     | 
    
         
             
            Install via Rubygems:
         
     | 
| 
       9 
13 
     | 
    
         | 
| 
       10 
14 
     | 
    
         
             
                $ gem install vault
         
     | 
| 
         @@ -49,6 +53,16 @@ Vault::Client.configure do |config| 
     | 
|
| 
       49 
53 
     | 
    
         | 
| 
       50 
54 
     | 
    
         
             
              # Use SSL verification, also read as ENV["VAULT_SSL_VERIFY"]
         
     | 
| 
       51 
55 
     | 
    
         
             
              config.ssl_verify = false
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
              # Timeout the connection after a certain amount of time (seconds), also read
         
     | 
| 
      
 58 
     | 
    
         
            +
              # as ENV["VAULT_TIMEOUT"]
         
     | 
| 
      
 59 
     | 
    
         
            +
              config.timeout = 30
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
              # It is also possible to have finer-grained controls over the timeouts, these
         
     | 
| 
      
 62 
     | 
    
         
            +
              # may also be read as environment variables
         
     | 
| 
      
 63 
     | 
    
         
            +
              config.ssl_timeout  = 5
         
     | 
| 
      
 64 
     | 
    
         
            +
              config.open_timeout = 5
         
     | 
| 
      
 65 
     | 
    
         
            +
              config.read_timeout = 30
         
     | 
| 
       52 
66 
     | 
    
         
             
            end
         
     | 
| 
       53 
67 
     | 
    
         
             
            ```
         
     | 
| 
       54 
68 
     | 
    
         | 
    
        data/lib/vault.rb
    CHANGED
    
    | 
         @@ -8,31 +8,38 @@ module Vault 
     | 
|
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         
             
              require_relative "vault/api"
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
               
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
                 
     | 
| 
       18 
     | 
    
         
            -
                  @client = Vault::Client.new 
     | 
| 
      
 11 
     | 
    
         
            +
              class << self
         
     | 
| 
      
 12 
     | 
    
         
            +
                # API client object based off the configured options in {Configurable}.
         
     | 
| 
      
 13 
     | 
    
         
            +
                #
         
     | 
| 
      
 14 
     | 
    
         
            +
                # @return [Vault::Client]
         
     | 
| 
      
 15 
     | 
    
         
            +
                attr_reader :client
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                def setup!
         
     | 
| 
      
 18 
     | 
    
         
            +
                  @client = Vault::Client.new
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                  # Set secure SSL options
         
     | 
| 
      
 21 
     | 
    
         
            +
                  OpenSSL::SSL::SSLContext::DEFAULT_PARAMS[:options] &= ~OpenSSL::SSL::OP_DONT_INSERT_EMPTY_FRAGMENTS
         
     | 
| 
      
 22 
     | 
    
         
            +
                  OpenSSL::SSL::SSLContext::DEFAULT_PARAMS[:options] |= OpenSSL::SSL::OP_NO_COMPRESSION
         
     | 
| 
      
 23 
     | 
    
         
            +
                  OpenSSL::SSL::SSLContext::DEFAULT_PARAMS[:options] |= OpenSSL::SSL::OP_NO_SSLv2
         
     | 
| 
      
 24 
     | 
    
         
            +
                  OpenSSL::SSL::SSLContext::DEFAULT_PARAMS[:options] |= OpenSSL::SSL::OP_NO_SSLv3
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                  self
         
     | 
| 
       19 
27 
     | 
    
         
             
                end
         
     | 
| 
       20 
     | 
    
         
            -
                @client
         
     | 
| 
       21 
     | 
    
         
            -
              end
         
     | 
| 
       22 
28 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
      
 29 
     | 
    
         
            +
                # Delegate all methods to the client object, essentially making the module
         
     | 
| 
      
 30 
     | 
    
         
            +
                # object behave like a {Client}.
         
     | 
| 
      
 31 
     | 
    
         
            +
                def method_missing(m, *args, &block)
         
     | 
| 
      
 32 
     | 
    
         
            +
                  if client.respond_to?(m)
         
     | 
| 
      
 33 
     | 
    
         
            +
                    client.send(m, *args, &block)
         
     | 
| 
      
 34 
     | 
    
         
            +
                  else
         
     | 
| 
      
 35 
     | 
    
         
            +
                    super
         
     | 
| 
      
 36 
     | 
    
         
            +
                  end
         
     | 
| 
       30 
37 
     | 
    
         
             
                end
         
     | 
| 
       31 
     | 
    
         
            -
              end
         
     | 
| 
       32 
38 
     | 
    
         | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
      
 39 
     | 
    
         
            +
                # Delegating +respond_to+ to the {Client}.
         
     | 
| 
      
 40 
     | 
    
         
            +
                def respond_to_missing?(m, include_private = false)
         
     | 
| 
      
 41 
     | 
    
         
            +
                  client.respond_to?(m, include_private) || super
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
       36 
43 
     | 
    
         
             
              end
         
     | 
| 
       37 
44 
     | 
    
         
             
            end
         
     | 
| 
       38 
45 
     | 
    
         | 
    
        data/lib/vault/api.rb
    CHANGED
    
    
| 
         @@ -0,0 +1,102 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require "json"
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require_relative "secret"
         
     | 
| 
      
 4 
     | 
    
         
            +
            require_relative "../client"
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            module Vault
         
     | 
| 
      
 7 
     | 
    
         
            +
              class Client
         
     | 
| 
      
 8 
     | 
    
         
            +
                # A proxy to the {Auth} methods.
         
     | 
| 
      
 9 
     | 
    
         
            +
                # @return [Auth]
         
     | 
| 
      
 10 
     | 
    
         
            +
                def auth
         
     | 
| 
      
 11 
     | 
    
         
            +
                  @auth ||= Authenticate.new(self)
         
     | 
| 
      
 12 
     | 
    
         
            +
                end
         
     | 
| 
      
 13 
     | 
    
         
            +
              end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
              class Authenticate < Request
         
     | 
| 
      
 16 
     | 
    
         
            +
                # Authenticate via the "token" authentication method. This authentication
         
     | 
| 
      
 17 
     | 
    
         
            +
                # method is a bit bizarre because you already have a token, but hey,
         
     | 
| 
      
 18 
     | 
    
         
            +
                # whatever floats your boat.
         
     | 
| 
      
 19 
     | 
    
         
            +
                #
         
     | 
| 
      
 20 
     | 
    
         
            +
                # This method hits the `/v1/auth/token/lookup-self` endpoint after setting
         
     | 
| 
      
 21 
     | 
    
         
            +
                # the Vault client's token to the given token parameter. If the self lookup
         
     | 
| 
      
 22 
     | 
    
         
            +
                # succeeds, the token is persisted onto the client for future requests. If
         
     | 
| 
      
 23 
     | 
    
         
            +
                # the lookup fails, the old token (which could be unset) is restored on the
         
     | 
| 
      
 24 
     | 
    
         
            +
                # client.
         
     | 
| 
      
 25 
     | 
    
         
            +
                #
         
     | 
| 
      
 26 
     | 
    
         
            +
                # @example
         
     | 
| 
      
 27 
     | 
    
         
            +
                #   Vault.auth.token("6440e1bd-ba22-716a-887d-e133944d22bd") #=> #<Vault::Secret lease_id="">
         
     | 
| 
      
 28 
     | 
    
         
            +
                #   Vault.token #=> "6440e1bd-ba22-716a-887d-e133944d22bd"
         
     | 
| 
      
 29 
     | 
    
         
            +
                #
         
     | 
| 
      
 30 
     | 
    
         
            +
                # @param [String] new_token
         
     | 
| 
      
 31 
     | 
    
         
            +
                #   the new token to try to authenticate and store on the client
         
     | 
| 
      
 32 
     | 
    
         
            +
                #
         
     | 
| 
      
 33 
     | 
    
         
            +
                # @return [Secret]
         
     | 
| 
      
 34 
     | 
    
         
            +
                def token(new_token)
         
     | 
| 
      
 35 
     | 
    
         
            +
                  old_token    = client.token
         
     | 
| 
      
 36 
     | 
    
         
            +
                  client.token = new_token
         
     | 
| 
      
 37 
     | 
    
         
            +
                  json = client.get("/v1/auth/token/lookup-self")
         
     | 
| 
      
 38 
     | 
    
         
            +
                  secret = Secret.decode(json)
         
     | 
| 
      
 39 
     | 
    
         
            +
                  return secret
         
     | 
| 
      
 40 
     | 
    
         
            +
                rescue
         
     | 
| 
      
 41 
     | 
    
         
            +
                  client.token = old_token
         
     | 
| 
      
 42 
     | 
    
         
            +
                  raise
         
     | 
| 
      
 43 
     | 
    
         
            +
                end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                # Authenticate via the "app-id" authentication method. If authentication is
         
     | 
| 
      
 46 
     | 
    
         
            +
                # successful, the resulting token will be stored on the client and used for
         
     | 
| 
      
 47 
     | 
    
         
            +
                # future requests.
         
     | 
| 
      
 48 
     | 
    
         
            +
                #
         
     | 
| 
      
 49 
     | 
    
         
            +
                # @example
         
     | 
| 
      
 50 
     | 
    
         
            +
                #   Vault.auth.app_id(
         
     | 
| 
      
 51 
     | 
    
         
            +
                #     "aeece56e-3f9b-40c3-8f85-781d3e9a8f68",
         
     | 
| 
      
 52 
     | 
    
         
            +
                #     "3b87be76-95cf-493a-a61b-7d5fc70870ad",
         
     | 
| 
      
 53 
     | 
    
         
            +
                #   ) #=> #<Vault::Secret lease_id="">
         
     | 
| 
      
 54 
     | 
    
         
            +
                #
         
     | 
| 
      
 55 
     | 
    
         
            +
                # @example with a custom mount point
         
     | 
| 
      
 56 
     | 
    
         
            +
                #   Vault.auth.app_id(
         
     | 
| 
      
 57 
     | 
    
         
            +
                #     "aeece56e-3f9b-40c3-8f85-781d3e9a8f68",
         
     | 
| 
      
 58 
     | 
    
         
            +
                #     "3b87be76-95cf-493a-a61b-7d5fc70870ad",
         
     | 
| 
      
 59 
     | 
    
         
            +
                #     mount: "new-app-id",
         
     | 
| 
      
 60 
     | 
    
         
            +
                #   )
         
     | 
| 
      
 61 
     | 
    
         
            +
                #
         
     | 
| 
      
 62 
     | 
    
         
            +
                # @param [String] app_id
         
     | 
| 
      
 63 
     | 
    
         
            +
                # @param [String] user_id
         
     | 
| 
      
 64 
     | 
    
         
            +
                # @param [Hash] options
         
     | 
| 
      
 65 
     | 
    
         
            +
                #   additional options to pass to the authentication call, such as a custom
         
     | 
| 
      
 66 
     | 
    
         
            +
                #   mount point
         
     | 
| 
      
 67 
     | 
    
         
            +
                #
         
     | 
| 
      
 68 
     | 
    
         
            +
                # @return [Secret]
         
     | 
| 
      
 69 
     | 
    
         
            +
                def app_id(app_id, user_id, options = {})
         
     | 
| 
      
 70 
     | 
    
         
            +
                  payload = { app_id: app_id, user_id: user_id }.merge(options)
         
     | 
| 
      
 71 
     | 
    
         
            +
                  json = client.post("/v1/auth/app-id/login", JSON.fast_generate(payload))
         
     | 
| 
      
 72 
     | 
    
         
            +
                  secret = Secret.decode(json)
         
     | 
| 
      
 73 
     | 
    
         
            +
                  client.token = secret.auth.client_token
         
     | 
| 
      
 74 
     | 
    
         
            +
                  return secret
         
     | 
| 
      
 75 
     | 
    
         
            +
                end
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
                # Authenticate via the "userpass" authentication method. If authentication
         
     | 
| 
      
 78 
     | 
    
         
            +
                # is successful, the resulting token will be stored on the client and used
         
     | 
| 
      
 79 
     | 
    
         
            +
                # for future requests.
         
     | 
| 
      
 80 
     | 
    
         
            +
                #
         
     | 
| 
      
 81 
     | 
    
         
            +
                # @example
         
     | 
| 
      
 82 
     | 
    
         
            +
                #   Vault.auth.userpass("sethvargo", "s3kr3t") #=> #<Vault::Secret lease_id="">
         
     | 
| 
      
 83 
     | 
    
         
            +
                #
         
     | 
| 
      
 84 
     | 
    
         
            +
                # @example with a custom mount point
         
     | 
| 
      
 85 
     | 
    
         
            +
                #   Vault.auth.userpass("sethvargo", "s3kr3t", mount: "admin-login") #=> #<Vault::Secret lease_id="">
         
     | 
| 
      
 86 
     | 
    
         
            +
                #
         
     | 
| 
      
 87 
     | 
    
         
            +
                # @param [String] username
         
     | 
| 
      
 88 
     | 
    
         
            +
                # @param [String] password
         
     | 
| 
      
 89 
     | 
    
         
            +
                # @param [Hash] options
         
     | 
| 
      
 90 
     | 
    
         
            +
                #   additional options to pass to the authentication call, such as a custom
         
     | 
| 
      
 91 
     | 
    
         
            +
                #   mount point
         
     | 
| 
      
 92 
     | 
    
         
            +
                #
         
     | 
| 
      
 93 
     | 
    
         
            +
                # @return [Secret]
         
     | 
| 
      
 94 
     | 
    
         
            +
                def userpass(username, password, options = {})
         
     | 
| 
      
 95 
     | 
    
         
            +
                  payload = { password: password }.merge(options)
         
     | 
| 
      
 96 
     | 
    
         
            +
                  json = client.post("/v1/auth/userpass/login/#{username}", JSON.fast_generate(payload))
         
     | 
| 
      
 97 
     | 
    
         
            +
                  secret = Secret.decode(json)
         
     | 
| 
      
 98 
     | 
    
         
            +
                  client.token = secret.auth.client_token
         
     | 
| 
      
 99 
     | 
    
         
            +
                  return secret
         
     | 
| 
      
 100 
     | 
    
         
            +
                end
         
     | 
| 
      
 101 
     | 
    
         
            +
              end
         
     | 
| 
      
 102 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/vault/api/logical.rb
    CHANGED
    
    | 
         @@ -45,7 +45,11 @@ module Vault 
     | 
|
| 
       45 
45 
     | 
    
         
             
                # @return [Secret]
         
     | 
| 
       46 
46 
     | 
    
         
             
                def write(path, data = {})
         
     | 
| 
       47 
47 
     | 
    
         
             
                  json = client.put("/v1/#{path}", JSON.fast_generate(data))
         
     | 
| 
       48 
     | 
    
         
            -
                   
     | 
| 
      
 48 
     | 
    
         
            +
                  if json.nil?
         
     | 
| 
      
 49 
     | 
    
         
            +
                    return true
         
     | 
| 
      
 50 
     | 
    
         
            +
                  else
         
     | 
| 
      
 51 
     | 
    
         
            +
                    return Secret.decode(json)
         
     | 
| 
      
 52 
     | 
    
         
            +
                  end
         
     | 
| 
       49 
53 
     | 
    
         
             
                end
         
     | 
| 
       50 
54 
     | 
    
         | 
| 
       51 
55 
     | 
    
         
             
                # Delete the secret at the given path. If the secret does not exist, vault
         
     | 
    
        data/lib/vault/client.rb
    CHANGED
    
    | 
         @@ -28,6 +28,25 @@ module Vault 
     | 
|
| 
       28 
28 
     | 
    
         
             
                  symbolize_names:  true,
         
     | 
| 
       29 
29 
     | 
    
         
             
                }.freeze
         
     | 
| 
       30 
30 
     | 
    
         | 
| 
      
 31 
     | 
    
         
            +
                RESCUED_EXCEPTIONS = [].tap do |a|
         
     | 
| 
      
 32 
     | 
    
         
            +
                  # Failure to even open the socket (usually permissions)
         
     | 
| 
      
 33 
     | 
    
         
            +
                  a << SocketError
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                  # Failed to reach the server (aka bad URL)
         
     | 
| 
      
 36 
     | 
    
         
            +
                  a << Errno::ECONNREFUSED
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                  # Failed to read body or no response body given
         
     | 
| 
      
 39 
     | 
    
         
            +
                  a << EOFError
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                  # Timeout (Ruby 1.9-)
         
     | 
| 
      
 42 
     | 
    
         
            +
                  a << Timeout::Error
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                  # Timeout (Ruby 1.9+) - Ruby 1.9 does not define these constants so we
         
     | 
| 
      
 45 
     | 
    
         
            +
                  # only add them if they are defiend
         
     | 
| 
      
 46 
     | 
    
         
            +
                  a << Net::ReadTimeout if defined?(Net::ReadTimeout)
         
     | 
| 
      
 47 
     | 
    
         
            +
                  a << Net::OpenTimeout if defined?(Net::OpenTimeout)
         
     | 
| 
      
 48 
     | 
    
         
            +
                end.freeze
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
       31 
50 
     | 
    
         
             
                include Vault::Configurable
         
     | 
| 
       32 
51 
     | 
    
         | 
| 
       33 
52 
     | 
    
         
             
                # Create a new Client with the given options. Any options given take
         
     | 
| 
         @@ -37,12 +56,7 @@ module Vault 
     | 
|
| 
       37 
56 
     | 
    
         
             
                def initialize(options = {})
         
     | 
| 
       38 
57 
     | 
    
         
             
                  # Use any options given, but fall back to the defaults set on the module
         
     | 
| 
       39 
58 
     | 
    
         
             
                  Vault::Configurable.keys.each do |key|
         
     | 
| 
       40 
     | 
    
         
            -
                    value =  
     | 
| 
       41 
     | 
    
         
            -
                      Vault.instance_variable_get(:"@#{key}")
         
     | 
| 
       42 
     | 
    
         
            -
                    else
         
     | 
| 
       43 
     | 
    
         
            -
                      options[key]
         
     | 
| 
       44 
     | 
    
         
            -
                    end
         
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
      
 59 
     | 
    
         
            +
                    value = options.key?(key) ? options[key] : Defaults.public_send(key)
         
     | 
| 
       46 
60 
     | 
    
         
             
                    instance_variable_set(:"@#{key}", value)
         
     | 
| 
       47 
61 
     | 
    
         
             
                  end
         
     | 
| 
       48 
62 
     | 
    
         
             
                end
         
     | 
| 
         @@ -103,10 +117,6 @@ module Vault 
     | 
|
| 
       103 
117 
     | 
    
         
             
                # @return [String, Hash]
         
     | 
| 
       104 
118 
     | 
    
         
             
                #   the response body
         
     | 
| 
       105 
119 
     | 
    
         
             
                def request(verb, path, data = {}, headers = {})
         
     | 
| 
       106 
     | 
    
         
            -
                  # All requests to vault require a token, so we should error without even
         
     | 
| 
       107 
     | 
    
         
            -
                  # trying if there is no token set
         
     | 
| 
       108 
     | 
    
         
            -
                  raise MissingTokenError if token.nil?
         
     | 
| 
       109 
     | 
    
         
            -
             
     | 
| 
       110 
120 
     | 
    
         
             
                  # Build the URI and request object from the given information
         
     | 
| 
       111 
121 
     | 
    
         
             
                  uri = build_uri(verb, path, data)
         
     | 
| 
       112 
122 
     | 
    
         
             
                  request = class_for_request(verb).new(uri.request_uri)
         
     | 
| 
         @@ -135,18 +145,34 @@ module Vault 
     | 
|
| 
       135 
145 
     | 
    
         
             
                  connection = Net::HTTP.new(uri.host, uri.port,
         
     | 
| 
       136 
146 
     | 
    
         
             
                    proxy_address, proxy_port, proxy_username, proxy_password)
         
     | 
| 
       137 
147 
     | 
    
         | 
| 
      
 148 
     | 
    
         
            +
                  # Use a custom open timeout
         
     | 
| 
      
 149 
     | 
    
         
            +
                  if open_timeout || timeout
         
     | 
| 
      
 150 
     | 
    
         
            +
                    connection.open_timeout = (open_timeout || timeout).to_i
         
     | 
| 
      
 151 
     | 
    
         
            +
                  end
         
     | 
| 
      
 152 
     | 
    
         
            +
             
     | 
| 
      
 153 
     | 
    
         
            +
                  # Use a custom read timeout
         
     | 
| 
      
 154 
     | 
    
         
            +
                  if read_timeout || timeout
         
     | 
| 
      
 155 
     | 
    
         
            +
                    connection.read_timeout = (read_timeout || timeout).to_i
         
     | 
| 
      
 156 
     | 
    
         
            +
                  end
         
     | 
| 
      
 157 
     | 
    
         
            +
             
     | 
| 
       138 
158 
     | 
    
         
             
                  # Create the cookie for the request.
         
     | 
| 
       139 
159 
     | 
    
         
             
                  cookie = CGI::Cookie.new
         
     | 
| 
       140 
160 
     | 
    
         
             
                  cookie.name    = "token"
         
     | 
| 
       141 
161 
     | 
    
         
             
                  cookie.value   = token
         
     | 
| 
       142 
162 
     | 
    
         
             
                  cookie.path    = "/"
         
     | 
| 
       143 
     | 
    
         
            -
                  cookie.expires = Time.now + (60*60*24* 
     | 
| 
      
 163 
     | 
    
         
            +
                  cookie.expires = Time.now + (60*60*24*365)
         
     | 
| 
       144 
164 
     | 
    
         | 
| 
       145 
165 
     | 
    
         
             
                  # Apply SSL, if applicable
         
     | 
| 
       146 
166 
     | 
    
         
             
                  if uri.scheme == "https"
         
     | 
| 
       147 
167 
     | 
    
         
             
                    # Turn on SSL
         
     | 
| 
       148 
168 
     | 
    
         
             
                    connection.use_ssl = true
         
     | 
| 
       149 
169 
     | 
    
         | 
| 
      
 170 
     | 
    
         
            +
                    # Vault requires TLS1.2
         
     | 
| 
      
 171 
     | 
    
         
            +
                    connection.ssl_version = "TLSv1_2"
         
     | 
| 
      
 172 
     | 
    
         
            +
             
     | 
| 
      
 173 
     | 
    
         
            +
                    # Only use secure ciphers
         
     | 
| 
      
 174 
     | 
    
         
            +
                    connection.ciphers = ssl_ciphers
         
     | 
| 
      
 175 
     | 
    
         
            +
             
     | 
| 
       150 
176 
     | 
    
         
             
                    # Turn on secure cookies
         
     | 
| 
       151 
177 
     | 
    
         
             
                    cookie.secure = true
         
     | 
| 
       152 
178 
     | 
    
         | 
| 
         @@ -154,37 +180,56 @@ module Vault 
     | 
|
| 
       154 
180 
     | 
    
         
             
                    if ssl_pem_file
         
     | 
| 
       155 
181 
     | 
    
         
             
                      pem = File.read(ssl_pem_file)
         
     | 
| 
       156 
182 
     | 
    
         
             
                      connection.cert = OpenSSL::X509::Certificate.new(pem)
         
     | 
| 
       157 
     | 
    
         
            -
                      connection.key = OpenSSL::PKey::RSA.new(pem)
         
     | 
| 
      
 183 
     | 
    
         
            +
                      connection.key = OpenSSL::PKey::RSA.new(pem, ssl_pem_passphrase)
         
     | 
| 
       158 
184 
     | 
    
         
             
                      connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
         
     | 
| 
       159 
185 
     | 
    
         
             
                    end
         
     | 
| 
       160 
186 
     | 
    
         | 
| 
       161 
     | 
    
         
            -
                    #  
     | 
| 
      
 187 
     | 
    
         
            +
                    # Use custom CA cert for verification
         
     | 
| 
      
 188 
     | 
    
         
            +
                    if ssl_ca_cert
         
     | 
| 
      
 189 
     | 
    
         
            +
                      connection.ca_file = ssl_ca_cert
         
     | 
| 
      
 190 
     | 
    
         
            +
                    end
         
     | 
| 
      
 191 
     | 
    
         
            +
             
     | 
| 
      
 192 
     | 
    
         
            +
                    # Use custom CA path that contains CA certs
         
     | 
| 
      
 193 
     | 
    
         
            +
                    if ssl_ca_path
         
     | 
| 
      
 194 
     | 
    
         
            +
                      connection.ca_path = ssl_ca_path
         
     | 
| 
      
 195 
     | 
    
         
            +
                    end
         
     | 
| 
      
 196 
     | 
    
         
            +
             
     | 
| 
      
 197 
     | 
    
         
            +
                    # Naughty, naughty, naughty! Don't blame me when someone hops in
         
     | 
| 
       162 
198 
     | 
    
         
             
                    # and executes a MITM attack!
         
     | 
| 
       163 
     | 
    
         
            -
                     
     | 
| 
      
 199 
     | 
    
         
            +
                    if !ssl_verify
         
     | 
| 
       164 
200 
     | 
    
         
             
                      connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
         
     | 
| 
       165 
201 
     | 
    
         
             
                    end
         
     | 
| 
       166 
     | 
    
         
            -
                  end
         
     | 
| 
       167 
202 
     | 
    
         | 
| 
       168 
     | 
    
         
            -
             
     | 
| 
       169 
     | 
    
         
            -
             
     | 
| 
      
 203 
     | 
    
         
            +
                    # Use custom timeout for connecting and verifying via SSL
         
     | 
| 
      
 204 
     | 
    
         
            +
                    if ssl_timeout || timeout
         
     | 
| 
      
 205 
     | 
    
         
            +
                      connection.ssl_timeout = (ssl_timeout || timeout).to_i
         
     | 
| 
      
 206 
     | 
    
         
            +
                    end
         
     | 
| 
      
 207 
     | 
    
         
            +
                  end
         
     | 
| 
       170 
208 
     | 
    
         | 
| 
       171 
     | 
    
         
            -
                  #  
     | 
| 
       172 
     | 
    
         
            -
                   
     | 
| 
       173 
     | 
    
         
            -
             
     | 
| 
       174 
     | 
    
         
            -
             
     | 
| 
      
 209 
     | 
    
         
            +
                  # Add the cookie to the request if a token was given.
         
     | 
| 
      
 210 
     | 
    
         
            +
                  if !token.nil?
         
     | 
| 
      
 211 
     | 
    
         
            +
                    request["Cookie"] = cookie.to_s
         
     | 
| 
      
 212 
     | 
    
         
            +
                  end
         
     | 
| 
       175 
213 
     | 
    
         | 
| 
       176 
     | 
    
         
            -
             
     | 
| 
       177 
     | 
    
         
            -
                     
     | 
| 
       178 
     | 
    
         
            -
             
     | 
| 
       179 
     | 
    
         
            -
             
     | 
| 
       180 
     | 
    
         
            -
             
     | 
| 
       181 
     | 
    
         
            -
             
     | 
| 
       182 
     | 
    
         
            -
             
     | 
| 
       183 
     | 
    
         
            -
                       
     | 
| 
      
 214 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 215 
     | 
    
         
            +
                    # Create a connection using the block form, which will ensure the socket
         
     | 
| 
      
 216 
     | 
    
         
            +
                    # is properly closed in the event of an error.
         
     | 
| 
      
 217 
     | 
    
         
            +
                    connection.start do |http|
         
     | 
| 
      
 218 
     | 
    
         
            +
                      response = http.request(request)
         
     | 
| 
      
 219 
     | 
    
         
            +
             
     | 
| 
      
 220 
     | 
    
         
            +
                      case response
         
     | 
| 
      
 221 
     | 
    
         
            +
                      when Net::HTTPRedirection
         
     | 
| 
      
 222 
     | 
    
         
            +
                        redirect = URI.parse(response["location"])
         
     | 
| 
      
 223 
     | 
    
         
            +
                        request(verb, redirect, data, headers)
         
     | 
| 
      
 224 
     | 
    
         
            +
                      when Net::HTTPSuccess
         
     | 
| 
      
 225 
     | 
    
         
            +
                        success(response)
         
     | 
| 
      
 226 
     | 
    
         
            +
                      else
         
     | 
| 
      
 227 
     | 
    
         
            +
                        error(response)
         
     | 
| 
      
 228 
     | 
    
         
            +
                      end
         
     | 
| 
       184 
229 
     | 
    
         
             
                    end
         
     | 
| 
      
 230 
     | 
    
         
            +
                  rescue *RESCUED_EXCEPTIONS => e
         
     | 
| 
      
 231 
     | 
    
         
            +
                    raise HTTPConnectionError.new(address, e)
         
     | 
| 
       185 
232 
     | 
    
         
             
                  end
         
     | 
| 
       186 
     | 
    
         
            -
                rescue SocketError, Errno::ECONNREFUSED, EOFError
         
     | 
| 
       187 
     | 
    
         
            -
                  raise HTTPConnectionError.new(address)
         
     | 
| 
       188 
233 
     | 
    
         
             
                end
         
     | 
| 
       189 
234 
     | 
    
         | 
| 
       190 
235 
     | 
    
         
             
                # Construct a URL from the given verb and path. If the request is a GET or
         
     | 
| 
         @@ -269,6 +314,10 @@ module Vault 
     | 
|
| 
       269 
314 
     | 
    
         
             
                # @param [HTTP::Message] response
         
     | 
| 
       270 
315 
     | 
    
         
             
                #   the response object from the request
         
     | 
| 
       271 
316 
     | 
    
         
             
                def error(response)
         
     | 
| 
      
 317 
     | 
    
         
            +
                  if response.body && response.body.match("missing client token")
         
     | 
| 
      
 318 
     | 
    
         
            +
                    raise MissingTokenError
         
     | 
| 
      
 319 
     | 
    
         
            +
                  end
         
     | 
| 
      
 320 
     | 
    
         
            +
             
     | 
| 
       272 
321 
     | 
    
         
             
                  if (response.content_type || '').include?("json")
         
     | 
| 
       273 
322 
     | 
    
         
             
                    # Attempt to parse the error as JSON
         
     | 
| 
       274 
323 
     | 
    
         
             
                    begin
         
     | 
    
        data/lib/vault/configurable.rb
    CHANGED
    
    | 
         @@ -6,12 +6,19 @@ module Vault 
     | 
|
| 
       6 
6 
     | 
    
         
             
                  @keys ||= [
         
     | 
| 
       7 
7 
     | 
    
         
             
                    :address,
         
     | 
| 
       8 
8 
     | 
    
         
             
                    :token,
         
     | 
| 
      
 9 
     | 
    
         
            +
                    :open_timeout,
         
     | 
| 
       9 
10 
     | 
    
         
             
                    :proxy_address,
         
     | 
| 
       10 
11 
     | 
    
         
             
                    :proxy_password,
         
     | 
| 
       11 
12 
     | 
    
         
             
                    :proxy_port,
         
     | 
| 
       12 
13 
     | 
    
         
             
                    :proxy_username,
         
     | 
| 
      
 14 
     | 
    
         
            +
                    :read_timeout,
         
     | 
| 
      
 15 
     | 
    
         
            +
                    :ssl_ciphers,
         
     | 
| 
       13 
16 
     | 
    
         
             
                    :ssl_pem_file,
         
     | 
| 
      
 17 
     | 
    
         
            +
                    :ssl_ca_cert,
         
     | 
| 
      
 18 
     | 
    
         
            +
                    :ssl_ca_path,
         
     | 
| 
       14 
19 
     | 
    
         
             
                    :ssl_verify,
         
     | 
| 
      
 20 
     | 
    
         
            +
                    :ssl_timeout,
         
     | 
| 
      
 21 
     | 
    
         
            +
                    :timeout,
         
     | 
| 
       15 
22 
     | 
    
         
             
                  ]
         
     | 
| 
       16 
23 
     | 
    
         
             
                end
         
     | 
| 
       17 
24 
     | 
    
         | 
| 
         @@ -24,18 +31,6 @@ module Vault 
     | 
|
| 
       24 
31 
     | 
    
         
             
                  yield self
         
     | 
| 
       25 
32 
     | 
    
         
             
                end
         
     | 
| 
       26 
33 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
                # Reset all the values to their defaults.
         
     | 
| 
       28 
     | 
    
         
            -
                #
         
     | 
| 
       29 
     | 
    
         
            -
                # @return [self]
         
     | 
| 
       30 
     | 
    
         
            -
                def reset!
         
     | 
| 
       31 
     | 
    
         
            -
                  defaults = Defaults.options
         
     | 
| 
       32 
     | 
    
         
            -
                  Vault::Configurable.keys.each do |key|
         
     | 
| 
       33 
     | 
    
         
            -
                    instance_variable_set(:"@#{key}", defaults[key])
         
     | 
| 
       34 
     | 
    
         
            -
                  end
         
     | 
| 
       35 
     | 
    
         
            -
                  self
         
     | 
| 
       36 
     | 
    
         
            -
                end
         
     | 
| 
       37 
     | 
    
         
            -
                alias_method :setup!, :reset!
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
34 
     | 
    
         
             
                # The list of options for this configurable.
         
     | 
| 
       40 
35 
     | 
    
         
             
                #
         
     | 
| 
       41 
36 
     | 
    
         
             
                # @return [Hash<Symbol, Object>]
         
     | 
    
        data/lib/vault/defaults.rb
    CHANGED
    
    | 
         @@ -1,9 +1,20 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require "pathname"
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            module Vault
         
     | 
| 
       2 
4 
     | 
    
         
             
              module Defaults
         
     | 
| 
       3 
5 
     | 
    
         
             
                # The default vault address.
         
     | 
| 
       4 
6 
     | 
    
         
             
                # @return [String]
         
     | 
| 
       5 
7 
     | 
    
         
             
                VAULT_ADDRESS = "https://127.0.0.1:8200".freeze
         
     | 
| 
       6 
8 
     | 
    
         | 
| 
      
 9 
     | 
    
         
            +
                # The path to the vault token on disk.
         
     | 
| 
      
 10 
     | 
    
         
            +
                # @return [String]
         
     | 
| 
      
 11 
     | 
    
         
            +
                VAULT_DISK_TOKEN = Pathname.new("~/.vault-token").expand_path.freeze
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                # The list of SSL ciphers to allow. You should not change this value unless
         
     | 
| 
      
 14 
     | 
    
         
            +
                # you absolutely know what you are doing!
         
     | 
| 
      
 15 
     | 
    
         
            +
                # @return [String]
         
     | 
| 
      
 16 
     | 
    
         
            +
                SSL_CIPHERS = "TLSv1.2:!aNULL:!eNULL".freeze
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
       7 
18 
     | 
    
         
             
                class << self
         
     | 
| 
       8 
19 
     | 
    
         
             
                  # The list of calculated options for this configurable.
         
     | 
| 
       9 
20 
     | 
    
         
             
                  # @return [Hash]
         
     | 
| 
         @@ -20,7 +31,18 @@ module Vault 
     | 
|
| 
       20 
31 
     | 
    
         
             
                  # The vault token to use for authentiation.
         
     | 
| 
       21 
32 
     | 
    
         
             
                  # @return [String, nil]
         
     | 
| 
       22 
33 
     | 
    
         
             
                  def token
         
     | 
| 
       23 
     | 
    
         
            -
                     
     | 
| 
      
 34 
     | 
    
         
            +
                    if VAULT_DISK_TOKEN.exist? && VAULT_DISK_TOKEN.readable?
         
     | 
| 
      
 35 
     | 
    
         
            +
                      VAULT_DISK_TOKEN.read
         
     | 
| 
      
 36 
     | 
    
         
            +
                    else
         
     | 
| 
      
 37 
     | 
    
         
            +
                      ENV["VAULT_TOKEN"]
         
     | 
| 
      
 38 
     | 
    
         
            +
                    end
         
     | 
| 
      
 39 
     | 
    
         
            +
                  end
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                  # The number of seconds to wait when trying to open a connection before
         
     | 
| 
      
 42 
     | 
    
         
            +
                  # timing out
         
     | 
| 
      
 43 
     | 
    
         
            +
                  # @return [String, nil]
         
     | 
| 
      
 44 
     | 
    
         
            +
                  def open_timeout
         
     | 
| 
      
 45 
     | 
    
         
            +
                    ENV["VAULT_OPEN_TIMEOUT"]
         
     | 
| 
       24 
46 
     | 
    
         
             
                  end
         
     | 
| 
       25 
47 
     | 
    
         | 
| 
       26 
48 
     | 
    
         
             
                  # The HTTP Proxy server address as a string
         
     | 
| 
         @@ -47,14 +69,46 @@ module Vault 
     | 
|
| 
       47 
69 
     | 
    
         
             
                    ENV["VAULT_PROXY_PORT"]
         
     | 
| 
       48 
70 
     | 
    
         
             
                  end
         
     | 
| 
       49 
71 
     | 
    
         | 
| 
      
 72 
     | 
    
         
            +
                  # The number of seconds to wait when reading a response before timing out
         
     | 
| 
      
 73 
     | 
    
         
            +
                  # @return [String, nil]
         
     | 
| 
      
 74 
     | 
    
         
            +
                  def read_timeout
         
     | 
| 
      
 75 
     | 
    
         
            +
                    ENV["VAULT_READ_TIMEOUT"]
         
     | 
| 
      
 76 
     | 
    
         
            +
                  end
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
                  # The ciphers that will be used when communicating with vault over ssl
         
     | 
| 
      
 79 
     | 
    
         
            +
                  # You should only change the defaults if the ciphers are not available on
         
     | 
| 
      
 80 
     | 
    
         
            +
                  # your platform and you know what you are doing
         
     | 
| 
      
 81 
     | 
    
         
            +
                  # @return [String]
         
     | 
| 
      
 82 
     | 
    
         
            +
                  def ssl_ciphers
         
     | 
| 
      
 83 
     | 
    
         
            +
                    ENV["VAULT_SSL_CIPHERS"] || SSL_CIPHERS
         
     | 
| 
      
 84 
     | 
    
         
            +
                  end
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
       50 
86 
     | 
    
         
             
                  # The path to a pem on disk to use with custom SSL verification
         
     | 
| 
       51 
87 
     | 
    
         
             
                  # @return [String, nil]
         
     | 
| 
       52 
88 
     | 
    
         
             
                  def ssl_pem_file
         
     | 
| 
       53 
89 
     | 
    
         
             
                    ENV["VAULT_SSL_CERT"]
         
     | 
| 
       54 
90 
     | 
    
         
             
                  end
         
     | 
| 
       55 
91 
     | 
    
         | 
| 
       56 
     | 
    
         
            -
                  #  
     | 
| 
      
 92 
     | 
    
         
            +
                  # The path to a pem on disk to use with custom SSL verification
         
     | 
| 
      
 93 
     | 
    
         
            +
                  # @return [String, nil]
         
     | 
| 
      
 94 
     | 
    
         
            +
                  def ssl_pem_passphrase
         
     | 
| 
      
 95 
     | 
    
         
            +
                    ENV["VAULT_SSL_CERT_PASSPHRASE"]
         
     | 
| 
      
 96 
     | 
    
         
            +
                  end
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
      
 98 
     | 
    
         
            +
                  # The path to the CA cert on disk to use for certificate verification
         
     | 
| 
      
 99 
     | 
    
         
            +
                  # @return [String, nil]
         
     | 
| 
      
 100 
     | 
    
         
            +
                  def ssl_ca_cert
         
     | 
| 
      
 101 
     | 
    
         
            +
                    ENV["VAULT_CACERT"]
         
     | 
| 
      
 102 
     | 
    
         
            +
                  end
         
     | 
| 
       57 
103 
     | 
    
         
             
                  #
         
     | 
| 
      
 104 
     | 
    
         
            +
                  # The path to the directory on disk holding CA certs to use
         
     | 
| 
      
 105 
     | 
    
         
            +
                  # for certificate verification
         
     | 
| 
      
 106 
     | 
    
         
            +
                  # @return [String, nil]
         
     | 
| 
      
 107 
     | 
    
         
            +
                  def ssl_ca_path
         
     | 
| 
      
 108 
     | 
    
         
            +
                    ENV["VAULT_CAPATH"]
         
     | 
| 
      
 109 
     | 
    
         
            +
                  end
         
     | 
| 
      
 110 
     | 
    
         
            +
             
     | 
| 
      
 111 
     | 
    
         
            +
                  # Verify SSL requests (default: true)
         
     | 
| 
       58 
112 
     | 
    
         
             
                  # @return [true, false]
         
     | 
| 
       59 
113 
     | 
    
         
             
                  def ssl_verify
         
     | 
| 
       60 
114 
     | 
    
         
             
                    if ENV["VAULT_SSL_VERIFY"].nil?
         
     | 
| 
         @@ -63,6 +117,19 @@ module Vault 
     | 
|
| 
       63 
117 
     | 
    
         
             
                      %w[t y].include?(ENV["VAULT_SSL_VERIFY"].downcase[0])
         
     | 
| 
       64 
118 
     | 
    
         
             
                    end
         
     | 
| 
       65 
119 
     | 
    
         
             
                  end
         
     | 
| 
      
 120 
     | 
    
         
            +
             
     | 
| 
      
 121 
     | 
    
         
            +
                  # The number of seconds to wait for connecting and verifying SSL
         
     | 
| 
      
 122 
     | 
    
         
            +
                  # @return [String, nil]
         
     | 
| 
      
 123 
     | 
    
         
            +
                  def ssl_timeout
         
     | 
| 
      
 124 
     | 
    
         
            +
                    ENV["VAULT_SSL_TIMEOUT"]
         
     | 
| 
      
 125 
     | 
    
         
            +
                  end
         
     | 
| 
      
 126 
     | 
    
         
            +
             
     | 
| 
      
 127 
     | 
    
         
            +
                  # A default meta-attribute to set all timeout values - individually set
         
     | 
| 
      
 128 
     | 
    
         
            +
                  # timeout values will take precedence
         
     | 
| 
      
 129 
     | 
    
         
            +
                  # @return [String, nil]
         
     | 
| 
      
 130 
     | 
    
         
            +
                  def timeout
         
     | 
| 
      
 131 
     | 
    
         
            +
                    ENV["VAULT_TIMEOUT"]
         
     | 
| 
      
 132 
     | 
    
         
            +
                  end
         
     | 
| 
       66 
133 
     | 
    
         
             
                end
         
     | 
| 
       67 
134 
     | 
    
         
             
              end
         
     | 
| 
       68 
135 
     | 
    
         
             
            end
         
     | 
    
        data/lib/vault/errors.rb
    CHANGED
    
    | 
         @@ -5,10 +5,18 @@ module Vault 
     | 
|
| 
       5 
5 
     | 
    
         
             
                def initialize
         
     | 
| 
       6 
6 
     | 
    
         
             
                  super <<-EOH
         
     | 
| 
       7 
7 
     | 
    
         
             
            Missing Vault token! I cannot make requests to Vault without a token. Please
         
     | 
| 
       8 
     | 
    
         
            -
            set a Vault token:
         
     | 
| 
      
 8 
     | 
    
         
            +
            set a Vault token in the client:
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
                Vault.token = "42d1dee5-eb6e-102c-8d23-cc3ba875da51"
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
      
 12 
     | 
    
         
            +
            or authenticate with Vault using the Vault CLI:
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                $ vault auth ...
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            or set the environment variable $VAULT_TOKEN to the token value:
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                $ export VAULT_TOKEN="..."
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
       12 
20 
     | 
    
         
             
            Please refer to the documentation for more examples.
         
     | 
| 
       13 
21 
     | 
    
         
             
            EOH
         
     | 
| 
       14 
22 
     | 
    
         
             
                end
         
     | 
| 
         @@ -17,13 +25,21 @@ EOH 
     | 
|
| 
       17 
25 
     | 
    
         
             
              class HTTPConnectionError < VaultError
         
     | 
| 
       18 
26 
     | 
    
         
             
                attr_reader :address
         
     | 
| 
       19 
27 
     | 
    
         | 
| 
       20 
     | 
    
         
            -
                def initialize(address)
         
     | 
| 
      
 28 
     | 
    
         
            +
                def initialize(address, exception)
         
     | 
| 
       21 
29 
     | 
    
         
             
                  @address = address
         
     | 
| 
      
 30 
     | 
    
         
            +
                  @exception = exception
         
     | 
| 
       22 
31 
     | 
    
         | 
| 
       23 
32 
     | 
    
         
             
                  super <<-EOH
         
     | 
| 
       24 
33 
     | 
    
         
             
            The Vault server at `#{address}' is not currently
         
     | 
| 
       25 
     | 
    
         
            -
            accepting connections. Please ensure that the server is running  
     | 
| 
      
 34 
     | 
    
         
            +
            accepting connections. Please ensure that the server is running and that your
         
     | 
| 
       26 
35 
     | 
    
         
             
            authentication information is correct.
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
            The original error was `#{exception.class}'. Additional information (if any) is
         
     | 
| 
      
 38 
     | 
    
         
            +
            shown below:
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                #{exception.message}
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
            Please refer to the documentation for more help.
         
     | 
| 
       27 
43 
     | 
    
         
             
            EOH
         
     | 
| 
       28 
44 
     | 
    
         
             
                end
         
     | 
| 
       29 
45 
     | 
    
         
             
              end
         
     | 
    
        data/lib/vault/version.rb
    CHANGED
    
    
    
        data/vault.gemspec
    CHANGED
    
    | 
         @@ -20,6 +20,7 @@ Gem::Specification.new do |spec| 
     | 
|
| 
       20 
20 
     | 
    
         
             
              spec.require_paths = ["lib"]
         
     | 
| 
       21 
21 
     | 
    
         | 
| 
       22 
22 
     | 
    
         
             
              spec.add_development_dependency "bundler", "~> 1.9"
         
     | 
| 
      
 23 
     | 
    
         
            +
              spec.add_development_dependency "pry"
         
     | 
| 
       23 
24 
     | 
    
         
             
              spec.add_development_dependency "rake",    "~> 10.0"
         
     | 
| 
       24 
25 
     | 
    
         
             
              spec.add_development_dependency "rspec",   "~> 3.2"
         
     | 
| 
       25 
26 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: vault
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.4
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Seth Vargo
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2015- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2015-08-15 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     | 
| 
         @@ -24,6 +24,20 @@ dependencies: 
     | 
|
| 
       24 
24 
     | 
    
         
             
                - - "~>"
         
     | 
| 
       25 
25 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       26 
26 
     | 
    
         
             
                    version: '1.9'
         
     | 
| 
      
 27 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 28 
     | 
    
         
            +
              name: pry
         
     | 
| 
      
 29 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 30 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 31 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 32 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 33 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
      
 34 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 35 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 36 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 37 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 38 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 39 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 40 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
       27 
41 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       28 
42 
     | 
    
         
             
              name: rake
         
     | 
| 
       29 
43 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
         @@ -70,6 +84,7 @@ files: 
     | 
|
| 
       70 
84 
     | 
    
         
             
            - Rakefile
         
     | 
| 
       71 
85 
     | 
    
         
             
            - lib/vault.rb
         
     | 
| 
       72 
86 
     | 
    
         
             
            - lib/vault/api.rb
         
     | 
| 
      
 87 
     | 
    
         
            +
            - lib/vault/api/auth.rb
         
     | 
| 
       73 
88 
     | 
    
         
             
            - lib/vault/api/auth_token.rb
         
     | 
| 
       74 
89 
     | 
    
         
             
            - lib/vault/api/help.rb
         
     | 
| 
       75 
90 
     | 
    
         
             
            - lib/vault/api/logical.rb
         
     |