Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(storage): Add ARCHIVE storage class #4319

Merged
merged 1 commit into from
Jan 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions google-cloud-storage/acceptance/storage/file_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -468,12 +468,12 @@
uploaded = bucket.create_file files[:logo][:path], "CloudLogo-storage_class.png", storage_class: :nearline

uploaded.storage_class.must_equal "NEARLINE"
uploaded.storage_class = :dra
uploaded.storage_class.must_equal "DURABLE_REDUCED_AVAILABILITY"
uploaded.storage_class = :archive
uploaded.storage_class.must_equal "ARCHIVE"

retrieved1 = bucket.file "CloudLogo-storage_class.png"

retrieved1.storage_class.must_equal "DURABLE_REDUCED_AVAILABILITY"
retrieved1.storage_class.must_equal "ARCHIVE"
end

it "should copy an existing file" do
Expand Down
16 changes: 8 additions & 8 deletions google-cloud-storage/lib/google/cloud/storage/bucket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def logging_prefix= logging_prefix
##
# The bucket's storage class. This defines how objects in the bucket are
# stored and determines the SLA and the cost of storage. Values include
# `STANDARD`, `NEARLINE`, and `COLDLINE`. `REGIONAL`,`MULTI_REGIONAL`,
# `STANDARD`, `NEARLINE`, `COLDLINE`, and `ARCHIVE`. `REGIONAL`,`MULTI_REGIONAL`,
# and `DURABLE_REDUCED_AVAILABILITY` are supported as legacy storage
# classes.
#
Expand All @@ -370,11 +370,11 @@ def storage_class
##
# Updates the bucket's storage class. This defines how objects in the
# bucket are stored and determines the SLA and the cost of storage.
# Accepted values include `:standard`, `:nearline`, and `:coldline`, as
# well as the equivalent strings returned by {Bucket#storage_class}.
# `:multi_regional`, `:regional`, and `durable_reduced_availability`
# are accepted as legacy storage classes. For more information, see
# [Storage
# Accepted values include `:standard`, `:nearline`, `:coldline`, and
# `:archive`, as well as the equivalent strings returned by
# {Bucket#storage_class}. `:multi_regional`, `:regional`, and
# `durable_reduced_availability` are accepted as legacy storage classes.
# For more information, see [Storage
# Classes](https://cloud.google.com/storage/docs/storage-classes).
#
# @param [Symbol, String] new_storage_class Storage class of the bucket.
Expand Down Expand Up @@ -1143,8 +1143,8 @@ def file path, generation: nil, skip_lookup: nil, encryption_key: nil
# @param [Symbol, String] storage_class Storage class of the file.
# Determines how the file is stored and determines the SLA and the
# cost of storage. Accepted values include `:standard`, `:nearline`,
# and `:coldline`, as well as the equivalent strings returned by
# {#storage_class}. `:multi_regional`, `:regional`, and
# `:coldline`, and `:archive`, as well as the equivalent strings
# returned by {#storage_class}. `:multi_regional`, `:regional`, and
# `durable_reduced_availability` are accepted legacy storage classes.
# For more information, see [Storage
# Classes](https://cloud.google.com/storage/docs/storage-classes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def changed?
# @param [String,Symbol,Array<String,Symbol>] matches_storage_class
# Files having any of the storage classes specified by this
# condition will be matched. Values include `STANDARD`, `NEARLINE`,
# and `COLDLINE`. `REGIONAL`,`MULTI_REGIONAL`, and
# `COLDLINE`, and `ARCHIVE`. `REGIONAL`,`MULTI_REGIONAL`, and
# `DURABLE_REDUCED_AVAILABILITY` are supported as legacy storage
# classes. Arguments will be converted from symbols and lower-case
# to upper-case strings.
Expand Down Expand Up @@ -162,7 +162,7 @@ def add_set_storage_class_rule storage_class, age: nil,
# @param [String,Symbol,Array<String,Symbol>] matches_storage_class
# Files having any of the storage classes specified by this
# condition will be matched. Values include `STANDARD`, `NEARLINE`,
# and `COLDLINE`. `REGIONAL`,`MULTI_REGIONAL`, and
# `COLDLINE`, and `ARCHIVE`. `REGIONAL`,`MULTI_REGIONAL`, and
# `DURABLE_REDUCED_AVAILABILITY` are supported as legacy storage
# classes. Arguments will be converted from symbols and lower-case
# to upper-case strings.
Expand Down Expand Up @@ -240,9 +240,9 @@ def freeze
# is `false`, it matches archived files.
# @attr [Array<String>] matches_storage_class Files having any of the
# storage classes specified by this condition will be matched.
# Values include `STANDARD`, `NEARLINE`, and `COLDLINE`. `REGIONAL`,
# `MULTI_REGIONAL`, and `DURABLE_REDUCED_AVAILABILITY` are supported
# as legacy storage classes.
# Values include `STANDARD`, `NEARLINE`, `COLDLINE`, and `ARCHIVE`.
# `REGIONAL`, `MULTI_REGIONAL`, and `DURABLE_REDUCED_AVAILABILITY`
# are supported as legacy storage classes.
# @attr [Integer] num_newer_versions Relevant only for versioned
# files. If the value is N, this condition is satisfied when there
# are at least N versions (including the live version) newer than
Expand Down
7 changes: 4 additions & 3 deletions google-cloud-storage/lib/google/cloud/storage/convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ module Convert
def storage_class_for str
return nil if str.nil?
return str.map { |s| storage_class_for s } if str.is_a? Array
{ "durable_reduced_availability" => "DURABLE_REDUCED_AVAILABILITY",
{ "archive" => "ARCHIVE",
"coldline" => "COLDLINE",
"dra" => "DURABLE_REDUCED_AVAILABILITY",
"durable" => "DURABLE_REDUCED_AVAILABILITY",
"nearline" => "NEARLINE",
"coldline" => "COLDLINE",
"durable_reduced_availability" => "DURABLE_REDUCED_AVAILABILITY",
"multi_regional" => "MULTI_REGIONAL",
"nearline" => "NEARLINE",
"regional" => "REGIONAL",
"standard" => "STANDARD" }[str.to_s.downcase] || str.to_s
end
Expand Down
1 change: 1 addition & 0 deletions google-cloud-storage/lib/google/cloud/storage/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ def storage_class
# * `:standard`
# * `:nearline`
# * `:coldline`
# * `:archive`
#
# as well as the equivalent strings returned by {File#storage_class} or
# {Bucket#storage_class}. For more information, see [Storage
Expand Down
4 changes: 2 additions & 2 deletions google-cloud-storage/lib/google/cloud/storage/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ def bucket bucket_name, skip_lookup: false, user_project: nil
# Logs](https://cloud.google.com/storage/docs/access-logs).
# @param [Symbol, String] storage_class Defines how objects in the
# bucket are stored and determines the SLA and the cost of storage.
# Accepted values include `:standard`, `:nearline`, and `:coldline`,
# as well as the equivalent strings returned by
# Accepted values include `:standard`, `:nearline`, `:coldline`, and
# `:archive`, as well as the equivalent strings returned by
# {Bucket#storage_class}. For more information, see [Storage
# Classes](https://cloud.google.com/storage/docs/storage-classes). The
# default value is the `:standard` storage class.
Expand Down
24 changes: 12 additions & 12 deletions google-cloud-storage/test/google/cloud/storage/file_update_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,43 +107,43 @@

it "updates its storage_class" do
mock = Minitest::Mock.new
patch_file_gapi = Google::Apis::StorageV1::Object.new storage_class: "DURABLE_REDUCED_AVAILABILITY"
patch_file_gapi = Google::Apis::StorageV1::Object.new storage_class: "NEARLINE"
patched_file_gapi = file_gapi.dup
patched_file_gapi.storage_class = "DURABLE_REDUCED_AVAILABILITY"
patched_file_gapi.storage_class = "NEARLINE"
mock.expect :rewrite_object, done_rewrite(patched_file_gapi),
[bucket_name, file.name, bucket_name, file.name, patch_file_gapi, destination_kms_key_name: nil, destination_predefined_acl: nil, source_generation: nil, rewrite_token: nil, user_project: nil, options: {}]

file.service.mocked_service = mock

file.storage_class.must_equal "STANDARD"
file.storage_class = :dra
file.storage_class.must_equal "DURABLE_REDUCED_AVAILABILITY"
file.storage_class = :nearline
file.storage_class.must_equal "NEARLINE"

mock.verify
end

it "updates its storage_class with user_project set to true" do
mock = Minitest::Mock.new
patch_file_gapi = Google::Apis::StorageV1::Object.new storage_class: "DURABLE_REDUCED_AVAILABILITY"
patch_file_gapi = Google::Apis::StorageV1::Object.new storage_class: "COLDLINE"
patched_file_gapi = file_gapi.dup
patched_file_gapi.storage_class = "DURABLE_REDUCED_AVAILABILITY"
patched_file_gapi.storage_class = "COLDLINE"
mock.expect :rewrite_object, done_rewrite(patched_file_gapi),
[bucket_name, file.name, bucket_name, file_user_project.name, patch_file_gapi, destination_kms_key_name: nil, destination_predefined_acl: nil, source_generation: nil, rewrite_token: nil, user_project: "test", options: {}]

file_user_project.service.mocked_service = mock

file_user_project.storage_class.must_equal "STANDARD"
file_user_project.storage_class = :dra
file_user_project.storage_class.must_equal "DURABLE_REDUCED_AVAILABILITY"
file_user_project.storage_class = :coldline
file_user_project.storage_class.must_equal "COLDLINE"

mock.verify
end

it "updates its storage_class, calling rewrite_object as many times as is needed" do
mock = Minitest::Mock.new
patch_file_gapi = Google::Apis::StorageV1::Object.new storage_class: "DURABLE_REDUCED_AVAILABILITY"
patch_file_gapi = Google::Apis::StorageV1::Object.new storage_class: "ARCHIVE"
patched_file_gapi = file_gapi.dup
patched_file_gapi.storage_class = "DURABLE_REDUCED_AVAILABILITY"
patched_file_gapi.storage_class = "ARCHIVE"
mock.expect :rewrite_object, undone_rewrite("notyetcomplete"),
[bucket_name, file.name, bucket_name, file.name, patch_file_gapi, destination_kms_key_name: nil, destination_predefined_acl: nil, source_generation: nil, rewrite_token: nil, user_project: nil, options: {}]
mock.expect :rewrite_object, undone_rewrite("keeptrying"),
Expand All @@ -160,8 +160,8 @@ def file.sleep *args
end

file.storage_class.must_equal "STANDARD"
file.storage_class = :dra
file.storage_class.must_equal "DURABLE_REDUCED_AVAILABILITY"
file.storage_class = :archive
file.storage_class.must_equal "ARCHIVE"

mock.verify
end
Expand Down