Skip to content

Commit

Permalink
feat(cloud-storage): support match_glob for Object.list
Browse files Browse the repository at this point in the history
Introduce `match_glob` parameter to `Bucket.files, with required changes to the service method and storing instance variables for pagination in `File::List`.

Updating gem to Ruby v2.7 as current supported version.

More info at https://cloud.google.com/storage/docs/json_api/v1/objects/list
  • Loading branch information
aandreassa committed Nov 10, 2023
1 parent 9a97018 commit aeb8329
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: '2.6'
ruby-version: '3.2'
- run: ruby --version
- run: bundle install
- run: bundle exec rake conformance
Expand Down
2 changes: 1 addition & 1 deletion google-cloud-storage/google-cloud-storage.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
["OVERVIEW.md", "AUTHENTICATION.md", "LOGGING.md", "CONTRIBUTING.md", "TROUBLESHOOTING.md", "CHANGELOG.md", "CODE_OF_CONDUCT.md", "LICENSE", ".yardopts"]
gem.require_paths = ["lib"]

gem.required_ruby_version = ">= 2.5"
gem.required_ruby_version = ">= 2.7"

gem.add_dependency "google-cloud-core", "~> 1.6"
gem.add_dependency "google-apis-iamcredentials_v1", "~> 0.1"
Expand Down
12 changes: 9 additions & 3 deletions google-cloud-storage/lib/google/cloud/storage/bucket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,9 @@ def delete if_metageneration_match: nil, if_metageneration_not_match: nil
# `prefixes` are omitted.
# @param [String] token A previously-returned page token representing
# part of the larger set of results to view.
# @param [String] match_glob A glob pattern used to filter results returned in items (e.g. `foo*bar`).
# The string value must be UTF-8 encoded. See:
# https://cloud.google.com/storage/docs/json_api/v1/objects/list#list-object-glob
# @param [Integer] max Maximum number of items plus prefixes to return.
# As duplicate prefixes are omitted, fewer total results may be
# returned than requested. The default value of this parameter is
Expand Down Expand Up @@ -1334,14 +1337,17 @@ def delete if_metageneration_match: nil, if_metageneration_not_match: nil
# end
#
def files prefix: nil, delimiter: nil, token: nil, max: nil,
versions: nil
versions: nil, match_glob: nil
ensure_service!
gapi = service.list_files name, prefix: prefix, delimiter: delimiter,
token: token, max: max,
versions: versions,
user_project: user_project
user_project: user_project,
match_glob: match_glob
File::List.from_gapi gapi, service, name, prefix, delimiter, max,
versions, user_project: user_project
versions,
user_project: user_project,
match_glob: match_glob
end
alias find_files files

Expand Down
10 changes: 7 additions & 3 deletions google-cloud-storage/lib/google/cloud/storage/file/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ def next
token: @token,
max: @max,
versions: @versions,
user_project: @user_project
user_project: @user_project,
match_glob: @match_glob
File::List.from_gapi gapi, @service, @bucket, @prefix,
@delimiter, @max, @versions,
user_project: @user_project
user_project: @user_project,
match_glob: @match_glob
end

##
Expand Down Expand Up @@ -163,7 +165,8 @@ def all request_limit: nil, &block
# Google::Apis::StorageV1::Objects object.
def self.from_gapi gapi_list, service, bucket = nil, prefix = nil,
delimiter = nil, max = nil, versions = nil,
user_project: nil
user_project: nil,
match_glob: nil
files = new(Array(gapi_list.items).map do |gapi_object|
File.from_gapi gapi_object, service, user_project: user_project
end)
Expand All @@ -176,6 +179,7 @@ def self.from_gapi gapi_list, service, bucket = nil, prefix = nil,
files.instance_variable_set :@max, max
files.instance_variable_set :@versions, versions
files.instance_variable_set :@user_project, user_project
files.instance_variable_set :@match_glob, match_glob
files
end

Expand Down
2 changes: 2 additions & 0 deletions google-cloud-storage/lib/google/cloud/storage/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,15 @@ def delete_notification bucket_name, notification_id, user_project: nil, options
# Retrieves a list of files matching the criteria.
def list_files bucket_name, delimiter: nil, max: nil, token: nil,
prefix: nil, versions: nil, user_project: nil,
match_glob: nil,
options: {}
execute do
service.list_objects \
bucket_name, delimiter: delimiter, max_results: max,
page_token: token, prefix: prefix,
versions: versions,
user_project: user_project(user_project),
match_glob: match_glob,
options: options
end
end
Expand Down
Loading

0 comments on commit aeb8329

Please sign in to comment.