Class: S3Sync::CLI::Url
- Defined in:
- lib/s3sync/cli.rb
Instance Attribute Summary collapse
-
#method ⇒ Object
Returns the value of attribute method.
-
#secure ⇒ Object
Returns the value of attribute secure.
Instance Method Summary collapse
-
#initialize ⇒ Url
constructor
A new instance of Url.
- #run(s3, bucket, key, file, args) ⇒ Object
Methods inherited from BaseCmd
#execute, #has_options?, #has_prefix?, #usage
Constructor Details
#initialize ⇒ Url
Returns a new instance of Url.
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/s3sync/cli.rb', line 244 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. = 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 |
Instance Attribute Details
#method ⇒ Object
Returns the value of attribute method.
241 242 243 |
# File 'lib/s3sync/cli.rb', line 241 def method @method end |
#secure ⇒ Object
Returns the value of attribute secure.
242 243 244 |
# File 'lib/s3sync/cli.rb', line 242 def secure @secure end |
Instance Method Details
#run(s3, bucket, key, file, args) ⇒ Object
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
# File 'lib/s3sync/cli.rb', line 286 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 |