diff --git a/lib/vault/api/auth.rb b/lib/vault/api/auth.rb index 156c1945..af6e929b 100644 --- a/lib/vault/api/auth.rb +++ b/lib/vault/api/auth.rb @@ -287,11 +287,13 @@ def gcp(role, jwt, path = 'gcp') # The path to the auth backend to use for the login procedure. # # @return [Secret] - def tls(pem = nil, path = 'cert') + def tls(pem = nil, path = 'cert', name = nil) new_client = client.dup new_client.ssl_pem_contents = pem if !pem.nil? + + payload = name.nil? ? {} : { name: name } - json = new_client.post("/v1/auth/#{CGI.escape(path)}/login") + json = new_client.post("/v1/auth/#{CGI.escape(path)}/login", JSON.fast_generate(payload)) secret = Secret.decode(json) client.token = secret.auth.client_token return secret diff --git a/lib/vault/client.rb b/lib/vault/client.rb index ddc9aa28..f68a7019 100644 --- a/lib/vault/client.rb +++ b/lib/vault/client.rb @@ -237,7 +237,14 @@ def delete(path, params = {}, headers = {}) def request(verb, path, data = {}, headers = {}) # Build the URI and request object from the given information uri = build_uri(verb, path, data) - request = class_for_request(verb).new(uri.request_uri) + request_class = class_for_request(verb) + + if request_class.nil? # Support Verbs not in Net::HTTP + request = Net::HTTPGenericRequest.new(verb.to_s.upcase,false, true, uri.request_uri) + else + request = request_class.new(uri.request_uri) + end + if uri.userinfo() request.basic_auth uri.user, uri.password end @@ -335,7 +342,11 @@ def build_uri(verb, path, params = {}) # # @return [Class] def class_for_request(verb) - Net::HTTP.const_get(verb.to_s.capitalize) + begin + Net::HTTP.const_get(verb.to_s.capitalize) + rescue NameError # The contsant doesn't exist + nil + end end # Convert the given hash to a list of query string parameters. Each key and diff --git a/lib/vault/version.rb b/lib/vault/version.rb index 3357c48a..9a246152 100644 --- a/lib/vault/version.rb +++ b/lib/vault/version.rb @@ -1,3 +1,3 @@ module Vault - VERSION = "0.12.0" + VERSION = "0.12.2" end diff --git a/spec/integration/api/auth_spec.rb b/spec/integration/api/auth_spec.rb index 6a380789..b63832e9 100644 --- a/spec/integration/api/auth_spec.rb +++ b/spec/integration/api/auth_spec.rb @@ -202,6 +202,16 @@ module Vault expect(subject.token).to eq(result.auth.client_token) end + it "authenticates with named ssl_pem_file" do + pending "dev server does not support tls" + + subject.auth_tls.set_certificate("kaelumania", certificate) + subject.ssl_pem_file = auth_cert + + result = subject.auth.tls(name: "kaelumania") + expect(subject.token).to eq(result.auth.client_token) + end + it "raises an error if the authentication is bad", vault: "> 0.6.1" do subject.sys.disable_auth("cert")