1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
|
# -*- encoding: utf-8 -*-
require 'base64'
require 'json'
require 'uri'
module Aliyun
module OSS
##
# Access Control List, it controls how the bucket/object can be
# accessed.
# * public-read-write: allow access(read&write) anonymously
# * public-read: allow read anonymously
# * private: access must be signatured
#
module ACL
PUBLIC_READ_WRITE = "public-read-write"
PUBLIC_READ = "public-read"
PRIVATE = "private"
end # ACL
##
# A OSS object may carry some metas(String key-value pairs) with
# it. MetaDirective specifies what to do with the metas in the
# copy process.
# * COPY: metas are copied from the source object to the dest
# object
# * REPLACE: source object's metas are NOT copied, use user
# provided metas for the dest object
#
module MetaDirective
COPY = "COPY"
REPLACE = "REPLACE"
end # MetaDirective
##
# The object key may contains unicode charactors which cannot be
# encoded in the request/response body(XML). KeyEncoding specifies
# the encoding type for the object key.
# * url: the object key is url-encoded
# @note url-encoding is the only supported KeyEncoding type
#
module KeyEncoding
URL = "url"
@@all = [URL]
def self.include?(enc)
all.include?(enc)
end
def self.all
@@all
end
end # KeyEncoding
##
# Bucket Logging setting. See: {http://help.aliyun.com/document_detail/oss/product-documentation/function/logging.html OSS Bucket logging}
# Attributes:
# * enable [Boolean] whether to enable bucket logging
# * target_bucket [String] the target bucket to store access logs
# * target_prefix [String] the target object prefix to store access logs
# @example Enable bucket logging
# bucket.logging = BucketLogging.new(
# :enable => true, :target_bucket => 'log_bucket', :target_prefix => 'my-log')
# @example Disable bucket logging
# bucket.logging = BucketLogging.new(:enable => false)
class BucketLogging < Common::Struct::Base
attrs :enable, :target_bucket, :target_prefix
def enabled?
enable == true
end
end
##
# Bucket Versioning setting. See: {http://help.aliyun.com/document_detail/oss/product-documentation/function/versioning.html OSS Bucket versioning}
# Attributes:
# * status [String] the bucket versioning status, can be 'Enabled' and 'Suspended'
# @example Enable bucket versioning
# bucket.versioning = BucketVersioning.new(:status => 'Enabled')
# @example Suspend bucket versioning
# bucket.versioning = BucketVersioning.new(:status => 'Suspended')
class BucketVersioning < Common::Struct::Base
attrs :status
end
##
# Bucket Encryption setting. See: {http://help.aliyun.com/document_detail/oss/product-documentation/function/encryption.html OSS Bucket encryption}
# Attributes:
# * sse_algorithm [string] Indicates the default server-side encryption method
# * kms_master_key_id [string] Indicates the ID of CMK that is currently used.
class BucketEncryption < Common::Struct::Base
attrs :enable, :sse_algorithm, :kms_master_key_id
def enabled?
enable == true
end
end
##
# Bucket website setting. See: {http://help.aliyun.com/document_detail/oss/product-documentation/function/host-static-website.html OSS Website hosting}
# Attributes:
# * enable [Boolean] whether to enable website hosting for the bucket
# * index [String] the index object as the index page for the website
# * error [String] the error object as the error page for the website
class BucketWebsite < Common::Struct::Base
attrs :enable, :index, :error
def enabled?
enable == true
end
end
##
# Bucket referer setting. See: {http://help.aliyun.com/document_detail/oss/product-documentation/function/referer-white-list.html OSS Website hosting}
# Attributes:
# * allow_empty [Boolean] whether to allow requests with empty "Referer"
# * whitelist [Array<String>] the allowed origins for requests
class BucketReferer < Common::Struct::Base
attrs :allow_empty, :whitelist
def allow_empty?
allow_empty == true
end
end
##
# LifeCycle rule for bucket. See: {http://help.aliyun.com/document_detail/oss/product-documentation/function/lifecycle.html OSS Bucket LifeCycle}
# Attributes:
# * id [String] the unique id of a rule
# * enabled [Boolean] whether to enable this rule
# * prefix [String] the prefix objects to apply this rule
# * expiry [Date] or [Integer] the expire time of objects
# * if expiry is a Date, it specifies the absolute date to
# expire objects
# * if expiry is a Integer, it specifies the relative date to
# expire objects: how many days after the object's last
# modification time to expire the object
# @example Specify expiry as Date
# LifeCycleRule.new(
# :id => 'rule1',
# :enabled => true,
# :prefix => 'foo/',
# :expiry => Date.new(2016, 1, 1))
# @example Specify expiry as days
# LifeCycleRule.new(
# :id => 'rule1',
# :enabled => true,
# :prefix => 'foo/',
# :expiry => 15)
# @note the expiry date is treated as UTC time
class LifeCycleRule < Common::Struct::Base
attrs :id, :enable, :prefix, :expiry
def enabled?
enable == true
end
end # LifeCycleRule
##
# CORS rule for bucket. See: {http://help.aliyun.com/document_detail/oss/product-documentation/function/referer-white-list.html OSS CORS}
# Attributes:
# * allowed_origins [Array<String>] the allowed origins
# * allowed_methods [Array<String>] the allowed methods
# * allowed_headers [Array<String>] the allowed headers
# * expose_headers [Array<String>] the expose headers
# * max_age_seconds [Integer] the max age seconds
class CORSRule < Common::Struct::Base
attrs :allowed_origins, :allowed_methods, :allowed_headers,
:expose_headers, :max_age_seconds
end # CORSRule
##
# Callback represents a HTTP call made by OSS to user's
# application server after an event happens, such as an object is
# successfully uploaded to OSS. See: {https://help.aliyun.com/document_detail/oss/api-reference/object/Callback.html}
# Attributes:
# * url [String] the URL *WITHOUT* the query string
# * query [Hash] the query to generate query string
# * body [String] the body of the request
# * content_type [String] the Content-Type of the request
# * host [String] the Host in HTTP header for this request
class Callback < Common::Struct::Base
attrs :url, :query, :body, :content_type, :host
include Common::Logging
def serialize
query_string = (query || {}).map { |k, v|
[CGI.escape(k.to_s), CGI.escape(v.to_s)].join('=') }.join('&')
cb = {
'callbackUrl' => "#{normalize_url(url)}?#{query_string}",
'callbackBody' => body,
'callbackBodyType' => content_type || default_content_type
}
cb['callbackHost'] = host if host
logger.debug("Callback json: #{cb}")
Base64.strict_encode64(cb.to_json)
end
private
def normalize_url(url)
uri = URI.parse(url)
uri = URI.parse("http://#{url}") unless uri.scheme
if uri.scheme != 'http' and uri.scheme != 'https'
fail ClientError, "Only HTTP and HTTPS endpoint are accepted."
end
unless uri.query.nil?
fail ClientError, "Query parameters should not appear in URL."
end
uri.to_s
end
def default_content_type
"application/x-www-form-urlencoded"
end
end # Callback
end # OSS
end # Aliyun
|