Class: Cerberus::CerberusClient
- Inherits:
-
Object
- Object
- Cerberus::CerberusClient
- Defined in:
- lib/cerberus/cerberus_client.rb
Overview
Client for interacting with the Cerberus API
Constant Summary collapse
- SECRET_PATH_PREFIX =
relative path to the Cerberus secrets API
"/v1/secret/"- SECRET_MAP_DATA_KEY =
CERBERUS_LIST_DATA_KEY = "data"
- CERBERUS_TOKEN_HEADER_KEY =
'X-Vault-Token'- CERBERUS_ERRORS_KEY =
"errors"- CERBERUS_PERMISSION_DENIED_ERR =
"permission denied"- CERBERUS_LIST_KEYS_KEY =
"keys"- CERBERUS_LIST_PARAM_KEY =
"list"- SLASH =
"/"
Instance Attribute Summary collapse
-
#cerberus_base_url ⇒ Object
readonly
Returns the value of attribute cerberus_base_url.
-
#credentials_provider ⇒ Object
readonly
Returns the value of attribute credentials_provider.
Instance Method Summary collapse
-
#initialize(cerberus_url_resolver, credentials_provider_chain) ⇒ CerberusClient
constructor
Init with the base URL for cerberus.
-
#list(path) ⇒ Object
Returns a list of key names at the specified location.
-
#read(path) ⇒ Object
Read operation for a specified path.
Constructor Details
#initialize(cerberus_url_resolver, credentials_provider_chain) ⇒ CerberusClient
Init with the base URL for cerberus
33 34 35 36 37 38 39 40 |
# File 'lib/cerberus/cerberus_client.rb', line 33 def initialize(cerberus_url_resolver, credentials_provider_chain) require 'net/https' @cerberus_base_url = CerberusUtils::get_url_from_resolver(cerberus_url_resolver) @credentials_provider = credentials_provider_chain.get_credentials_provider end |
Instance Attribute Details
#cerberus_base_url ⇒ Object (readonly)
Returns the value of attribute cerberus_base_url.
27 28 29 |
# File 'lib/cerberus/cerberus_client.rb', line 27 def cerberus_base_url @cerberus_base_url end |
#credentials_provider ⇒ Object (readonly)
Returns the value of attribute credentials_provider.
28 29 30 |
# File 'lib/cerberus/cerberus_client.rb', line 28 def credentials_provider @credentials_provider end |
Instance Method Details
#list(path) ⇒ Object
Returns a list of key names at the specified location. Folders are suffixed with /. The input must be a folder; list on a file will return nil
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/cerberus/cerberus_client.rb', line 61 def list(path) begin response = read_value_from_cerberus(SECRET_PATH_PREFIX + path + "?list=true") CerberusUtils::Log.instance.debug("CerberusClient::list(#{path}) HTTP response: #{response.code}, #{response.}") json_response_body = JSON.parse(response.body) pathList = json_response_body[CERBERUS_LIST_DATA_KEY][CERBERUS_LIST_KEYS_KEY] CerberusUtils::Log.instance.debug("CerberusClient::list returning #{pathList.join(", ")} ") pathList rescue => ex # check to see if we threw the Http error with a response object response = (ex.instance_of?(Cerberus::Exception::HttpError)) ? ex.response : nil if(!response.nil? && response.code.to_i == 404) return nil end CerberusUtils::Log.instance.error("CerberusClient::list(#{path}) unhandled exception trying to read: #{ex.}") raise ex end end |
#read(path) ⇒ Object
Read operation for a specified path.
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/cerberus/cerberus_client.rb', line 45 def read(path) begin response = read_value_from_cerberus(SECRET_PATH_PREFIX + path) CerberusUtils::Log.instance.debug("CerberusClient::read(path) HTTP response: #{response.code}, #{response.}") response.body rescue => ex CerberusUtils::Log.instance.error("CerberusClient::read(#{path}) unhandled exception trying to read: #{ex.}") raise ex end end |