1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
module Fog
module OpenStack
class Storage < Fog::Service
requires :openstack_auth_url
recognizes :openstack_auth_token, :openstack_management_url,
:persistent, :openstack_service_type, :openstack_service_name,
:openstack_tenant, :openstack_tenant_id, :openstack_userid,
:openstack_api_key, :openstack_username, :openstack_identity_endpoint,
:current_user, :current_tenant, :openstack_region,
:openstack_endpoint_type, :openstack_auth_omit_default_port,
:openstack_project_name, :openstack_project_id, :openstack_cache_ttl,
:openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
:openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
:openstack_identity_api_version, :openstack_temp_url_key,
:openstack_application_credential_id, :openstack_application_credential_secret
model_path 'fog/openstack/storage/models'
model :directory
collection :directories
model :file
collection :files
request_path 'fog/openstack/storage/requests'
request :copy_object
request :delete_container
request :delete_object
request :delete_multiple_objects
request :delete_static_large_object
request :get_container
request :get_containers
request :get_object
request :get_object_http_url
request :get_object_https_url
request :head_container
request :head_containers
request :head_object
request :put_container
request :put_object
request :post_object
request :put_object_manifest
request :put_dynamic_obj_manifest
request :put_static_obj_manifest
request :post_set_meta_temp_url_key
request :public_url
module Utils
def require_mime_types
# Use mime/types/columnar if available, for reduced memory usage
require 'mime/types/columnar'
rescue LoadError
begin
require 'mime/types'
rescue LoadError
Fog::Logger.warning("'mime-types' missing, please install and try again.")
exit(1)
end
end
end
class Mock
include Utils
def self.data
@data ||= Hash.new do |hash, key|
hash[key] = {}
end
end
def self.reset
@data = nil
end
def initialize(options = {})
require_mime_types
@openstack_api_key = options[:openstack_api_key]
@openstack_username = options[:openstack_username]
@openstack_management_url = options[:openstack_management_url] || 'http://example:8774/v2/AUTH_1234'
@openstack_management_uri = URI.parse(@openstack_management_url)
@path = @openstack_management_uri.path
@path.sub!(%r{/$}, '')
end
def data
self.class.data[@openstack_username]
end
def reset_data
self.class.data.delete(@openstack_username)
end
def change_account(account)
@original_path ||= @path
version_string = @original_path.split('/')[1]
@path = "/#{version_string}/#{account}"
end
def reset_account_name
@path = @original_path
end
end
class Real
include Utils
include Fog::OpenStack::Core
def self.not_found_class
Fog::OpenStack::Storage::NotFound
end
def default_service_type
%w[object-store]
end
def initialize(options = {})
require_mime_types
super
end
# Change the current account while re-using the auth token.
#
# This is usefull when you have an admin role and you're able
# to HEAD other user accounts, set quotas, list files, etc.
#
# For example:
#
# # List current user account details
# service = Fog::OpenStack::Storage.new
# service.request :method => 'HEAD'
#
# Would return something like:
#
# Account: AUTH_1234
# Date: Tue, 05 Mar 2013 16:50:52 GMT
# X-Account-Bytes-Used: 0 (0.00 Bytes)
# X-Account-Container-Count: 0
# X-Account-Object-Count: 0
#
# Now let's change the account
#
# service.change_account('AUTH_3333')
# service.request :method => 'HEAD'
#
# Would return something like:
#
# Account: AUTH_3333
# Date: Tue, 05 Mar 2013 16:51:53 GMT
# X-Account-Bytes-Used: 23423433
# X-Account-Container-Count: 2
# X-Account-Object-Count: 10
#
# If we wan't to go back to our original admin account:
#
# service.reset_account_name
#
def change_account(account)
@original_path ||= @path
version_string = @path.split('/')[1]
@path = "/#{version_string}/#{account}"
end
def reset_account_name
@path = @original_path
end
end
end
end
end
|