Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Able to set custom AWS S3 settings for coverband #98

Merged
merged 1 commit into from
Jul 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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