lib/conjur/variable.rb in conjur-api-4.19.1 vs lib/conjur/variable.rb in conjur-api-4.20.0
- old
+ new
@@ -1,7 +1,7 @@
#
-# Copyright (C) 2013 Conjur Inc
+# Copyright (C) 2013-2016 Conjur Inc
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
@@ -203,7 +203,30 @@
def value(version = nil)
url = 'value'
url << "?version=#{version}" if version
self[url].get.body
end
+
+ # Set the variable to expire after the given interval. The
+ # interval can either be an ISO8601 duration or it can the number
+ # of seconds for which the variable should be valid. Once a
+ # variable has expired, its value will no longer be retrievable.
+ #
+ # You must have the **`'update'`** permission on a variable to call this method.
+ #
+ # @example Use an ISO8601 duration to set the expiration for a variable to tomorrow
+ # var = api.variable 'my-secret'
+ # var.expires_in "P1D"
+ #
+ # @example Use ActiveSupport to set the expiration for a variable to tomorrow
+ # require 'active_support/all'
+ # var = api.variable 'my-secret'
+ # var.expires_in 1.day
+ # @param interval a String containing an ISO8601 duration, otherwise the number of seconds before the variable xpires
+ # @return [Hash] description of the variable's expiration, including the (Conjur server) time when it expires
+ def expires_in interval
+ duration = interval.respond_to?(:to_str) ? interval : "PT#{interval.to_i}S"
+ JSON::parse(self['expiration'].post(duration: duration).body)
+ end
+
end
-end
\ No newline at end of file
+end