Skip to content

Instantly share code, notes, and snippets.

@bradgignac
Last active August 29, 2015 14:01
Show Gist options
  • Save bradgignac/1dcb1561973d3abd3ecf to your computer and use it in GitHub Desktop.
Save bradgignac/1dcb1561973d3abd3ecf to your computer and use it in GitHub Desktop.
Enable CORS with Fog
gem install fog
ruby enable-cors.rb RACKSPACE_USERNAME RACKSPACE_API_KEY CONTAINER_NAME
require 'fog'
username, api_key, container = ARGV
connection = Fog::Storage.new(provider: 'Rackspace', rackspace_username: username, rackspace_api_key: api_key)
container = connection.directories.get(container)
puts "Enabling CORS for #{container}..."
container.files.each do |file|
begin
print " #{file.key}... "
file.access_control_allow_origin = '*'
file.save
puts "Complete!"
rescue => e
puts "Failed!"
puts "Script Error: #{e}"
break
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment