Class: Fog::Storage::OracleCloud::Real
- Inherits:
-
Object
- Object
- Fog::Storage::OracleCloud::Real
- Defined in:
- lib/fog/oraclecloud/storage.rb,
lib/fog/oraclecloud/requests/storage/get_container.rb,
lib/fog/oraclecloud/requests/storage/list_containers.rb,
lib/fog/oraclecloud/requests/storage/create_container.rb,
lib/fog/oraclecloud/requests/storage/delete_container.rb
Instance Method Summary collapse
- #authenticate ⇒ Object
- #create_container(name) ⇒ Object
- #delete_container(name) ⇒ Object
- #get_container(name) ⇒ Object
- #get_container_with_objects(name) ⇒ Object
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
- #list_containers ⇒ Object
- #request(params, parse_json = true, &block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Real
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/fog/oraclecloud/storage.rb', line 19 def initialize(={}) @username = [:oracle_username] @password = [:oracle_password] @identity_domain = [:oracle_domain] @api_endpoint = [:oracle_storage_api] @connection = Fog::XML::Connection.new(@api_endpoint) # Get authentication token authenticate end |
Instance Method Details
#authenticate ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# 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) ⇒ Object
8 9 10 11 12 13 14 |
# 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) ⇒ Object
5 6 7 8 9 10 11 |
# 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) ⇒ Object
5 6 7 8 9 10 11 12 |
# 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) ⇒ Object
13 14 15 16 17 18 19 20 |
# 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 ⇒ Object
5 6 7 8 9 10 11 12 |
# 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) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# 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 |