diff --git a/lib/glitter/cli.rb b/lib/glitter/cli.rb index 75d0fa5..347f5f7 100644 --- a/lib/glitter/cli.rb +++ b/lib/glitter/cli.rb @@ -7,9 +7,10 @@ class CLI < Thor method_option :version, :type => :string, :aliases => "-v", :required => true method_option :channel, :type => :string, :aliases => "-c", :required => true method_option :notes, :type => :string, :aliases => "-n" - method_option :force, :type => :boolean, :aliases => "-f" method_option :bundle_version, :type => :string, :aliases => "-b" method_option :minimum_system_version, :type => :string, :aliases => "-m" + method_option :force, :type => :boolean, :aliases => "-f" + method_option :timeout, :type => :numeric, :aliases => "-t", :default => Server::DEFAULT_S3_TIMEOUT def push(executable_path, *asset_paths) release = Release::Sparkle.new(channel, options.version) release.minimum_system_version = options.minimum_system_version @@ -52,7 +53,7 @@ def channel end def server - @server ||= Server.new + @server ||= Server.new(timeout: options.timeout) end end end diff --git a/lib/glitter/server.rb b/lib/glitter/server.rb index 80b4951..aab125d 100644 --- a/lib/glitter/server.rb +++ b/lib/glitter/server.rb @@ -5,10 +5,15 @@ # contain multiple releases of software. module Glitter class Server - attr_reader :access_key_id, :secret_access_key, :bucket_name + attr_reader :access_key_id, :secret_access_key, :bucket_name, :timeout - def initialize(access_key_id = ENV['AWS_ACCESS_KEY_ID'], secret_access_key = ENV['AWS_SECRET_ACCESS_KEY'], bucket_name = ENV['AWS_BUCKET_NAME']) - @access_key_id, @secret_access_key, @bucket_name = access_key_id, secret_access_key, bucket_name + DEFAULT_S3_TIMEOUT = 60 + + def initialize(access_key_id = ENV['AWS_ACCESS_KEY_ID'], secret_access_key = ENV['AWS_SECRET_ACCESS_KEY'], bucket_name = ENV['AWS_BUCKET_NAME'], timeout: DEFAULT_S3_TIMEOUT) + @access_key_id = access_key_id + @secret_access_key = secret_access_key + @bucket_name = bucket_name + @timeout = timeout end def channel(name) @@ -35,7 +40,7 @@ def channels end def s3 - @s3 ||= ::S3::Service.new(:access_key_id => access_key_id, :secret_access_key => secret_access_key, :use_ssl => true) + @s3 ||= ::S3::Service.new(access_key_id: access_key_id, secret_access_key: secret_access_key, timeout: timeout, use_ssl: true) end end -end \ No newline at end of file +end diff --git a/spec/lib/glitter_spec.rb b/spec/lib/glitter_spec.rb index 361ed90..10d3268 100644 --- a/spec/lib/glitter_spec.rb +++ b/spec/lib/glitter_spec.rb @@ -6,13 +6,11 @@ Glitter::Server.new end - # Note that running this spec *will* upload a single file to your S3 bucket - it "should release to channel" do - Glitter::Release::Sparkle.new server.channel('test-channel'), "1.1.2-#{rand}" do |r| - r.executable = File.open(__FILE__) - r.notes = %[Did you know that its #{Time.now}? Wait, you can only answer yes to that question.] - r.minimum_system_version = "10.10" - end.push.head + it "Glitter takes in an optional -t flag and passes the proper timeout to S3" do + server = Glitter::Server.new() # no timeout passed in + expect(server.timeout).to eq Glitter::Server::DEFAULT_S3_TIMEOUT + server = Glitter::Server.new(timeout: 10) # timeout passed in + expect(server.timeout).to eq 10 end it "AWS path segments are parsed correctly for an item at top level of version folder" do @@ -29,3 +27,12 @@ expect(key).to eq("some-dir/some-item") end end + + # # Note that uncommenting and running this spec *will* upload a single file to your S3 bucket + # it "should release to channel" do + # Glitter::Release::Sparkle.new server.channel('test-channel'), "1.1.2-#{rand}" do |r| + # r.executable = File.open(__FILE__) + # r.notes = %[Did you know that its #{Time.now}? Wait, you can only answer yes to that question.] + # r.minimum_system_version = "10.10" + # end.push.head + # end