Class: Aliyun::Oss::Struct::Bucket

Inherits:
Base
  • Object
show all
Defined in:
lib/aliyun/oss/struct/bucket.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Aliyun::Oss::Struct::Base

Instance Attribute Details

#clientObject

reference to client



15
16
17
# File 'lib/aliyun/oss/struct/bucket.rb', line 15

def client
  @client
end

#creation_dateObject

Createion date of Bucket



12
13
14
# File 'lib/aliyun/oss/struct/bucket.rb', line 12

def creation_date
  @creation_date
end

#locationObject

Bucket Location



9
10
11
# File 'lib/aliyun/oss/struct/bucket.rb', line 9

def location
  @location
end

#nameObject

Bucket Name



6
7
8
# File 'lib/aliyun/oss/struct/bucket.rb', line 6

def name
  @name
end

Instance Method Details

#acl!String

Get the acl

Returns:

  • (String)

See Also:



70
71
72
73
74
# File 'lib/aliyun/oss/struct/bucket.rb', line 70

def acl!
  result = client.bucket_get_acl.parsed_response
  acl_keys = %w(AccessControlPolicy AccessControlList Grant)
  Utils.dig_value(result, *acl_keys)
end

#cors!Array<Aliyun::Oss::Struct::Cors>

Get the CORS



93
94
95
96
97
98
99
# File 'lib/aliyun/oss/struct/bucket.rb', line 93

def cors!
  result = client.bucket_get_cors.parsed_response
  cors_keys = %w(CORSConfiguration CORSRule)
  Utils.wrap(Utils.dig_value(result, *cors_keys)).map do |cors|
    Struct::Cors.new(cors)
  end
end

#disable_corstrue

Disable CORS for bucket

Returns:

  • (true)

See Also:



118
119
120
# File 'lib/aliyun/oss/struct/bucket.rb', line 118

def disable_cors
  !!client.bucket_disable_cors
end

#disable_lifecycletrue

Used to disable lifecycle for bucket



216
217
218
# File 'lib/aliyun/oss/struct/bucket.rb', line 216

def disable_lifecycle
  !!client.bucket_disable_lifecycle
end

#disable_loggingtrue

Used to disable access logging.

Returns:

  • (true)

See Also:



61
62
63
# File 'lib/aliyun/oss/struct/bucket.rb', line 61

def disable_logging
  !!client.bucket_disable_logging
end

#disable_websitetrue

Used to disable website hostted mode.

Returns:

  • (true)

See Also:



154
155
156
# File 'lib/aliyun/oss/struct/bucket.rb', line 154

def disable_website
  !!client.bucket_disable_website
end

#enable_cors(*args) ⇒ true

Set CORS for bucket

Parameters:

Returns:

  • (true)

Raises:

See Also:



109
110
111
# File 'lib/aliyun/oss/struct/bucket.rb', line 109

def enable_cors(*args)
  !!client.bucket_enable_cors(*args)
end

#enable_lifecycle(*args) ⇒ true

Used to enable and set lifecycle for bucket

Returns:

  • (true)

See Also:

  • Client#bucket_enable_lifecycle


207
208
209
# File 'lib/aliyun/oss/struct/bucket.rb', line 207

def enable_lifecycle(*args)
  !!client.bucket_enable_lifecycle(*args)
end

#enable_logging(*args) ⇒ true

Used to enable access logging.

Parameters:

  • target_bucket (String)

    specifies the bucket where you want Aliyun OSS to store server access logs.

  • target_prefix (String)

    this element lets you specify a prefix for the objects that the log files will be stored.

Returns:

  • (true)

Raises:

See Also:



50
51
52
# File 'lib/aliyun/oss/struct/bucket.rb', line 50

def enable_logging(*args)
  !!client.bucket_enable_logging(*args)
end

#enable_website(*args) ⇒ true

Used to enable static website hosted mode.

Parameters:

  • suffix (String)

    A suffix that is appended to a request that is for a directory on the website endpoint (e.g. if the suffix is index.html and you make a request to samplebucket/images/ the data that is returned will be for the object with the key name images/index.html) The suffix must not be empty and must not include a slash character.

  • key (String)

    The object key name to use when a 4XX class error occurs

