Skip to content

Commit

Permalink
Merge 1fa6e08 into c3bdaf6
Browse files Browse the repository at this point in the history
  • Loading branch information
justinlittman committed Jan 15, 2020
2 parents c3bdaf6 + 1fa6e08 commit 758c759
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
10 changes: 9 additions & 1 deletion app/lib/preservation_catalog/s3/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module S3
# Methods for auditing checking the state of a ZippedMoabVersion on an S3 endpoint. Requires AWS credentials are
# available in the environment. At the time of this comment, ONLY running queue workers will have proper creds loaded.
class Audit
delegate :bucket, :bucket_name, to: ::PreservationCatalog::S3
delegate :bucket_name, to: ::PreservationCatalog::S3

attr_reader :zmv, :results

Expand Down Expand Up @@ -72,6 +72,14 @@ def check_existence(aws_s3_object, part)
false
end
end

def bucket
endpoint = zmv.zip_endpoint.endpoint_name
::PreservationCatalog::S3.configure(region: Settings.zip_endpoints[endpoint].region,
access_key_id: Settings.zip_endpoints[endpoint].access_key_id,
secret_access_key: Settings.zip_endpoints[endpoint].secret_access_key)
::PreservationCatalog::S3.bucket
end
end
end
end
15 changes: 14 additions & 1 deletion spec/lib/preservation_catalog/s3/audit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
require 'rails_helper'

RSpec.describe PreservationCatalog::S3::Audit do
let(:zmv) { create(:zipped_moab_version) }
let(:zip_endpoint) do
ZipEndpoint.find_by(endpoint_name: 'aws_s3_west_2')
end
let(:zmv) do
create(:zipped_moab_version, zip_endpoint: zip_endpoint)
end
let(:cm) { zmv.complete_moab }
let(:bucket) { instance_double(Aws::S3::Bucket) }
let(:bucket_name) { "sul-sdr-us-west-bucket" }
Expand All @@ -16,6 +21,7 @@
allow(AuditResults).to receive(:new).and_return(results)
allow(PreservationCatalog::S3).to receive(:bucket).and_return(bucket)
allow(PreservationCatalog::S3).to receive(:bucket_name).and_return(bucket_name)
allow(PreservationCatalog::S3).to receive(:configure)
end

context 'some parts are unreplicated' do
Expand Down Expand Up @@ -45,6 +51,13 @@
.to change { ok_part.reload.last_existence_check }.from(nil)
.and change { ok_part.reload.last_checksum_validation }.from(nil)
end

it 'configures S3' do
described_class.check_replicated_zipped_moab_version(zmv, results)
expect(PreservationCatalog::S3).to have_received(:configure).with(region: 'us-west-2',
access_key_id: 'overridden-by-env-var-in-ci',
secret_access_key: 'overridden-by-env-var-in-ci')
end
end

context 'all parts listed as ok, but no parts exist on s3' do
Expand Down

0 comments on commit 758c759

Please sign in to comment.