Pirkka Esko Pirkka Esko - 6 months ago 16
Ruby Question

How to create publicly readable object store containers with ruby openstack gem?

I have tried to create publicly readable openstack object store containers like this:

os = OpenStack::Connection.create(...)
container = os.create_container(container_name)
container.set_metadata({'X-Container-Read' => '.r:*'})


Using my code above, the newly created containers are private.

What is the correct way to create containers with public read permissions with the ruby openstack gem?

Answer

You can try the following way.

You can redfine the create_container method

then

class MyStack < OpenStack::Swift::Connection
  def create_container(containername)
   super
   @connection.req("PUT", path, {:headers=>{"Content-Length"=>"0", "X-Container-Read" => ".r:*", "X-Container-Write" => ".r:*}})
   OpenStack::Swift::Container.new(self, containername)
 end
end

These "X-Container-Read" => ".r:*", "X-Container-Write" => ".r:*" header value you need to set.

or

container.set_metadata({"X-Container-Read" => ".r:*", "X-Container-Write" => ".r:*"})