4.7. Swift get 임시 URL 오브젝트
임시 URL은 다음 요소를 포함하는 암호화 HMAC-SHA1 서명을 사용합니다.
- Request 메서드의 값, 인스턴스의 "GET"
- 만료 시간(epoch 이후의 초) 즉 Unix 시간
- "v1"에서 시작하는 요청 경로
위의 항목은 둘 사이에 추가된 newlines로 정규화되고 HMAC는 이전에 게시된 Temp URL Keys 중 하나에 SHA-1 해시 알고리즘을 사용하여 생성됩니다.
위의 예를 보여주는 샘플 python 스크립트는 다음과 같습니다.
예제
import hmac from hashlib import sha1 from time import time method = 'GET' host = 'https://objectstore.example.com' duration_in_seconds = 300 # Duration for which the url is valid expires = int(time() + duration_in_seconds) path = '/v1/your-bucket/your-object' 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
출력 예
https://objectstore.example.com/v1/your-bucket/your-object?temp_url_sig=ff4657876227fc6025f04fcf1e82818266d022c6&temp_url_expires=1423200992