Class: S3Ranger::CLI::Url
- Inherits:
-
CmdParse::Command
- Object
- CmdParse::Command
- 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
Constructor Details
#initialize ⇒ Url
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/s3ranger/cli.rb', line 144 def initialize super 'url', false, false @short_desc = "Generates a url pointing to the given key" @method = 'read' @secure = true @expires_in = false self. = CmdParse::OptionParserWrapper.new do |opt| opt.on("-m", "--method", "Options: #{AVAILABLE_METHODS.join ', '}") {|m| @method = m } 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.
141 142 143 |
# File 'lib/s3ranger/cli.rb', line 141 def method @method end |
#secure ⇒ Object
Returns the value of attribute secure.
142 143 144 |
# File 'lib/s3ranger/cli.rb', line 142 def secure @secure end |
Instance Method Details
#run(s3, bucket, key, file, args) ⇒ Object
179 180 181 182 183 184 185 186 187 188 |
# File 'lib/s3ranger/cli.rb', line 179 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, "Unknown method #{@method}") unless AVAILABLE_METHODS.include? @method opts = {} opts.merge!({:secure => @secure}) opts.merge!({:expires => @expires_in}) if @expires_in puts (s3.buckets[bucket].objects[key].url_for @method.to_sym, opts).to_s end |