Class: S3Ranger::CLI::Url
- Defined in:
- lib/s3ranger/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
#has_options?, #has_prefix?, #usage
Constructor Details
#initialize ⇒ Url
Returns a new instance of Url.
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/s3ranger/cli.rb', line 213 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.
210 211 212 |
# File 'lib/s3ranger/cli.rb', line 210 def method @method end |
#secure ⇒ Object
Returns the value of attribute secure.
211 212 213 |
# File 'lib/s3ranger/cli.rb', line 211 def secure @secure end |
Instance Method Details
#run(s3, bucket, key, file, args) ⇒ Object
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/s3ranger/cli.rb', line 255 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 |