Skip to content

Commit

Permalink
Add method to Vault::Sys to retrieve mount tuning settings. (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
ohookins authored May 3, 2021
1 parent 9ebb47e commit 44d180d
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
54 changes: 54 additions & 0 deletions lib/vault/api/sys/mount.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,48 @@ class Mount < Response
field :options
end

class MountTune < Response
# @!attribute [r] description
# Specifies the description of the mount.
# @return [String]
field :description

# @!attribute [r] default_lease_ttl
# Specifies the default time-to-live.
# @return [Fixnum]
field :default_lease_ttl

# @!attribute [r] max_lease_ttl
# Specifies the maximum time-to-live.
# @return [Fixnum]
field :max_lease_ttl

# @!attribute [r] audit_non_hmac_request_keys
# Specifies the comma-separated list of keys that will not be HMAC'd by audit devices in the request data object.
# @return [Array<String>]
field :audit_non_hmac_request_keys

# @!attribute [r] audit_non_hmac_response_keys
# Specifies the comma-separated list of keys that will not be HMAC'd by audit devices in the response data object.
# @return [Array<String>]
field :audit_non_hmac_response_keys

# @!attribute [r] listing_visibility
# Specifies whether to show this mount in the UI-specific listing endpoint.
# @return [String]
field :listing_visibility

# @!attribute [r] passthrough_request_headers
# Comma-separated list of headers to whitelist and pass from the request to the plugin.
# @return [Array<String>]
field :passthrough_request_headers

# @!attribute [r] allowed_response_headers
# Comma-separated list of headers to whitelist, allowing a plugin to include them in the response.
# @return [Array<String>]
field :allowed_response_headers
end

class Sys < Request
# List all mounts in the vault.
#
Expand Down Expand Up @@ -57,6 +99,18 @@ def mount(path, type, description = nil, options = {})
return true
end

# Get the mount tunings at a given path.
#
# @example
# Vault.sys.get_mount_tune("pki") #=> { :pki => #<struct Vault::MountTune default_lease_ttl=2764800> }
#
# @return [MountTune]
def get_mount_tune(path)
json = client.get("/v1/sys/mounts/#{encode_path(path)}/tune")
json = json[:data] if json[:data]
return MountTune.decode(json)
end

# Tune a mount at the given path.
#
# @example
Expand Down
15 changes: 15 additions & 0 deletions spec/integration/api/sys/mount_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ module Vault
end
end

describe "#get_mount_tune" do
it "gets the mount tune settings" do
subject.mount("test_mount_get_tune", "aws")
result = subject.get_mount_tune("test_mount_get_tune")
expect(result.default_lease_ttl).to eq(2764800)
expect(result).to be_a(MountTune)

# Modify the mount tuning setting and recheck
subject.mount_tune("test_mount_get_tune", default_lease_ttl: 12345)
result = subject.get_mount_tune("test_mount_get_tune")
expect(result.default_lease_ttl).to eq(12345)
expect(result).to be_a(MountTune)
end
end

describe "#mount_tune" do
it "tunes the mount" do
expect(subject.mount("test_mount_tune", "aws")).to be(true)
Expand Down

0 comments on commit 44d180d

Please sign in to comment.