Returns:

  • (true)

Raises:

See Also:



145
146
147
# File 'lib/aliyun/oss/struct/bucket.rb', line 145

def enable_website(*args)
  !!client.bucket_enable_website(*args)
end

#hostObject



17
18
19
# File 'lib/aliyun/oss/struct/bucket.rb', line 17

def host
  "#{location}.aliyuncs.com"
end

#lifecycle!Array<Aliyun::Oss::Struct::Lifecycle?]

Get the lifecycle configuration

Returns:

  • (Array<Aliyun::Oss::Struct::Lifecycle?])

    Array<Aliyun::Oss::Struct::Lifecycle?]

See Also:



190
191
192
193
194
195
196
# File 'lib/aliyun/oss/struct/bucket.rb', line 190

def lifecycle!
  result = client.bucket_get_lifecycle.parsed_response
  lifecycle_keys = %w(LifecycleConfiguration Rule)
  Utils.wrap(Utils.dig_value(result, *lifecycle_keys)).map do |lifecycle|
    Struct::LifeCycle.new(lifecycle)
  end
end

#location!String

Get the location

Returns:

  • (String)

See Also:



26
27
28
29
30
# File 'lib/aliyun/oss/struct/bucket.rb', line 26

def location!
  result = client.bucket_get_location.parsed_response
  Utils.dig_value(result, 'LocationConstraint', '__content__') ||
    Utils.dig_value(result, 'LocationConstraint')
end

#logging!Object

Get Logging configration for bucket

return [true]



37
38
39
40
# File 'lib/aliyun/oss/struct/bucket.rb', line 37

def logging!
  result = client.bucket_get_logging.parsed_response
  Struct::Logging.new(Utils.dig_value(result, 'BucketLoggingStatus'))
end

#preflight(*args) ⇒ true Also known as: options

OPTIONS Object

Returns:

  • (true)

See Also:

  • Api::BucketProperty#bucket_preflight


228
229
230
# File 'lib/aliyun/oss/struct/bucket.rb', line 228

def preflight(*args)
  !!client.bucket_preflight(*args)
end

#referer!Aliyun::Oss::Struct::Referer

Get the referer configuration



163
164
165
166
167
168
169
170
171
# File 'lib/aliyun/oss/struct/bucket.rb', line 163

def referer!
  result = client.bucket_get_referer.parsed_response
  allow_empty = %w(RefererConfiguration AllowEmptyReferer)
  referers = %w(RefererConfiguration RefererList Referer)
  Aliyun::Oss::Struct::Referer.new(
    allow_empty: Utils.dig_value(result, *allow_empty),
    referers: Utils.dig_value(result, *referers)
  )
end

#set_acl(*args) ⇒ true

Set ACL for bucket

Parameters:

  • acl (String)

    supported value: public-read-write | public-read | private

Returns:

  • (true)

Raises:

See Also:



84
85
86
# File 'lib/aliyun/oss/struct/bucket.rb', line 84

def set_acl(*args)
  !!client.bucket_set_acl(*args)
end

#set_referer(*args) ⇒ true

Used to set referer for bucket.

Parameters:

  • referers (Array<String>)

    white list for allowed referer.

  • allowed_empty (Boolean)

    whether allow empty refer.

Returns:

  • (true)

Raises:

See Also:



181
182
183
# File 'lib/aliyun/oss/struct/bucket.rb', line 181

def set_referer(*args)
  !!client.bucket_set_referer(*args)
end

#website!Aliyun::Oss::Rule::Website

Get the website configuration

Returns:

  • (Aliyun::Oss::Rule::Website)

See Also:



127
128
129
130
131
132
133
134
135
# File 'lib/aliyun/oss/struct/bucket.rb', line 127

def website!
  result = client.bucket_get_website.parsed_response
  suffix_keys = %w(WebsiteConfiguration IndexDocument Suffix)
  error_keys = %w(WebsiteConfiguration ErrorDocument Key)
  Aliyun::Oss::Struct::Website.new(
    suffix: Utils.dig_value(result, *suffix_keys),
    error_key: Utils.dig_value(result, *error_keys)
  )
end