Class: OpenstackBridge::Swift

Inherits:
Struct
  • Object
show all
Defined in:
lib/openstack_bridge/swift.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSwift

Returns a new instance of Swift.



5
6
7
8
# File 'lib/openstack_bridge/swift.rb', line 5

def initialize(*)
  super
  self.authentication_response = OpenstackBridge::Authentication.new(host, user, password, tenant).response
end

Instance Attribute Details

#authentication_responseObject

Returns the value of attribute authentication_response.



3
4
5
# File 'lib/openstack_bridge/swift.rb', line 3

def authentication_response
  @authentication_response
end

#containerObject

Returns the value of attribute container

Returns:

  • (Object)

    the current value of container



2
3
4
# File 'lib/openstack_bridge/swift.rb', line 2

def container
  @container
end

#hostObject

Returns the value of attribute host

Returns:

  • (Object)

    the current value of host



2
3
4
# File 'lib/openstack_bridge/swift.rb', line 2

def host
  @host
end

#passwordObject

Returns the value of attribute password

Returns:

  • (Object)

    the current value of password



2
3
4
# File 'lib/openstack_bridge/swift.rb', line 2

def password
  @password
end

#tenantObject

Returns the value of attribute tenant

Returns:

  • (Object)

    the current value of tenant



2
3
4
# File 'lib/openstack_bridge/swift.rb', line 2

def tenant
  @tenant
end

#userObject

Returns the value of attribute user

Returns:

  • (Object)

    the current value of user



2
3
4
# File 'lib/openstack_bridge/swift.rb', line 2

def user
  @user
end

Instance Method Details

#create(path, content) ⇒ Object



34
35
36
# File 'lib/openstack_bridge/swift.rb', line 34

def create(path, content)
  request(:put, file_path(path), content)
end

#delete(path) ⇒ Object



30
31
32
# File 'lib/openstack_bridge/swift.rb', line 30

def delete(path)
  request(:delete, file_path(path))
end

#end_pointObject



14
15
16
# File 'lib/openstack_bridge/swift.rb', line 14

def end_point
  self.authentication_response['access']['serviceCatalog'].detect {|s| s['name'] == 'swift'}['endpoints'].first['publicURL']
end

#exists?(path) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/openstack_bridge/swift.rb', line 22

def exists?(path)
  request(:head, file_path(path)).code == 200
end

#file_path(path) ⇒ Object



18
19
20
# File 'lib/openstack_bridge/swift.rb', line 18

def file_path(path)
  "#{end_point}/#{container}/#{path}"
end

#read(path) ⇒ Object



26
27
28
# File 'lib/openstack_bridge/swift.rb', line 26

def read(path)
  request(:get, file_path(path)).raw_body
end

#request(method, path, params = {}.to_json, httpclient = false) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/openstack_bridge/swift.rb', line 39

def request(method, path, params={}.to_json, httpclient = false)
  request = HTTPI::Request.new
  request.url = path
  request.body = params
  request.headers['Content-Type'] = 'application/json'
  request.headers['X-Auth-Token'] = token
  HTTPI.send(method, request, (httpclient ? :httpclient : :curb))
end

#tokenObject



10
11
12
# File 'lib/openstack_bridge/swift.rb', line 10

def token
  self.authentication_response['access']['token']['id']
end