Skip to content

Commit f22d0a3

Browse files
authored
Merge pull request #299 from emilymye/storage_fileget
Fix arguments for storage list_objects and enable :prefix
2 parents 4647ce1 + 41445b6 commit f22d0a3

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

lib/fog/storage/google_json/models/directories.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@ def get(bucket_name, options = {})
2121
:projection => projection
2222
).to_h
2323

24-
new(data)
24+
directory = new(data)
25+
# Because fog-aws accepts these arguments on files at the
26+
# directories.get level, we need to preload the directory files
27+
# with these attributes here.
28+
files_attr_names = %i(delimiter page_token max_results prefix)
29+
30+
file_opts = options.select { |k, _| files_attr_names.include? k }
31+
directory.files(file_opts)
32+
directory
2533
rescue ::Google::Apis::ClientError => e
2634
# metageneration check failures returns HTTP 412 Precondition Failed
2735
raise e unless e.status_code == 404 || e.status_code == 412

lib/fog/storage/google_json/models/directory.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,10 @@ def destroy
3737
false
3838
end
3939

40-
def files
40+
def files(attr = {})
4141
@files ||= begin
4242
Fog::Storage::GoogleJSON::Files.new(
43-
:directory => self,
44-
:service => service
43+
attr.merge(:directory => self, :service => service)
4544
)
4645
end
4746
end

lib/fog/storage/google_json/models/files.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class Files < Fog::Collection
1616

1717
def all(options = {})
1818
requires :directory
19-
20-
data = service.list_objects(directory.key, options).to_h[:items] || []
19+
data = service.list_objects(directory.key, attributes.merge(options))
20+
.to_h[:items] || []
2121
load(data)
2222
end
2323

lib/fog/storage/google_json/requests/list_objects.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,19 @@ class Real
2020
# object as distinct results (defaults to False)
2121
# @return [Google::Apis::StorageV1::Objects]
2222
def list_objects(bucket, options = {})
23-
request_options = ::Google::Apis::RequestOptions.default.merge(options)
24-
@storage_json.list_objects(bucket, :options => request_options)
23+
allowed_opts = %i(
24+
delimiter
25+
max_results
26+
page_token
27+
prefix
28+
projection
29+
versions
30+
)
31+
32+
@storage_json.list_objects(
33+
bucket,
34+
options.select { |k, _| allowed_opts.include? k }
35+
)
2536
end
2637
end
2738

0 commit comments

Comments
 (0)