Use directories.new when getting S3 directory

Calling `Fog::Storage::AWS::Directories#get` requires the
ListAllMyBuckets permission, but we can avoid that extra query and
permission by initializing the directory with a specific bucket:
https://stackoverflow.com/a/12288581/1992201
This commit is contained in:
Jan Provaznik 2018-12-21 12:16:15 +01:00
parent e242c8cd6b
commit 2bfc317492
3 changed files with 8 additions and 2 deletions

View file

@ -0,0 +1,6 @@
---
title: Allow 'rake gitlab:cleanup:remote_upload_files' to read bucket files without
having permissions to see all buckets.
merge_request: 23981
author:
type: fixed

View file

@ -67,7 +67,7 @@ module Gitlab
end
def remote_directory
connection.directories.get(configuration['remote_directory'])
connection.directories.new(key: configuration['remote_directory'])
end
def connection

View file

@ -25,7 +25,7 @@ describe Gitlab::Cleanup::RemoteUploads do
expect(::Fog::Storage).to receive(:new).and_return(connection)
expect(connection).to receive(:directories).and_return(double(get: directory))
expect(connection).to receive(:directories).and_return(double(new: directory))
expect(directory).to receive(:files).and_return(remote_files)
end