Class: Vault::AppRole
Instance Attribute Summary
Attributes inherited from Request
Instance Method Summary collapse
-
#create_secret_id(role_name, options = {}) ⇒ true
Generates and issues a new SecretID on an existing AppRole.
-
#delete_role(name) ⇒ Object
Deletes the AppRole with the given name.
-
#role(name) ⇒ Secret?
Gets the AppRole by the given name.
-
#role_id(name) ⇒ Secret?
Reads the RoleID of an existing AppRole.
-
#roles(options = {}) ⇒ Array<String>
Gets the list of AppRoles in vault auth backend.
-
#secret_id(role_name, secret_id) ⇒ Secret?
Reads out the properties of a SecretID assigned to an AppRole.
-
#secret_id_accessors(role_name, options = {}) ⇒ Array<String>
Lists the accessors of all the SecretIDs issued against the AppRole.
-
#set_role(name, options = {}) ⇒ true
Creates a new AppRole or update an existing AppRole with the given name and attributes.
-
#set_role_id(name, role_id) ⇒ true
Updates the RoleID of an existing AppRole to a custom value.
Methods inherited from Request
Methods included from EncodePath
Constructor Details
This class inherits a constructor from Vault::Request
Instance Method Details
#create_secret_id(role_name, options = {}) ⇒ true
Generates and issues a new SecretID on an existing AppRole.
160 161 162 163 164 165 166 167 168 |
# File 'lib/vault/api/approle.rb', line 160 def create_secret_id(role_name, = {}) headers = extract_headers!() if [:secret_id] json = client.post("/v1/auth/approle/role/#{encode_path(role_name)}/custom-secret-id", JSON.fast_generate(), headers) else json = client.post("/v1/auth/approle/role/#{encode_path(role_name)}/secret-id", JSON.fast_generate(), headers) end return Secret.decode(json) end |
#delete_role(name) ⇒ Object
Deletes the AppRole with the given name. If an AppRole does not exist, vault will not return an error.
130 131 132 133 |
# File 'lib/vault/api/approle.rb', line 130 def delete_role(name) client.delete("/v1/auth/approle/role/#{encode_path(name)}") return true end |
#role(name) ⇒ Secret?
Gets the AppRole by the given name. If an AppRole does not exist by that name, nil
is returned.
72 73 74 75 76 77 78 |
# File 'lib/vault/api/approle.rb', line 72 def role(name) json = client.get("/v1/auth/approle/role/#{encode_path(name)}") return Secret.decode(json) rescue HTTPError => e return nil if e.code == 404 raise end |
#role_id(name) ⇒ Secret?
Reads the RoleID of an existing AppRole. If an AppRole does not exist by that name, nil
is returned.
102 103 104 105 106 107 108 |
# File 'lib/vault/api/approle.rb', line 102 def role_id(name) json = client.get("/v1/auth/approle/role/#{encode_path(name)}/role-id") return Secret.decode(json).data[:role_id] rescue HTTPError => e return nil if e.code == 404 raise end |
#roles(options = {}) ⇒ Array<String>
Gets the list of AppRoles in vault auth backend.
86 87 88 89 90 91 92 93 |
# File 'lib/vault/api/approle.rb', line 86 def roles( = {}) headers = extract_headers!() json = client.list("/v1/auth/approle/role", , headers) return Secret.decode(json).data[:keys] || [] rescue HTTPError => e return [] if e.code == 404 raise end |
#secret_id(role_name, secret_id) ⇒ Secret?
Reads out the properties of a SecretID assigned to an AppRole. If the specified SecretID don’t exist, nil
is returned.
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/vault/api/approle.rb', line 182 def secret_id(role_name, secret_id) opts = { secret_id: secret_id } json = client.post("/v1/auth/approle/role/#{encode_path(role_name)}/secret-id/lookup", JSON.fast_generate(opts), {}) return nil unless json return Secret.decode(json) rescue HTTPError => e if e.code == 404 || e.code == 405 begin json = client.get("/v1/auth/approle/role/#{encode_path(role_name)}/secret-id/#{encode_path(secret_id)}") return Secret.decode(json) rescue HTTPError => e return nil if e.code == 404 raise e end end raise end |
#secret_id_accessors(role_name, options = {}) ⇒ Array<String>
Lists the accessors of all the SecretIDs issued against the AppRole. This includes the accessors for “custom” SecretIDs as well. If there are no SecretIDs against this role, an empty array will be returned.
209 210 211 212 213 214 215 216 |
# File 'lib/vault/api/approle.rb', line 209 def secret_id_accessors(role_name, = {}) headers = extract_headers!() json = client.list("/v1/auth/approle/role/#{encode_path(role_name)}/secret-id", , headers) return Secret.decode(json).data[:keys] || [] rescue HTTPError => e return [] if e.code == 404 raise end |
#set_role(name, options = {}) ⇒ true
Creates a new AppRole or update an existing AppRole with the given name and attributes.
59 60 61 62 63 |
# File 'lib/vault/api/approle.rb', line 59 def set_role(name, = {}) headers = extract_headers!() client.post("/v1/auth/approle/role/#{encode_path(name)}", JSON.fast_generate(), headers) return true end |
#set_role_id(name, role_id) ⇒ true
Updates the RoleID of an existing AppRole to a custom value.
116 117 118 119 120 |
# File 'lib/vault/api/approle.rb', line 116 def set_role_id(name, role_id) = { role_id: role_id } client.post("/v1/auth/approle/role/#{encode_path(name)}/role-id", JSON.fast_generate()) return true end |