lib/cloudfiles/container.rb in cloudfiles-1.4.2 vs lib/cloudfiles/container.rb in cloudfiles-1.4.3
- old
+ new
@@ -21,10 +21,16 @@
# CDN container URL (if container if public)
attr_reader :cdn_url
# The parent CloudFiles::Connection object for this container
attr_reader :connection
+
+ # The container ACL on the User Agent
+ attr_reader :user_agent_acl
+
+ # The container ACL on the site Referrer
+ attr_reader :referrer_acl
# Retrieves an existing CloudFiles::Container object tied to the current CloudFiles::Connection. If the requested
# container does not exist, it will raise a NoSuchContainerException.
#
# Will likely not be called directly, instead use connection.container('container_name') to retrieve the object.
@@ -62,12 +68,14 @@
@count = response["x-container-object-count"].to_i
# Get the CDN-related details
response = self.connection.cfreq("HEAD",@cdnmgmthost,@cdnmgmtpath,@cdnmgmtport,@cdnmgmtscheme)
@cdn_enabled = ((response["x-cdn-enabled"] || "").downcase == "true") ? true : false
- @cdn_ttl = @cdn_enabled ? response["x-ttl"] : false
+ @cdn_ttl = @cdn_enabled ? response["x-ttl"].to_i : false
@cdn_url = @cdn_enabled ? response["x-cdn-uri"] : false
+ @user_agent_acl = response["x-user-agent-acl"]
+ @referrer_acl = response["x-referrer-acl"]
if @cdn_enabled
@cdn_log = response["x-log-retention"] == "False" ? false : true
else
@cdn_log = false
end
@@ -236,21 +244,42 @@
end
# Makes a container publicly available via the Cloud Files CDN and returns true upon success. Throws NoSuchContainerException
# if the container doesn't exist or if the request fails.
#
- # Takes an optional argument, which is the CDN cache TTL in seconds (default 86400 seconds or 1 day, maximum 259200 or 3 days)
+ # Takes an optional hash of options, including:
#
- # container.make_public(432000)
+ # :ttl, which is the CDN cache TTL in seconds (default 86400 seconds or 1 day, minimum 3600 or 1 hour, maximum 259200 or 3 days)
+ #
+ # :user_agent_acl, a Perl-compatible regular expression limiting access to this container to user agents matching the given regular expression
+ #
+ # :referrer_acl, a Perl-compatible regular expression limiting access to this container to HTTP referral URLs matching the given regular expression
+ #
+ # container.make_public(:ttl => 8900, :user_agent_acl => "/Mozilla/", :referrer_acl => "/^http://rackspace.com")
# => true
- def make_public(ttl = 86400)
+ def make_public(options = {:ttl => 86400})
+ if options.is_a?(Fixnum)
+ print "DEPRECATED: make_public takes a hash of options now, instead of a TTL number"
+ ttl = options
+ options = {:ttl => ttl}
+ end
+ if options[:ttl] < 3600
+ options[:ttl] = 3600
+ end
+ if options[:ttl] > 259200
+ options[:ttl] = 259200
+ end
+
response = self.connection.cfreq("PUT",@cdnmgmthost,@cdnmgmtpath,@cdnmgmtport,@cdnmgmtscheme)
raise NoSuchContainerException, "Container #{@name} does not exist" unless (response.code == "201" || response.code == "202")
- headers = { "X-TTL" => ttl.to_s , "X-CDN-Enabled" => "True" }
+ headers = { "X-TTL" => options[:ttl].to_s , "X-CDN-Enabled" => "True" }
+ headers["X-User-Agent-ACL"] = options[:user_agent_acl] if options[:user_agent_acl]
+ headers["X-Referrer-ACL"] = options[:referrer_acl] if options[:referrer_acl]
response = self.connection.cfreq("POST",@cdnmgmthost,@cdnmgmtpath,@cdnmgmtport,@cdnmgmtscheme,headers)
raise NoSuchContainerException, "Container #{@name} does not exist" unless (response.code == "201" || response.code == "202")
+ populate
true
end
# Makes a container private and returns true upon success. Throws NoSuchContainerException
# if the container doesn't exist or if the request fails.
@@ -261,9 +290,10 @@
# => true
def make_private
headers = { "X-CDN-Enabled" => "False" }
response = self.connection.cfreq("POST",@cdnmgmthost,@cdnmgmtpath,@cdnmgmtport,@cdnmgmtscheme,headers)
raise NoSuchContainerException, "Container #{@name} does not exist" unless (response.code == "201" || response.code == "202")
+ populate
true
end
def to_s # :nodoc:
@name