Class: SwiftStorage::Container

Inherits:
Node
  • Object
show all
Defined in:
lib/swift_storage/container.rb

Constant Summary

Constants included from Headers

Headers::ACCOUNT_TEMP_URL_KEY, Headers::AUTH_KEY, Headers::AUTH_TOKEN, Headers::AUTH_USER, Headers::CACHE_CONTROL, Headers::CONNECTION, Headers::CONTAINER_READ, Headers::CONTAINER_WRITE, Headers::CONTENT_DISPOSITION, Headers::CONTENT_TYPE, Headers::DELETE_AFTER, Headers::DELETE_AT, Headers::DESTINATION, Headers::EXPIRES, Headers::OBJECT_MANIFEST, Headers::PROXY_CONNECTION, Headers::STORAGE_TOKEN, Headers::STORAGE_URL

Instance Attribute Summary

Attributes inherited from Node

#name, #parent

Instance Method Summary collapse

Methods inherited from Node

#clear_cache, #delete, #delete_if_exists, #exists?, #get_lines, #headers, #initialize, #metadata, #request, #service, #to_s

Methods included from Utils

#hmac, #sig_to_hex, #struct

Constructor Details

This class inherits a constructor from SwiftStorage::Node

Instance Method Details

#aclStruct

Read the container meta data

Returns:

  • (Struct)

    A struct with read and write ACL, each entry contains an Array of String.



54
55
56
57
58
# File 'lib/swift_storage/container.rb', line 54

def acl
  r = headers.read.split(',') rescue nil
  w = headers.write.split(',') rescue nil
  struct(:read => r, :write => w)
end

#createObject

Create the container



20
21
22
# File 'lib/swift_storage/container.rb', line 20

def create
  request(relative_path, :method => :put)
end

#objectsSwiftStorage::ObjectCollection

Returns the object collection for this container

Returns:



14
15
16
# File 'lib/swift_storage/container.rb', line 14

def objects
  @objects ||= SwiftStorage::ObjectCollection.new(self)
end

#relative_pathObject



5
6
7
# File 'lib/swift_storage/container.rb', line 5

def relative_path
  name
end

#write(write_acl: nil, read_acl: nil) ⇒ Object

Note:

This overrides all ACL set on the container.

Write the container meta data

Each ACL is a string in the following format:

  • team:jon give access to user "jon" of account "team"

Parameters:

  • read_acl (Array<String>) (defaults to: nil)

    An array of ACL.

  • write_acl (Array<String>) (defaults to: nil)

    An array of ACL.



38
39
40
41
42
43
44
45
46
47
# File 'lib/swift_storage/container.rb', line 38

def write(write_acl: nil, read_acl: nil)
  h = {}
  read_acl = read_acl.join(',') if read_acl.respond_to?(:to_ary)
  write_acl = write_acl.join(',') if write_acl.respond_to?(:to_ary)

  h[CONTAINER_READ] = read_acl
  h[CONTAINER_WRITE] = write_acl

  request(relative_path, :method => :post, :headers => h)
end