Class: COS::Signature
- Inherits:
-
Object
- Object
- COS::Signature
- Defined in:
- lib/cos/signature.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#expire_seconds ⇒ Object
readonly
Returns the value of attribute expire_seconds.
-
#file_id ⇒ Object
readonly
Returns the value of attribute file_id.
Instance Method Summary collapse
-
#initialize(config) ⇒ Signature
constructor
初始化.
-
#multiple(bucket, expire_seconds = config.multiple_sign_expire) ⇒ String
多次有效签名.
-
#once(bucket, path) ⇒ String
单次有效签名.
Constructor Details
#initialize(config) ⇒ Signature
初始化
22 23 24 |
# File 'lib/cos/signature.rb', line 22 def initialize(config) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
12 13 14 |
# File 'lib/cos/signature.rb', line 12 def config @config end |
#expire_seconds ⇒ Object (readonly)
Returns the value of attribute expire_seconds.
12 13 14 |
# File 'lib/cos/signature.rb', line 12 def expire_seconds @expire_seconds end |
#file_id ⇒ Object (readonly)
Returns the value of attribute file_id.
12 13 14 |
# File 'lib/cos/signature.rb', line 12 def file_id @file_id end |
Instance Method Details
#multiple(bucket, expire_seconds = config.multiple_sign_expire) ⇒ String
Note:
用于上传,查询目录、文件,查询目录、文件,创建目录,下载(开启token防盗链)
多次有效签名
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/cos/signature.rb', line 59 def multiple(bucket, expire_seconds = config.multiple_sign_expire) # 多次签名时,过期时间应大于当前时间 if expire_seconds <= 0 raise AttrError, 'Multiple signature expire_seconds must greater than 0' end @expire_seconds = expire_seconds sign(:multiple, bucket) end |
#once(bucket, path) ⇒ String
Note:
用于删除目录、文件, 更新目录、文件
单次有效签名
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cos/signature.rb', line 36 def once(bucket, path) # 单次签名,需要指定资源存储的唯一标识 unless path.start_with?('/') path = "/#{path}" end # 资源存储的唯一标识,格式为"/app_id/bucket/用户自定义路径或资源名" @file_id = "/#{config.app_id}/#{bucket}#{path}" sign(:once, bucket) end |