Ruby on rails Rails:使用带有Bluemix对象存储v2的Fog(回形针)
我尝试使用Bluemix对象存储来存储一些用户内容(图像)。 它运行Openstack Swift 根据,它支持绑定上下文中的Keystone V2或Keystone v3中的Keystone V2身份验证。 由于我的主应用程序不在同一个Bluemix环境中,我更喜欢使用unbound,但也可以通过虚拟应用程序使用bound 根据Fog gem和Fog源代码的一些发行说明,这两种身份验证方法都受支持。我用的是雾1.31.0 使用unbound方法,我在创建Bluemix服务后获得以下凭据。出于隐私原因,所有值都会略有更改Ruby on rails Rails:使用带有Bluemix对象存储v2的Fog(回形针),ruby-on-rails,openstack,ibm-cloud,fog,openstack-swift,Ruby On Rails,Openstack,Ibm Cloud,Fog,Openstack Swift,我尝试使用Bluemix对象存储来存储一些用户内容(图像)。 它运行Openstack Swift 根据,它支持绑定上下文中的Keystone V2或Keystone v3中的Keystone V2身份验证。 由于我的主应用程序不在同一个Bluemix环境中,我更喜欢使用unbound,但也可以通过虚拟应用程序使用bound 根据Fog gem和Fog源代码的一些发行说明,这两种身份验证方法都受支持。我用的是雾1.31.0 使用unbound方法,我在创建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"
}
}
fog openstack文档包含配置示例:
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'
})
我填写了我的凭证,并将其用作身份验证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'
Uncaught异常:预期([200204])实际(401未授权)
excon.error.response
:body=>“{\”error\”:{\”message\“:\”您提出的请求需要
身份验证。\“,\“代码\”:401,\“标题\:\“未经授权\”}”
:标题=>{
“内容长度”=>“114”
“内容类型”=>“应用程序/json”
“日期”=>“2015年11月6日星期五15:08:55 GMT”
“服务器”=>“Apache/2.4.6(CentOS)OpenSSL/1.0.1e-fips mod_wsgi/3.4 Python/2.7.5”
“更改”=>“X-Auth-Token”
“WWW Authenticate”=>“Keystone uri=\”https://identity.open.softlayer.com\""
“x-openstack-request-id”=>“req-2f68188e-2a9e-45ad-ae18-289ac88b78ae”}
:本地地址=>“10.0.2.15”
:本地_端口=>59407
:原因\短语=>“未经授权”
:remote_ip=>“198.23.119.11”
:状态=>401
:status\u line=>“HTTP/1.1 401未经授权\r\n”
/home/startupdeltadev/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/excon-0.45.3/lib/excon/middleware/expects.rb:10:在`应答电话'中
/home/startupdeltadev/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/excon-0.45.3/lib/excon/middleware/response\u parser.rb:8:in“response\u 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:在“响应”中
/home/startupdeltadev/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/excon-0.45.3/lib/excon/connection.rb:236:在“请求”中
/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:在“请求”中
/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:在“检索令牌”v2中
显然,我的凭证没有正确发送。有任何提示吗?您的Openstack用户属于“779543”域。Identity(Keystone)V3API支持域。我找不到任何关于如何在Fog中使用Keystone v3的好例子。根据文档 OpenStack标识(Keystone)v2 v2令牌请求是对的POST请求 如图所示 下面是curl命令: 注意:OpenStack标识中没有记录此请求方法 v2网站不能使用租户名称和用户名 Fog::OpenStack(和许多其他库)使用用户名而不是用户名 您应该以以下方式使用OpenStack Identity(Keystone)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']
})
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']
})