2015-08-18 56 views
0

我在VirtualBox上設置SAIO,並且想要檢查Temp網址功能的工作方式。無法從swift快速獲取對象

這裏是我創建下容器「testCon」呼叫test.txt的對象,你可以看到的內容和快捷列表中的對象

[email protected]:~/bin$ curl -X GET -H 'X-Auth-Token: AUTH_tkba199b23eeec4998b7119d2c9c903216' http://127.0.0.1:8080/v1/AUTH_test/testCon/test.txt 
this is a test 
[email protected]:~/bin$ swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing list testCon 
test.txt 

我跟隨鏈接(http://ceph.com/docs/master/radosgw/swift/tempurl/)設置臨時網址鍵臨時網址

[email protected]:~/bin$ curl -X POST -H 'X-Auth-Token: AUTH_tkba199b23eeec4998b7119d2c9c903216' -H 'X-Account-Meta-Temp-URL-Key: secret' http://127.0.0.1:8080/v1/AUTH_test/testCon/test.txt 
<html><h1>Accepted</h1><p>The request is accepted for processing.</p></html>[email protected]:~/bin$ 
[email protected]:~/bin$ swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing post -m "Temp-URL-Key:secret" 

,並按照Python的例子生成的臨時URL鏈接


import hmac 
from hashlib import sha1 
from time import time 

method = 'GET' 

host = "http://127.0.0.1:8080" 
duration_in_seconds = 300 # Duration for which the url is valid 
expires = int(time() + duration_in_seconds) 

path = '/v1/AUTH_test/testCon/test.txt' 
key = 'secret' 

hmac_body = '%s\n%s\n%s' % (method, expires, path) 
hmac_body = hmac.new(key, hmac_body, sha1).hexdigest() 

sig = hmac.new(key, hmac_body, sha1).hexdigest() 
rest_uri = "{host}{path}?temp_url_sig={sig}&temp_url_expires={expires}".format(
      host=host, path=path, sig=sig, expires=expires) 
print rest_uri 

但是當我把鏈接CLI中,它總是顯示:沒有這樣的文件或目錄

[email protected]:~/bin$ http://127.0.0.1:8080/v1/AUTH_test/testCon/test.txt?temp_url_sig=83fa35362613a18c2ca0b48203ccda61d2229daa&temp_url_expires=1439938672 
[1] 6125 
[email protected]:~/bin$ -bash: http://127.0.0.1:8080/v1/AUTH_test/testCon/test.txt?temp_url_sig=83fa35362613a18c2ca0b48203ccda61d2229daa: **No such file or directory** 

誰能幫助? 請向我提供一些建議嗎?

Thanks Million!

回答

0

您需要瀏覽到由python腳本生成的URL。 你可以做到這一點無論在Web瀏覽器或使用curl命令在命令行:

curl http://127.0.0.1:8080/v1/AUTH_test/testCon/test.txt?temp_url_sig=83fa35362613a18c2ca0b48203ccda61d2229daa&temp_url_expires=1439938672 

只需將鏈接在命令行上本身不會做任何事情。

+0

謝謝!但我重新生成鏈接,但我得到了「swift @ swift-VirtualBox:〜/ bin $ 401未經授權:Temp URL無效」,在上面發佈X-Account-Meta-Temp-URL-Key或錯誤路徑python? –

+0

這裏是我嘗試的cli: –

+0

我發現python的末尾有變化行和curl命令必須使用上面,然後可以得到文件下載沒有401. curl -L -o'download.txt''https: //region-a.geo-1.objects.hpcloudsvc.com/v1/10846130789747/USERMETAFILE/10846130789747_xxxxxxxx?temp_url_sig = 10846130789747:AWHYVDR62M98H1JKE3W2:92842990c61d1a063476a1e583a3dbef7d6c0ae0&temp_url_expires = 1440012858' –

0

任何人都可以爲tempURL問題提供有用的答案? 下面是你可以看到的swift屬性,tempurl鍵應該在那裏。

[email protected]:~$ swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing stat 
         Account: AUTH_test 
         Containers: 1 
         Objects: 0 
          Bytes: 0 
    Containers in policy "gold": 1 
     Objects in policy "gold": 0 
      Bytes in policy "gold": 0 
Meta X-Account-Meta-Temp-Url-Key: secret 
       Meta Temp-Url-Key: secret 
        X-Timestamp: 1439949170.11921 
         X-Trans-Id: tx38b5a254caf34023b96c3-0055d3e3e0 
        Content-Type: text/plain; charset=utf-8 
        Accept-Ranges: bytes 
[email protected]:~$ swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing stat testCon 
         Account: AUTH_test 
         Container: testCon 
         Objects: 1 
          Bytes: 15 
         Read ACL: 
         Write ACL: 
         Sync To: 
         Sync Key: 
Meta X-Account-Meta-Temp-Url-Key: secret 
        Accept-Ranges: bytes 
       X-Storage-Policy: gold 
        X-Timestamp: 1439949251.62009 
         X-Trans-Id: tx80638d6e3bb24764945fb-0055d3e3e6 
        Content-Type: text/plain; charset=utf-8 
[email protected]:~$ swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing stat testCon test.txt 
         Account: AUTH_test 
         Container: testCon 
          Object: test.txt 
        Content Type: text/plain 
        Content Length: 15 
        Last Modified: Wed, 19 Aug 2015 02:03:04 GMT 
          ETag: 81967071826aa902b0fa890876499cbb 
Meta X-Account-Meta-Temp-Url-Key: secret 
        Accept-Ranges: bytes 
        X-Timestamp: 1439949783.34589 
         X-Trans-Id: tx8d4566c37c9b4f598193e-0055d3e3ee 

我嘗試這兩種瀏覽器和捲髮+鏈接,他們不都是我的工作。

[email protected]:~$ curl http://127.0.0.1:8080/testCon/test.txt?temp_url_sig=e005d33b515a2e7900ff58f86e062f8a5682217f&temp_url_expires=1439952878 
[1] 18540 
[email protected]:~$ 401 Unauthorized: Temp URL invalid 

[email protected]:~$ curl http://127.0.0.1:8080/v1/AUTH_test/testCon/test.txt?temp_url_sig=b65dae8902026c3ade58d91a2f4c4ee135d564b0&temp_url_expires=1439952980 
[1] 18542 
[email protected]:~$ 401 Unauthorized: Temp URL invalid 

我不知道在Python路徑是正確與否,因爲我看到人們有兩種不同的建議,但包括/ V1/AUTH_USER /集裝箱/物體看起來像必要的。

import hmac 
from hashlib import sha1 
from time import time 

method = 'GET' 
#host = 'https://objectstore.example.com' 
host = "http://127.0.0.1:8080" 
#host = "http://127.0.0.1:8080/testCon/test.txt" 
duration_in_seconds = 3000 # Duration for which the url is valid 
expires = int(time() + duration_in_seconds) 
#path = '/v1/your-bucket/your-object' 
#path = '/v1/tempfolder/test.txt' 
path = '/v1/AUTH_test/testCon/test.txt' 
key = 'secret' 
#key2 = 'secret2' 
hmac_body = '%s\n%s\n%s' % (method, expires, path) 
hmac_body = hmac.new(key, hmac_body, sha1).hexdigest() 
#hmac_body = hmac.new(key, key2, hmac_body, sha1).hexdigest() 
sig = hmac.new(key, hmac_body, sha1).hexdigest() 
rest_uri = "{host}{path}?temp_url_sig={sig}&temp_url_expires={expires}".format(
      #host=host, path="", sig=sig, expires=expires) 
      host=host, path=path, sig=sig, expires=expires) 
print rest_uri 

如果您能與我分享建議,這將是一件好事。

+0

必須使用#curl -L -o'download.txt''tempurl link' –