Skip to content

Commit

Permalink
Able to set custom AWS S3 settings for coverband
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Osenenko committed Feb 26, 2018
1 parent 56aef29 commit dfe76f5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/coverband/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ class Configuration
attr_accessor :redis, :root_paths, :root,
:ignore, :additional_files, :percentage, :verbose, :reporter,
:stats, :logger, :startup_delay, :trace_point_events,
:include_gems, :memory_caching, :s3_bucket, :coverage_file, :store,
:disable_on_failure_for
:include_gems, :memory_caching, :coverage_file, :store, :disable_on_failure_for,
:s3_bucket, :s3_region, :s3_access_key_id, :s3_secret_access_key

# deprecated, but leaving to allow old configs to 'just work'
# remove for 2.0
Expand Down
7 changes: 6 additions & 1 deletion lib/coverband/reporters/simple_cov_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ def self.report(store, options = {})
Coverband.configuration.logger.info "report is ready and viewable: open #{SimpleCov.coverage_dir}/index.html"
end

S3ReportWriter.new(Coverband.configuration.s3_bucket).persist! if Coverband.configuration.s3_bucket
s3_writer_options = {
region: Coverband.configuration.s3_region,
access_key_id: Coverband.configuration.s3_access_key_id,
secret_access_key: Coverband.configuration.s3_secret_access_key
}
S3ReportWriter.new(Coverband.configuration.s3_bucket, s3_writer_options).persist! if Coverband.configuration.s3_bucket
end

end
Expand Down
14 changes: 12 additions & 2 deletions lib/coverband/s3_report_writer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
class S3ReportWriter

def initialize(bucket_name)
def initialize(bucket_name, options = {})
@bucket_name = bucket_name
@region = options[:region]
@access_key_id = options[:access_key_id]
@secret_access_key = options[:secret_access_key]
begin
require 'aws-sdk'
rescue
Expand Down Expand Up @@ -29,7 +32,14 @@ def object
end

def s3
Aws::S3::Resource.new
client_options = {
region: @region,
access_key_id: @access_key_id,
secret_access_key: @secret_access_key
}
resource_options = { client: Aws::S3::Client.new(client_options) }
resource_options = {} if client_options.values.any?(&:nil?)
Aws::S3::Resource.new(resource_options)
end

def bucket
Expand Down
11 changes: 9 additions & 2 deletions lib/coverband/s3_web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@ class S3Web < Sinatra::Base
private

def s3
@s3 ||= Aws::S3::Client.new
@s3 ||= begin
client_options = {
region: Coverband.configuration.s3_region,
access_key_id: Coverband.configuration.s3_access_key_id,
secret_access_key: Coverband.configuration.s3_secret_access_key
}
client_options = {} if client_options.values.any?(&:nil?)
Aws::S3::Client.new(client_options)
end
end

end

end

0 comments on commit dfe76f5

Please sign in to comment.