diff options
author | Jan Provaznik <jprovaznik@gitlab.com> | 2018-12-21 12:16:15 +0100 |
---|---|---|
committer | Jan Provaznik <jprovaznik@gitlab.com> | 2018-12-27 11:06:06 +0100 |
commit | 2bfc317492f0a5918c4861203f3eedf71b2627aa (patch) | |
tree | 852793689891b2d9e08922bfe6a8c9b6f874eb2f | |
parent | e242c8cd6b32f405c5734f9c3a61c48e746c30f1 (diff) | |
download | gitlab-ce-2bfc317492f0a5918c4861203f3eedf71b2627aa.tar.gz |
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
-rw-r--r-- | changelogs/unreleased/s3-directories-get.yml | 6 | ||||
-rw-r--r-- | lib/gitlab/cleanup/remote_uploads.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/cleanup/remote_uploads_spec.rb | 2 |
3 files changed, 8 insertions, 2 deletions
diff --git a/changelogs/unreleased/s3-directories-get.yml b/changelogs/unreleased/s3-directories-get.yml new file mode 100644 index 00000000000..9f76af2bb09 --- /dev/null +++ b/changelogs/unreleased/s3-directories-get.yml @@ -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 diff --git a/lib/gitlab/cleanup/remote_uploads.rb b/lib/gitlab/cleanup/remote_uploads.rb index eba1faacc3a..03298d960a4 100644 --- a/lib/gitlab/cleanup/remote_uploads.rb +++ b/lib/gitlab/cleanup/remote_uploads.rb @@ -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 diff --git a/spec/lib/gitlab/cleanup/remote_uploads_spec.rb b/spec/lib/gitlab/cleanup/remote_uploads_spec.rb index 8d03baeb07b..35642cd6e50 100644 --- a/spec/lib/gitlab/cleanup/remote_uploads_spec.rb +++ b/spec/lib/gitlab/cleanup/remote_uploads_spec.rb @@ -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 |