Using SwiftClient
Common usecase
Get token
swift auth
export OS_STORAGE_URL=https://hcm.vstorage.vnglab.com/v1/AUTH_afa7086fbef044938dbb7d8d328d452a
export OS_AUTH_TOKEN=gAAAAABjsYvUCXdVOkJo6EttO7WIVKrqnkbc2_nUU59RGBbzsOo4rbSra5RayTBtC_CJzosiJzZkOj77_nqLt-NcaShU47ggANr8dm9TGvHTY48mphfnZPRyAuFFEr4LiG7zNlJBkOxqbBPR7kDbJIpuVKTodupASxhQAYgaKP0s20zE4C77kC8
When using the SwiftClient tool, it's possible to omit exporting OS_STORAGE_URL and OS_AUTH_TOKEN. However, the request time will be longer because for each request or operation, a new token needs to be obtained. Therefore, it is recommended to export these variables for reuse multiple times.
Verify project(account)'s metadata information
swift stat
Account: AUTH_afa7086fbef044938dbb7d8d328d452a
Containers: 6
Objects: 4
Bytes: 24351437
Containers in policy "archive": 1
Objects in policy "archive": 0
Bytes in policy "archive": 0
Containers in policy "gold": 4
Objects in policy "gold": 4
Bytes in policy "gold": 24351437
Containers in policy "silver": 1
Objects in policy "silver": 0
Bytes in policy "silver": 0
Meta Quota-Bytes: 10000000
Meta Temp-Url-Key: tx71f555cc77df46afa6568-0063a286ee
Meta My-Custom-Metadata: abc
Vary: Accept
X-Vngcloud-Backend: 03/backend_hcm_vstorage_vnglab
X-Account-Project-Domain-Id: default
X-Timestamp: 1668228497.92635
Accept-Ranges: bytes
X-Trans-Id: tx1c351a6c5467473d8e823-0063b1a74c
X-Openstack-Request-Id: tx1c351a6c5467473d8e823-0063b1a74c
Server: vngcloud
Connection: keep-alive
Content-Type: text/plain; charset=utf-8
Key | ร nghฤฉa |
Account | Account name |
Containers | Number of containers |
Objects | Number of objects |
Bytes | Bytes used in account |
Containers in policy "xxx" | Number of containers belong policy xxx |
Objects in policy "xxx" | Number objects belong policy xxx |
Bytes in policy "xxx" | Bytes used belong policy xxx |
Meta Quota-Bytes | quota cแปงa account |
Meta Temp-Url-Key | temp-url-key cแปงa account ฤฦฐแปฃc dรนng ฤแป tแบกo ra temp-url |
Meta My-Custom-Metadata | Mแปt metadata tuแปณ chแปn do ngฦฐแปi dรนng tแปฑ ฤแบทt |
Thiแบฟt lแบญp metadata cho project (account)
swift post โm <key:value>
Xรณa metadata cho project (account)
swift post -m <key:>
Thiแบฟt lแบญp custom metadata (user metadata) cho project (account)
Swift post โm โmy_custom_metadata:abcโ
Liแปt kรช danh sรกch cรกc container thuแปc mแปt project (account)
swift list
Tแบกo mแปt container mแปi
swift post <container_name>
Xรณa container
swift delete container
Truy xuแบฅt thรดng tin metadata cแปงa mแปt container
swift stat my_container
\
Account: AUTH_afa7086fbef044938dbb7d8d328d452a
Container: my_container
Objects: 0
Bytes: 0
Read ACL:
Write ACL:
Sync To:
Sync Key:
Last-Modified: Sun, 01 Jan 2023 13:30:13 GMT
Accept-Ranges: bytes
Vary: Accept
Server: vngcloud
X-Storage-Policy: gold
Connection: keep-alive
X-Timestamp: 1672579812.82240
X-Trans-Id: tx0caa6b4d82d54f9c95548-0063b18b1a
X-Container-Sharding: False
Content-Type: text/plain; charset=utf-8
X-Openstack-Request-Id: tx0caa6b4d82d54f9c95548-0063b18b1a
X-Vngcloud-Backend: 03/backend_hcm_vstorage_vnglab
Thiแบฟt lแบญp metadata cho container
swift post container -m <key:value>
Liแปt kรช danh sรกch cรกc object cแปงa mแปt container
swift list <container_name>
Upload object lรชn mแปt container
swift upload <container_name> [--object-name <object-name>] <local_file_or_directory>
Upload mแปt large object (multipart upload) lรชn mแปt container
swift upload <container_name> <object_name> --segment-size <size>
swift upload container large_file --segment-size 50M
Download object tแปซ mแปt container
swift download <container_name> <object_name>
Xรณa mแปt object trong container
swift delete <container_name> <object_name>
Thiแบฟt lแบญp metadata cho mแปt object
swift post <container_name> <object_name> -m "<metadata>:<value>"
Xรณa metadata cแปงa mแปt object
swift post <container_name> <object_name> -m "<metadata>:"
Mแปt sแป use case nรขng cao
Tแบกo (generate) tempURL link
Tแบกo tempURL lร kแปน thuแบญt tแบกo ra ฤฦฐแปng dแบซn public cho mแปt object cรณ hiแปu lแปฑc trong mแปt khoแบฃng thแปi gian nhแบฅt ฤแปnh nhแบฑm chia sแบป quyแปn truy cแบญp object mร khรดng cแบงn phแบฃi cรดng khai thรดng tin ฤฤng nhแบญp nhฦฐ username, password, secret key. Sแปญ dแปฅng tรญnh nฤng tแบกo tempURL do SwiftClient cung cแบฅp nhฦฐ sau ฤแป tแบกo ra cรกc PUT/ GET tempURL.
swift tempurl --help
swift tempurl <method> <time> <path> <tempurl_key>
Vรญ dแปฅ tแบกo ra GET tempURL ฤแป download mแปt object
swift tempurl GET 3600 /v1/AUTH_afa7086fbef044938dbb7d8d328d452a/container/file1 tx71f555cc77df46afa6568-0063a286ee
โ /v1/AUTH_afa7086fbef044938dbb7d8d328d452a/container/file1?temp_url_sig=1fe9fbcdb9d6683eef8658a18aa97c7090525cec&temp_url_expires=1672595887
Sแปญ dแปฅng GET tempURL link ฤฦฐแปฃc sinh ra แป trรชn ฤแป download object
--2023-01-01 23:58:42-- https://hcm.vstorage.vnglab.com/v1/AUTH_afa7086fbef044938dbb7d8d328d452a/container/file1?temp_url_sig=1fe9fbcdb9d6683eef8658a18aa97c7090525cec&temp_url_expires=1672595887
Resolving hcm.vstorage.vnglab.com (hcm.vstorage.vnglab.com)... 61.28.228.48
Connecting to hcm.vstorage.vnglab.com (hcm.vstorage.vnglab.com)|61.28.228.48|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 12174069 (12M) [application/octet-stream]
Saving to: โfile1?temp_url_sig=1fe9fbcdb9d6683eef8658a18aa97c7090525cec&temp_url_expires=1672595887โ
\
file1?temp_url_sig=1fe9 100%[===============================>] 11.61M 16.1MB/s in 0.7s
\
2023-01-01 23:58:43 (16.1 MB/s) - โfile1?temp_url_sig=1fe9fbcdb9d6683eef8658a18aa97c7090525cec&temp_url_expires=1672595887โ saved [12174069/12174069]
\
Tฦฐฦกng tแปฑ ta cรณ thแป tแบกo ฤฦฐแปng dแบซn tแบกm ฤแป cho user upload bแบฑng cรกch ฤแปi method thร nh "PUT".
Thiแบฟt lแบญp ACLs cho mแปt container
ฤแป thiแบฟt lแบญp ACLs cho mแปt container, chรบng tรดi khuyแบฟn nghแป bแบกn nรชn thแปฑc hiแปn tรญnh nฤng nร y thรดng qua vStorage portal. ฤแป thiแบฟt lแบญp ACLs cho container qua vStorage portal, vui lรฒng tham khแบฃo แป ฤรขy. Tuy nhiรชn, bแบกn cรณ thแป sแปญ dแปฅng cรดng cแปฅ ngฦฐแปi dรนng SwiftClient ฤแป thiแบฟt lแบญp ACLs cho mแปt container sแปญ dแปฅng lแปnh sau cแปงa SwiftClient:
swift post <container> -H โ<X-Container-Write| X-Container-Read>:<value>โ
Trong ฤรณ, biแบฟn <Value> nhแบญn cรกc giรก trแป trong bแบฃng sau:
Value | Description |
.r:* | Any user has access to objects. No token is required in the request. |
.r:<referrer> (Exp: .r: http://example.org/referring_page) | The referrer is granted access to objects. The referrer is identified by the Referer request header in the request. No token is required. Exp:
GET /wiki/Referrer HTTP/1.1 Host: http://de.wikipedia.org Referer: http://example.org/referring_page |
This syntax (with โ-โ prepended to the referrer) is supported. However, it does not deny access if another element (e.g., .r:*) grants access. Exp:
GET /wiki/Referrer HTTP/1.1 Host: http://de.wikipedia.org Referer: http://example.org/referring_page
| |
.rlistings | Any user can perform a HEAD or GET operation on the container provided the user also has read access on objects (e.g., also has .r:* or .r:<referrer>. No token is required. |
ฤแป hiแปu thรชm vแป ACLs cแปงa container, vui lรฒng tham khแบฃo https://docs.openstack.org/swift/latest/overview_acl.html.
Chรบ รฝ:
Khรดng nรชn sแปญ dแปฅng phiรชn bแบฃn SwiftClient quรก cลฉ trรชn cรกc hแป ฤiแปu hร nh cรณ phiรชn bแบฃn quรก cลฉ hoแบทc mแปi nhแบฅt vรฌ cรณ thแป gแบทp lแปi.
SwiftClient Khรดng gรขy ra incomplete segment (segment rรกc) trong quรก trรฌnh tแบฃi object lแปn (multipart upload).
Last updated