Skip to content

Commit

Permalink
feature: s3 timeout flag
Browse files Browse the repository at this point in the history
The -t flag in Glitter passes an optional timeout to the S3 server. This
is useful for uploads that exceed the default timeout of 60 seconds.
  • Loading branch information
Teyler7 committed May 12, 2022
1 parent e0c302d commit a5dc167
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
5 changes: 3 additions & 2 deletions lib/glitter/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -52,7 +53,7 @@ def channel
end

def server
@server ||= Server.new
@server ||= Server.new(timeout: options.timeout)
end
end
end
15 changes: 10 additions & 5 deletions lib/glitter/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
end
21 changes: 14 additions & 7 deletions spec/lib/glitter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit a5dc167

Please sign in to comment.