class S3Ranger::CLI::Url
Attributes
method[RW]
secure[RW]
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/s3ranger/cli.rb, line 218 def initialize super 'url', false, false @short_desc = "Generates public urls or authenticated endpoints for the object" @description = "Notice that --method and --public are mutually exclusive" @method = false @public = false @secure = true @expires_in = false @has_prefix = 'required' self.options = CmdParse::OptionParserWrapper.new do |opt| opt.on("-m", "--method=METHOD", "Options: #{AVAILABLE_METHODS.join ', '}") {|m| @method = m } opt.on("-p", "--public", "Generates a public (not authenticated) URL for the object") {|p| @public = p } opt.on("--no-ssl", "Generate an HTTP link, no HTTPS") { @secure = false } opt.on("--expires-in=EXPR", "How long the link takes to expire. Format: <# of seconds> | [#d|#h|#m|#s]") { |expr| val = 0 expr.scan(/(\d+\w)/) do |track| _, num, what = /(\d+)(\w)/.match(track[0]).to_a num = num.to_i case what when "d"; val += num * 86400 when "h"; val += num * 3600 when "m"; val += num * 60 when "s"; val += num end end @expires_in = val > 0 ? val : expr.to_i } end end
Public Instance Methods
run(s3, bucket, key, file, args)
click to toggle source
# File lib/s3ranger/cli.rb, line 260 def run s3, bucket, key, file, args raise WrongUsage.new(nil, "You need to inform a bucket") if not bucket raise WrongUsage.new(nil, "You need to inform a key") if not key raise WrongUsage.new(nil, "Params --method and --public are mutually exclusive") if (@method and @public) if not AVAILABLE_METHODS.include? method = @method || 'read' raise WrongUsage.new(nil, "Unknown method #{method}") end opts = {} opts.merge!({:secure => @secure}) if @public puts s3.buckets[bucket].objects[key].public_url(opts).to_s else opts.merge!({:expires => @expires_in}) if @expires_in puts s3.buckets[bucket].objects[key].url_for(method.to_sym, opts).to_s end end