Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Name parameter for TLS auth and real LIST HTTP Methods #201

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/vault/api/auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions lib/vault/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/vault/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Vault
VERSION = "0.12.0"
VERSION = "0.12.2"
end
10 changes: 10 additions & 0 deletions spec/integration/api/auth_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down