class Fog::Storage::OracleCloud::Real
Public Class Methods
new(options={})
click to toggle source
# File lib/fog/oraclecloud/storage.rb, line 19 def initialize(options={}) @username = options[:oracle_username] @password = options[:oracle_password] @identity_domain = options[:oracle_domain] @api_endpoint = options[:oracle_storage_api] @connection = Fog::XML::Connection.new(@api_endpoint) # Get authentication token authenticate end
Public Instance Methods
authenticate()
click to toggle source
# File lib/fog/oraclecloud/storage.rb, line 31 def authenticate() begin Fog::Logger.debug("Sending #{params[:body].to_s} to #{params[:path]}") response = @connection.request({ :expects => 200, :method => 'GET', :path => "auth/v1.0", :headers => { 'X-Storage-User' => "Storage-#{@identity_domain}:#{@username}", 'X-Storage-Pass' => @password } }) rescue Excon::Errors::HTTPStatusError => error error end if response.nil? || !response.headers['X-Auth-Token'] then raise Error.new('Could not authenticate to Storage Cloud Service. Check your athentication details in your config') end @auth_token = response.headers['X-Auth-Token'] end
create_container(name)
click to toggle source
# File lib/fog/oraclecloud/requests/storage/create_container.rb, line 8 def create_container(name) request({ :method => 'PUT', :expects => [201,202], :path => "/v1/Storage-#{@identity_domain}/#{name}" }, false) end
delete_container(name)
click to toggle source
# File lib/fog/oraclecloud/requests/storage/delete_container.rb, line 5 def delete_container (name) request( :method => 'DELETE', :expects => 204, :path => "/v1/Storage-#{@identity_domain}/#{name}" ) end
get_container(name)
click to toggle source
# File lib/fog/oraclecloud/requests/storage/get_container.rb, line 5 def get_container(name) response = request( :expects => [204], :method => 'HEAD', :path => "/v1/Storage-#{@identity_domain}/#{name}" ) response end
get_container_with_objects(name)
click to toggle source
# File lib/fog/oraclecloud/requests/storage/get_container.rb, line 13 def get_container_with_objects(name) response = request( :expects => [204,200], :method => 'GET', :path => "/v1/Storage-#{@identity_domain}/#{name}?format=json" ) response end
list_containers()
click to toggle source
# File lib/fog/oraclecloud/requests/storage/list_containers.rb, line 5 def list_containers response = request( :expects => 200, :method => 'GET', :path => "/v1/Storage-#{@identity_domain}?format=json" ) response end
request(params, parse_json = true, &block)
click to toggle source
# File lib/fog/oraclecloud/storage.rb, line 52 def request(params, parse_json = true, &block) begin response = @connection.request(params.merge!({ :headers => { 'X-Auth-Token' => @auth_token }.merge!(params[:headers] || {}) }), &block) rescue Excon::Errors::HTTPStatusError => error raise case error when Excon::Errors::Conflict data = Fog::JSON.decode(error.response.body) raise Error.new(data['message']) else error end end if !response.body.empty? && parse_json response.body = Fog::JSON.decode(response.body) end response end