lib/conjur/variable.rb in conjur-api-5.0.0 vs lib/conjur/variable.rb in conjur-api-5.1.0
- old
+ new
@@ -93,11 +93,11 @@
# model.
#
# @note this is **not** the same as the `kind` part of a qualified Conjur id.
# @return [String] a string representing the kind of secret.
def kind
- annotation_value 'conjur/kind' || "secret"
+ parser_for(:variable_kind, variable_attributes) || "secret"
end
# The MIME Type of the variable's value.
#
# You must have the **`'read'`** permission on a variable to call this method.
@@ -107,11 +107,11 @@
# so if you plan on accessing the variable in a way that depends on a correct `Content-Type` header
# you should make sure to store appropriate data for the mime type in all versions.
#
# @return [String] a MIME type, such as `'text/plain'` or `'application/octet-stream'`.
def mime_type
- annotation_value 'conjur/mime_type' || "text/plain"
+ parser_for(:variable_mime_type, variable_attributes) || "text/plain"
end
# Add a new value to the variable.
#
# You must have the **`'update'`** permission on a variable to call this method.
@@ -128,11 +128,16 @@
def add_value value
log do |logger|
logger << "Adding a value to variable #{id}"
end
invalidate do
- core_resource['secrets'][id.to_url_path].post value
+ route = url_for(:secrets_add, credentials, id)
+ Conjur.configuration.version_logic lambda {
+ route.post value: value
+ }, lambda {
+ route.post value
+ }
end
end
# Return the number of versions of the variable.
#
@@ -143,16 +148,20 @@
# var.add_value "something new"
# var.version_count # => 5
#
# @return [Integer] the number of versions
def version_count
- secrets = attributes['secrets']
- if secrets.empty?
- 0
- else
- secrets.last['version']
- end
+ Conjur.configuration.version_logic lambda {
+ JSON.parse(url_for(:variable, credentials, id).get)['version_count']
+ }, lambda {
+ secrets = attributes['secrets']
+ if secrets.empty?
+ 0
+ else
+ secrets.last['version']
+ end
+ }
end
# Return the version of a variable.
#
# You must have the **`'execute'`** permission on a variable to call this method.
@@ -185,9 +194,15 @@
# @param options [Hash]
# @option options [Boolean, false] :show_expired show value even if variable has expired
# @return [String] the value of the variable
def value version = nil, options = {}
options['version'] = version if version
- core_resource['secrets'][id.to_url_path][options_querystring options].get.body
+ url_for(:secrets_value, credentials, id, options).get.body
end
- end
+
+ private
+
+ def variable_attributes
+ @variable_attributes ||= url_for(:variable_attributes, credentials, self, id)
+ end
+ end
end