dd-vault 0.12.0

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.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +42 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +26 -0
  5. data/CHANGELOG.md +228 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE +362 -0
  8. data/README.md +214 -0
  9. data/Rakefile +6 -0
  10. data/lib/vault/api/approle.rb +218 -0
  11. data/lib/vault/api/auth.rb +316 -0
  12. data/lib/vault/api/auth_tls.rb +92 -0
  13. data/lib/vault/api/auth_token.rb +242 -0
  14. data/lib/vault/api/help.rb +33 -0
  15. data/lib/vault/api/logical.rb +150 -0
  16. data/lib/vault/api/secret.rb +156 -0
  17. data/lib/vault/api/sys/audit.rb +91 -0
  18. data/lib/vault/api/sys/auth.rb +116 -0
  19. data/lib/vault/api/sys/health.rb +63 -0
  20. data/lib/vault/api/sys/init.rb +83 -0
  21. data/lib/vault/api/sys/leader.rb +48 -0
  22. data/lib/vault/api/sys/lease.rb +49 -0
  23. data/lib/vault/api/sys/mount.rb +103 -0
  24. data/lib/vault/api/sys/policy.rb +92 -0
  25. data/lib/vault/api/sys/seal.rb +81 -0
  26. data/lib/vault/api/sys.rb +25 -0
  27. data/lib/vault/api.rb +12 -0
  28. data/lib/vault/client.rb +447 -0
  29. data/lib/vault/configurable.rb +48 -0
  30. data/lib/vault/defaults.rb +197 -0
  31. data/lib/vault/encode.rb +19 -0
  32. data/lib/vault/errors.rb +72 -0
  33. data/lib/vault/persistent/connection.rb +42 -0
  34. data/lib/vault/persistent/pool.rb +48 -0
  35. data/lib/vault/persistent/timed_stack_multi.rb +70 -0
  36. data/lib/vault/persistent.rb +1158 -0
  37. data/lib/vault/request.rb +43 -0
  38. data/lib/vault/response.rb +89 -0
  39. data/lib/vault/vendor/connection_pool/timed_stack.rb +178 -0
  40. data/lib/vault/vendor/connection_pool/version.rb +5 -0
  41. data/lib/vault/vendor/connection_pool.rb +150 -0
  42. data/lib/vault/version.rb +3 -0
  43. data/lib/vault.rb +49 -0
  44. data/vault.gemspec +30 -0
  45. metadata +185 -0
