2015-11-06 14 views
2

我試圖使用Bluemix Object Storage來存儲一些用戶內容(圖像)。 它運行Openstack Swift。Rails:在Bluemix Object Storage上使用霧(回形針)v2

根據bluemix guide,它支持Keystone V2身份驗證unbound context或Keystone v3綁定上下文中。 由於我的主應用程序不在同一個Bluemix環境中,我更喜歡使用unbound,但也可以通過虛擬應用程序使用綁定。

根據霧化寶石和霧源代碼的一些發行註記,兩種auth方法都受支持。我使用霧1.31.0。

使用未綁定的方法,在創建Bluemix服務後,我獲得了以下憑據。由於隱私原因,所有值都會稍作更改。

{ 
    "credentials": { 
    "auth_url": "https://identity.open.softlayer.com", 
    "project": "object_storage_af31119c", 
    "projectId": "82e592b46bb84232370f9657fec2b576", 
    "region": "dallas", 
    "userId": "02faa40ff3f342faaafdty1a75bd901a", 
    "username": "user_28uigjab0a2ef799eb5280c786a2ff503c978aaf", 
    "password": "V3i~]oYU8/UMNvVm", 
    "domainId": "3f160e53e6114a748a34724005a458ea", 
    "domainName": "779543" 
    } 
} 

霧OpenStack的文檔包含this配置示例:

service = Fog::Storage.new({ 
    :provider   => 'OpenStack', # OpenStack Fog provider 
    :openstack_username => USERNAME,  # Your OpenStack Username 
    :openstack_api_key => PASSWORD,  # Your OpenStack Password 
    :openstack_auth_url => 'http://YOUR_OPENSTACK_ENDPOINT:PORT/v2.0/tokens' 
}) 

我充滿了我的憑據,並使用https://identity.open.softlayer.com/v2.0/tokens作爲auth_url。 這是錯誤我得到:

Uncaught exception: Expected([200, 204]) <=> Actual(401 Unauthorized) 
excon.error.response 
:body => "{\"error\": {\"message\": \"The request you have made requires 
authentication.\", \"code\": 401, \"title\": \"Unauthorized \"}}" 

:headers => { 
"Content-Length" => "114" 
"Content-Type" => "application/json" 
"Date"   => "Fri, 06 Nov 2015 15:08:55 GMT" 
"Server"   => "Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips mod_wsgi/3.4 Python/2.7.5" 
"Vary"   => "X-Auth-Token" 
"WWW-Authenticate"  => "Keystone uri=\"https://identity.open.softlayer.com\"" 
"x-openstack-request-id" => "req-2f68188e-2a9e-45ad-ae18-289ac88b78ae" } 
:local_address => "10.0.2.15" 
:local_port => 59407 
:reason_phrase => "Unauthorized" 
:remote_ip  => "198.23.119.11" 
:status  => 401 
:status_line => "HTTP/1.1 401 Unauthorized\r\n" 

/home/startupdeltadev/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/excon-0.45.3/lib/excon/middlewares/expects.rb:10:in `response_call' 
/home/startupdeltadev/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/excon-0.45.3/lib/excon/middlewares/response_parser.rb:8:in `response_call' 
/home/startupdeltadev/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/excon-0.45.3/lib/excon/connection.rb:372:in `response' 
/home/startupdeltadev/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/excon-0.45.3/lib/excon/connection.rb:236:in `request' 
/home/startupdeltadev/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/fog-core-1.31.1/lib/fog/core/connection.rb:81:in `request' 
/home/startupdeltadev/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/fog-1.31.0/lib/fog/openstack/core.rb:331:in `retrieve_tokens_v2' 

很顯然,我的憑據不能正確發送。任何提示?

回答

0

您的Openstack用戶屬於'779543'域。身份(Keystone)v3 API支持域。我找不到有關如何使用Keystone v3和Fog的好例子。

0

根據文檔Bluemix OpenStack Swift

開棧身份(梯形失真校正)V2

的V2令牌請求是POST請求 https://identity.open.softlayer.com/v2.0/tokens如圖中 以下curl命令:

curl -i \ 
-H "Content-Type: application/json" \ 
-d ' 
{ 
    "auth": { 
     "tenantId": "0f47b41b06d047f9aae3b33f1db061ed", 
     "passwordCredentials": { 
     "userId": "ad78b2a3f843466988afd077731c61fc", 
     "password": "K/jyIi2jR=1?D.TP " 
    } 
} 
}' \ 
https://identity.open.softlayer.com/v2.0/tokens ; echo 

注意:此請求方法未在OpenStack Identity v2網站上記錄。 您不能使用tenantName和用戶名

霧:: OpenStack的(和許多其他庫)使用的用戶名代替用戶id

您應該使用OpenStack的身份(梯形)V3這樣:

storage = Fog::OpenStack.new({ 
    :provider     => 'OpenStack', 
    :openstack_auth_url  => credentials['auth_url'], 
    :openstack_api_key  => credentials['password'], 
    :openstack_project_id  => credentials['projectId'],   
    :openstack_username  => credentials['username'], 
    :openstack_domain_name => credentials['domainName'],#required if you use :openstack_username (otherwise set :openstack_userid) 
    :openstack_region   => credentials['region'] 
}) 
相關問題