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

wget "https://hcm.vstorage.vnglab.com/v1/AUTH_afa7086fbef044938dbb7d8d328d452a/container/file1?temp_url_sig=1fe9fbcdb9d6683eef8658a18aa97c7090525cec&temp_url_expires=1672595887"

--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

.r:-<referrer>

(Exp: .r: -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