@@ -0,0 +1,150 @@
1
+ require_relative "secret"
2
+ require_relative "../client"
3
+ require_relative "../request"
4
+ require_relative "../response"
5
+
6
+ module Vault
7
+ class Client
8
+ # A proxy to the {Logical} methods.
9
+ # @return [Logical]
10
+ def logical
11
+ @logical ||= Logical.new(self)
12
+ end
13
+ end
14
+
15
+ class Logical < Request
16
+ # List the secrets at the given path, if the path supports listing. If the
17
+ # the path does not exist, an exception will be raised.
18
+ #
19
+ # @example
20
+ # Vault.logical.list("secret") #=> [#<Vault::Secret>, #<Vault::Secret>, ...]
21
+ #
22
+ # @param [String] path
23
+ # the path to list
24
+ #
25
+ # @return [Array<String>]
26
+ def list(path, options = {})
27
+ headers = extract_headers!(options)
28
+ json = client.list("/v1/#{encode_path(path)}", {}, headers)
29
+ json[:data][:keys] || []
30
+ rescue HTTPError => e
31
+ return [] if e.code == 404
32
+ raise
33
+ end
34
+
35
+ # Read the secret at the given path. If the secret does not exist, +nil+
36
+ # will be returned.
37
+ #
38
+ # @example
39
+ # Vault.logical.read("secret/password") #=> #<Vault::Secret lease_id="">
40
+ #
41
+ # @param [String] path
42
+ # the path to read
43
+ #
44
+ # @return [Secret, nil]
45
+ def read(path, params = {}, options = {})
46
+ headers = extract_headers!(options)
47
+ json = client.get("/v1/#{encode_path(path)}", params, headers)
48
+ return Secret.decode(json)
49
+ rescue HTTPError => e
50
+ return nil if e.code == 404
51
+ raise
52
+ end
53
+
54
+ # Write the secret at the given path with the given data. Note that the
55
+ # data must be a {Hash}!
56
+ #
57
+ # @example
58
+ # Vault.logical.write("secret/password", value: "secret") #=> #<Vault::Secret lease_id="">
59
+ #
60
+ # @param [String] path
61
+ # the path to write
62
+ # @param [Hash] data
63
+ # the data to write
64
+ #
65
+ # @return [Secret]
66
+ def write(path, data = {}, options = {})
67
+ headers = extract_headers!(options)
68
+ json = client.put("/v1/#{encode_path(path)}", JSON.fast_generate(data), headers)
69
+ if json.nil?
70
+ return true
71
+ else
72
+ return Secret.decode(json)
73
+ end
74
+ end
75
+
76
+ # Delete the secret at the given path. If the secret does not exist, vault
77
+ # will still return true.
78
+ #
79
+ # @example
80
+ # Vault.logical.delete("secret/password") #=> true
81
+ #
82
+ # @param [String] path
83
+ # the path to delete
84
+ #
85
+ # @return [true]
86
+ def delete(path)
87
+ client.delete("/v1/#{encode_path(path)}")
88
+ return true
89
+ end
90
+
91
+ # Unwrap the data stored against the given token. If the secret does not
92
+ # exist, `nil` will be returned.
93
+ #
94
+ # @example
95
+ # Vault.logical.unwrap("f363dba8-25a7-08c5-430c-00b2367124e6") #=> #<Vault::Secret lease_id="">
96
+ #
97
+ # @param [String] wrapper
98
+ # the token to use when unwrapping the value
99
+ #
100
+ # @return [Secret, nil]
101
+ def unwrap(wrapper)
102
+ client.with_token(wrapper) do |client|
103
+ json = client.get("/v1/cubbyhole/response")
104
+ secret = Secret.decode(json)
105
+
106
+ # If there is nothing in the cubbyhole, return early.
107
+ if secret.nil? || secret.data.nil? || secret.data[:response].nil?
108
+ return nil
109
+ end
110
+
111
+ # Extract the response and parse it into a new secret.
112
+ json = JSON.parse(secret.data[:response], symbolize_names: true)
113
+ secret = Secret.decode(json)
114
+ return secret
115
+ end
116
+ rescue HTTPError => e
117
+ return nil if e.code == 404
118
+ raise
119
+ end
120
+
121
+ # Unwrap a token in a wrapped response given the temporary token.
122
+ #
123
+ # @example
124
+ # Vault.logical.unwrap("f363dba8-25a7-08c5-430c-00b2367124e6") #=> "0f0f40fd-06ce-4af1-61cb-cdc12796f42b"
125
+ #
126
+ # @param [String, Secret] wrapper
127
+ # the token to unwrap
128
+ #
129
+ # @return [String, nil]
130
+ def unwrap_token(wrapper)
131
+ # If provided a secret, grab the token. This is really just to make the
132
+ # API a bit nicer.
133
+ if wrapper.is_a?(Secret)
134
+ wrapper = wrapper.wrap_info.token
135
+ end
136
+
137
+ # Unwrap
138
+ response = unwrap(wrapper)
139
+
140
+ # If nothing was there, return nil
141
+ if response.nil? || response.auth.nil?
142
+ return nil
143
+ end
144
+
145
+ return response.auth.client_token
146
+ rescue HTTPError => e
147
+ raise
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,156 @@
1
+ require "time"
2
+
3
+ require_relative "../response"
4
+
5
+ module Vault
6
+ # Secret is a representation of a secret from Vault. Almost all data returned
7
+ # from Vault is represented as a secret.
8
+ class Secret < Response
9
+ # @!attribute [r] auth
10
+ # Authentication information for this secret, if any. Most secrets will
11
+ # contain this field, but it may also be `nil`. When authenticating to
12
+ # Vault, the resulting Vault token will be included in this embedded
13
+ # field.
14
+ #
15
+ # @example Authenticating to Vault
16
+ # secret = Vault.auth.userpass("username", "password")
17
+ # secret.auth.client_token #=> "fdb29070-6379-70c9-ca3a-46152fb66de1"
18
+ #
19
+ # @return [SecretAuth, nil]
20
+ field :auth, load: ->(v) { SecretAuth.decode(v) }
21
+
22
+ # @!attribute [r] data
23
+ # Arbitrary data returned by the secret. The keys returned are dependent
24
+ # upon the request made. For more information on the names of the keys
25
+ # that may be returned, please see the Vault documentation.
26
+ #
27
+ # @example Reading data
28
+ # secret = Vault.auth.token("abcd1234")
29
+ # secret.data[:id] #=> "abcd1234"
30
+ # secret.data[:ttl] #=> 0
31
+ #
32
+ # @return [Hash<Symbol, Object>]
33
+ field :data, freeze: true
34
+
35
+ # @!attribute [r] lease_duration
36
+ # The number of seconds this lease is valid. If this number is 0 or nil,
37
+ # the secret does not expire.
38
+ #
39
+ # @example Getting lease duration
40
+ # secret = Vault.logical.read("secret/foo")
41
+ # secret.lease_duration #=> 2592000 # 30 days
42
+ #
43
+ # @return [Fixnum]
44
+ field :lease_duration
45
+
46
+ # @!attribute [r] lease_id
47
+ # Unique ID for the lease associated with this secret. The `lease_id` is a
48
+ # path and UUID that uniquely represents the secret. This may be used for
49
+ # renewing and revoking the secret, if permitted.
50
+ #
51
+ # @example Getting lease ID
52
+ # secret = Vault.logical.read("postgresql/creds/readonly")
53
+ # secret.lease_id #=> "postgresql/readonly/fdb29070-6379-70c9-ca3a-46152fb66de1"
54
+ #
55
+ # @return [String]
56
+ field :lease_id
57
+
58
+ # @!method [r] renewable?
59
+ # Returns whether this lease is renewable.
60
+ #
61
+ # @example Checking if a lease is renewable
62
+ # secret = Vault.logical.read("secret/foo")
63
+ # secret.renewable? #=> false
64
+ #
65
+ # @return [Boolean]
66
+ field :renewable, as: :renewable?
67
+
68
+ # @!attribute [r] warnings
69
+ # List of warnings returned by the Vault server. These are returned by the
70
+ # Vault server and may include deprecation information, new APIs, or
71
+ # request using the API differently in the future.
72
+ #
73
+ # @example Display warnings
74
+ # result = Vault.logical.read("secret/foo")
75
+ # result.warnings #=> ["This path has been deprecated"]
76
+ #
77
+ # @return [Array<String>, nil]
78
+ field :warnings, freeze: true
79
+
80
+ # @!attribute [r] wrap_info
81
+ # Wrapped information sent with the request (only present in Vault 0.6+).
82
+ # @return [WrapInfo, nil]
83
+ field :wrap_info, load: ->(v) { WrapInfo.decode(v) }
84
+ end
85
+
86
+ # SecretAuth is a struct that contains the information about auth data, if
87
+ # present. This is never returned alone and is usually embededded in a
88
+ # {Secret}.
89
+ class SecretAuth < Response
90
+ # @!attribute [r] accessor
91
+ # Accessor for the token. This is like a `lease_id`, but for a token.
92
+ # @return [String]
93
+ field :accessor
94
+
95
+ # @!attribute [r] client_token
96
+ # The client token for this authentication.
97
+ # @return [String]
98
+ field :client_token
99
+
100
+ # @!attribute [r] lease_duration
101
+ # Number of seconds the token is valid.
102
+ # @return [Fixnum]
103
+ field :lease_duration
104
+
105
+ # @!attribute [r] metadata
106
+ # Arbitrary metadata from the authentication.
107
+ #
108
+ # @example Listing metadata attached to an authentication
109
+ # auth.metadata #=> { :username => "sethvargo" }
110
+ #
111
+ # @return [Hash<Symbol, Object>, nil]
112
+ field :metadata, freeze: true
113
+
114
+ # @!attribute [r] policies
115
+ # List of policies attached to this authentication.
116
+ #
117
+ # @example Listing policies attached to an authentication
118
+ # auth.policies #=> ["default"]
119
+ #
120
+ # @return [Array<String>, nil]
121
+ field :policies, freeze: true
122
+
123
+ # @!attribute [r] renewable
124
+ # Returns whether this authentication is renewable.
125
+ #
126
+ # @example Checking if an authentication is renewable
127
+ # auth.renewable? #=> false
128
+ #
129
+ # @return [Boolean]
130
+ field :renewable, as: :renewable?
131
+ end
132
+
133
+ # WrapInfo is the information returned by a wrapped response. This is almost
134
+ # always embedded as part of a {Secret}.
135
+ class WrapInfo < Response
136
+ # @!attribute [r] token
137
+ # Wrapped response token. This token may be used to unwrap the response.
138
+ # @return [String]
139
+ field :token
140
+
141
+ # @!attribute [r] wrapped_accessor
142
+ # Accessor for the wrapped token. This is like a `lease_id`, but for a token.
143
+ # @return [String]
144
+ field :wrapped_accessor
145
+
146
+ # @!attribute [r] creation_time
147
+ # Date & time when the wrapped token was created
148
+ # @return [Time]
149
+ field :creation_time, load: ->(v) { Time.parse(v) }
150
+
151
+ # @!attribute [r] ttl
152
+ # The TTL on the token returned in seconds.
153
+ # @return [Fixnum]
154
+ field :ttl
155
+ end
156
+ end
@@ -0,0 +1,91 @@
1
+ require "json"
2
+
3
+ module Vault
4
+ class Audit < Response
5
+ # @!attribute [r] description
6
+ # Description of the audit backend.
7
+ # @return [String]
8
+ field :description
9
+
10
+ # @!attribute [r] options
11
+ # Map of options configured to the audit backend.
12
+ # @return [Hash<Symbol, Object>]
13
+ field :options
14
+
15
+ # @!attribute [r] type
16
+ # Name of the audit backend.
17
+ # @return [String]
18
+ field :type
19
+ end
20
+
21
+ class Sys
22
+ # List all audits for the vault.
23
+ #
24
+ # @example
25
+ # Vault.sys.audits #=> { :file => #<Audit> }
26
+ #
27
+ # @return [Hash<Symbol, Audit>]
28
+ def audits
29
+ json = client.get("/v1/sys/audit")
30
+ json = json[:data] if json[:data]
31
+ return Hash[*json.map do |k,v|
32
+ [k.to_s.chomp("/").to_sym, Audit.decode(v)]
33
+ end.flatten]
34
+ end
35
+
36
+ # Enable a particular audit. Note: the +options+ depend heavily on the
37
+ # type of audit being enabled. Please refer to audit-specific documentation
38
+ # for which need to be enabled.
39
+ #
40
+ # @example
41
+ # Vault.sys.enable_audit("/file-audit", "file", "File audit", path: "/path/on/disk") #=> true
42
+ #
43
+ # @param [String] path
44
+ # the path to mount the audit
45
+ # @param [String] type
46
+ # the type of audit to enable
47
+ # @param [String] description
48
+ # a human-friendly description of the audit backend
49
+ # @param [Hash] options
50
+ # audit-specific options
51
+ #
52
+ # @return [true]
53
+ def enable_audit(path, type, description, options = {})
54
+ client.put("/v1/sys/audit/#{encode_path(path)}", JSON.fast_generate(
55
+ type: type,
56
+ description: description,
57
+ options: options,
58
+ ))
59
+ return true
60
+ end
61
+
62
+ # Disable a particular audit. If an audit does not exist, and error will be
63
+ # raised.
64
+ #
65
+ # @param [String] path
66
+ # the path of the audit to disable
67
+ #
68
+ # @return [true]
69
+ def disable_audit(path)
70
+ client.delete("/v1/sys/audit/#{encode_path(path)}")
71
+ return true
72
+ end
73
+
74
+ # Generates a HMAC verifier for a given input.
75
+ #
76
+ # @example
77
+ # Vault.sys.audit_hash("file-audit", "my input") #=> "hmac-sha256:30aa7de18a5e90bbc1063db91e7c387b32b9fa895977eb8c177bbc91e7d7c542"
78
+ #
79
+ # @param [String] path
80
+ # the path of the audit backend
81
+ # @param [String] input
82
+ # the input to generate a HMAC for
83
+ #
84
+ # @return [String]
85
+ def audit_hash(path, input)
86
+ json = client.post("/v1/sys/audit-hash/#{encode_path(path)}", JSON.fast_generate(input: input))
87
+ json = json[:data] if json[:data]
88
+ json[:hash]
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,116 @@
1
+ require "json"
2
+
3
+ module Vault
4
+ class Auth < Response
5
+ # @!attribute [r] description
6
+ # Description of the auth backend.
7
+ # @return [String]
8
+ field :description
9
+
10
+ # @!attribute [r] type
11
+ # Name of the auth backend.
12
+ # @return [String]
13
+ field :type
14
+ end
15
+
16
+ class AuthConfig < Response
17
+ # @!attribute [r] default_lease_ttl
18
+ # The default time-to-live.
19
+ # @return [String]
20
+ field :default_lease_ttl
21
+
22
+ # @!attribute [r] max_lease_ttl
23
+ # The maximum time-to-live.
24
+ # @return [String]
25
+ field :max_lease_ttl
26
+ end
27
+
28
+ class Sys
29
+ # List all auths in Vault.
30
+ #
31
+ # @example
32
+ # Vault.sys.auths #=> {:token => #<Vault::Auth type="token", description="token based credentials">}
33
+ #
34
+ # @return [Hash<Symbol, Auth>]
35
+ def auths
36
+ json = client.get("/v1/sys/auth")
37
+ json = json[:data] if json[:data]
38
+ return Hash[*json.map do |k,v|
39
+ [k.to_s.chomp("/").to_sym, Auth.decode(v)]
40
+ end.flatten]
41
+ end
42
+
43
+ # Enable a particular authentication at the given path.
44
+ #
45
+ # @example
46
+ # Vault.sys.enable_auth("github", "github") #=> true
47
+ #
48
+ # @param [String] path
49
+ # the path to mount the auth
50
+ # @param [String] type
51
+ # the type of authentication
52
+ # @param [String] description
53
+ # a human-friendly description (optional)
54
+ #
55
+ # @return [true]
56
+ def enable_auth(path, type, description = nil)
57
+ payload = { type: type }
58
+ payload[:description] = description if !description.nil?
59
+
60
+ client.post("/v1/sys/auth/#{encode_path(path)}", JSON.fast_generate(payload))
61
+ return true
62
+ end
63
+
64
+ # Disable a particular authentication at the given path. If not auth
65
+ # exists at that path, an error will be raised.
66
+ #
67
+ # @example
68
+ # Vault.sys.disable_auth("github") #=> true
69
+ #
70
+ # @param [String] path
71
+ # the path to disable
72
+ #
73
+ # @return [true]
74
+ def disable_auth(path)
75
+ client.delete("/v1/sys/auth/#{encode_path(path)}")
76
+ return true
77
+ end
78
+
79
+ # Read the given auth path's configuration.
80
+ #
81
+ # @example
82
+ # Vault.sys.auth_tune("github") #=> #<Vault::AuthConfig "default_lease_ttl"=3600, "max_lease_ttl"=7200>
83
+ #
84
+ # @param [String] path
85
+ # the path to retrieve configuration for
86
+ #
87
+ # @return [AuthConfig]
88
+ # configuration of the given auth path
89
+ def auth_tune(path)
90
+ json = client.get("/v1/sys/auth/#{encode_path(path)}/tune")
91
+ return AuthConfig.decode(json)
92
+ rescue HTTPError => e
93
+ return nil if e.code == 404
94
+ raise
95
+ end
96
+
97
+ # Write the given auth path's configuration.
98
+ #
99
+ # @example
100
+ # Vault.sys.auth_tune("github", "default_lease_ttl" => 600, "max_lease_ttl" => 1200 ) #=> true
101
+ #
102
+ # @param [String] path
103
+ # the path to retrieve configuration for
104
+ #
105
+ # @return [AuthConfig]
106
+ # configuration of the given auth path
107
+ def put_auth_tune(path, config = {})
108
+ json = client.put("/v1/sys/auth/#{encode_path(path)}/tune", JSON.fast_generate(config))
109
+ if json.nil?
110
+ return true
111
+ else
112
+ return Secret.decode(json)
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,63 @@
1
+ require "json"
2
+
3
+ module Vault
4
+ class HealthStatus < Response
5
+ # @!attribute [r] initialized
6
+ # Whether the Vault server is Initialized.
7
+ # @return [Boolean]
8
+ field :initialized, as: :initialized?
9
+
10
+ # @!attribute [r] sealed
11
+ # Whether the Vault server is Sealed.
12
+ # @return [Boolean]
13
+ field :sealed, as: :sealed?
14
+
15
+ # @!attribute [r] standby
16
+ # Whether the Vault server is in Standby mode.
17
+ # @return [Boolean]
18
+ field :standby, as: :standby?
19
+
20
+ # @!attribute [r] replication_performance_mode
21
+ # Verbose description of DR mode (added in 0.9.2)
22
+ # @return [String]
23
+ field :replication_performance_mode
24
+
25
+ # @!attribute [r] replication_dr_mode
26
+ # Verbose description of DR mode (added in 0.9.2)
27
+ # @return [String]
28
+ field :replication_dr_mode
29
+
30
+ # @!attribute [r] server_time_utc
31
+ # Server time in Unix seconds, UTC
32
+ # @return [Fixnum]
33
+ field :server_time_utc
34
+
35
+ # @!attribute [r] version
36
+ # Server Vault version string (added in 0.6.1)
37
+ # @return [String]
38
+ field :version
39
+
40
+ # @!attribute [r] cluster_name
41
+ # Server cluster name
42
+ # @return [String]
43
+ field :cluster_name
44
+
45
+ # @!attribute [r] cluster_id
46
+ # Server cluster UUID
47
+ # @return [String]
48
+ field :cluster_id
49
+ end
50
+
51
+ class Sys
52
+ # Show the health status for this vault.
53
+ #
54
+ # @example
55
+ # Vault.sys.health_status #=> #Vault::HealthStatus @initialized=true, @sealed=false, @standby=false, @replication_performance_mode="disabled", @replication_dr_mode="disabled", @server_time_utc=1519776728, @version="0.9.3", @cluster_name="vault-cluster-997f514e", @cluster_id="c2dad70a-6d88-a06d-69f6-9ae7f5485998">
56
+ #
57
+ # @return [HealthStatus]
58
+ def health_status
59
+ json = client.get("/v1/sys/health", {:sealedcode => 200, :uninitcode => 200, :standbycode => 200})
60
+ return HealthStatus.decode(json)
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,83 @@
1
+ require "json"
2
+
3
+ module Vault
4
+ class InitResponse < Response
5
+ # @!attribute [r] keys
6
+ # List of unseal keys.
7
+ # @return [Array<String>]
8
+ field :keys
9
+
10
+ # @!attribute [r] keys_base64
11
+ # List of unseal keys, base64-encoded
12
+ # @return [Array<String>]
13
+ field :keys_base64
14
+
15
+ # @!attribute [r] root_token
16
+ # Initial root token.
17
+ # @return [String]
18
+ field :root_token
19
+ end
20
+
21
+ class InitStatus < Response
22
+ # @!method initialized?
23
+ # Returns whether the Vault server is initialized.
24
+ # @return [Boolean]
25
+ field :initialized, as: :initialized?
26
+ end
27
+
28
+ class Sys
29
+ # Show the initialization status for this vault.
30
+ #
31
+ # @example
32
+ # Vault.sys.init_status #=> #<Vault::InitStatus initialized=true>
33
+ #
34
+ # @return [InitStatus]
35
+ def init_status
36
+ json = client.get("/v1/sys/init")
37
+ return InitStatus.decode(json)
38
+ end
39
+
40
+ # Initialize a new vault.
41
+ #
42
+ # @example
43
+ # Vault.sys.init #=> #<Vault::InitResponse keys=["..."] root_token="...">
44
+ #
45
+ # @param [Hash] options
46
+ # the list of init options
47
+ #
48
+ # @option options [String] :root_token_pgp_key
49
+ # optional base64-encoded PGP public key used to encrypt the initial root
50
+ # token.
51
+ # @option options [Fixnum] :secret_shares
52
+ # the number of shares
53
+ # @option options [Fixnum] :secret_threshold
54
+ # the number of keys needed to unlock
55
+ # @option options [Array<String>] :pgp_keys
56
+ # an optional Array of base64-encoded PGP public keys to encrypt sharees
57
+ # @option options [Fixnum] :stored_shares
58
+ # the number of shares that should be encrypted by the HSM for
59
+ # auto-unsealing
60
+ # @option options [Fixnum] :recovery_shares
61
+ # the number of shares to split the recovery key into
62
+ # @option options [Fixnum] :recovery_threshold
63
+ # the number of shares required to reconstruct the recovery key
64
+ # @option options [Array<String>] :recovery_pgp_keys
65
+ # an array of PGP public keys used to encrypt the output for the recovery
66
+ # keys
67
+ #
68
+ # @return [InitResponse]
69
+ def init(options = {})
70
+ json = client.put("/v1/sys/init", JSON.fast_generate(
71
+ root_token_pgp_key: options.fetch(:root_token_pgp_key, nil),
72
+ secret_shares: options.fetch(:secret_shares, options.fetch(:shares, 5)),
73
+ secret_threshold: options.fetch(:secret_threshold, options.fetch(:threshold, 3)),
74
+ pgp_keys: options.fetch(:pgp_keys, nil),
75
+ stored_shares: options.fetch(:stored_shares, nil),
76
+ recovery_shares: options.fetch(:recovery_shares, nil),
77
+ recovery_threshold: options.fetch(:recovery_threshold, nil),
78
+ recovery_pgp_keys: options.fetch(:recovery_pgp_keys, nil),
79
+ ))
80
+ return InitResponse.decode(json)
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,48 @@
1
+ module Vault
2
+ class LeaderStatus < Response
3
+ # @!method ha_enabled?
4
+ # Returns whether the high-availability mode is enabled.
5
+ # @return [Boolean]
6
+ field :ha_enabled, as: :ha_enabled?
7
+
8
+ # @!method leader?
9
+ # Returns whether the Vault server queried is the leader.
10
+ # @return [Boolean]
11
+ field :is_self, as: :leader?
12
+
13
+ # @!attribute [r] address
14
+ # URL where the server is running.
15
+ # @return [String]
16
+ field :leader_address, as: :address
17
+
18
+ # @deprecated Use {#ha_enabled?} instead
19
+ def ha?; ha_enabled?; end
20
+
21
+ # @deprecated Use {#leader?} instead
22
+ def is_leader?; leader?; end
23
+
24
+ # @deprecated Use {#leader?} instead
25
+ def is_self?; leader?; end
26
+
27
+ # @deprecated Use {#leader?} instead
28
+ def self?; leader?; end
29
+ end
30
+
31
+ class Sys
32
+ # Determine the leader status for this vault.
33
+ #
34
+ # @example
35
+ # Vault.sys.leader #=> #<Vault::LeaderStatus ha_enabled=false, is_self=false, leader_address="">
36
+ #
37
+ # @return [LeaderStatus]
38
+ def leader
39
+ json = client.get("/v1/sys/leader")
40
+ return LeaderStatus.decode(json)
41
+ end
42
+
43
+ def step_down
44
+ client.put("/v1/sys/step-down", nil)
45
+ return true
46
+ end
47
+ end
48
+ end