From 456932595a3b86f1a20c6eda60bc410707e52092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Szajbe?= Date: Thu, 14 Jun 2012 10:42:05 +0200 Subject: [PATCH 1/3] accept --url option for a custom memprof.com application URL --- bin/memprof | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/bin/memprof b/bin/memprof index dc8dc27..51e2ac4 100755 --- a/bin/memprof +++ b/bin/memprof @@ -5,11 +5,8 @@ require 'optparse' require 'restclient' require 'term/ansicolor' -MEMPROF_URL = "https://memprof.com/upload" - MEMPROF_BANNER = <<-EOF Memprof Uploader -http://www.memprof.com ====================== EOF @@ -25,6 +22,7 @@ class MemprofUploader opts.on("-p", "--pid ", Integer, "PID of the process to dump (required)") {|arg| @pid = arg } opts.on("-n", "--name ", "Name for your dump (required)") {|arg| @name = arg } opts.on("-k", "--key ", "Memprof.com API key (required)") {|arg| @key = arg } + opts.on("-u", "--url ", "Memprof.com application URL (default https://memprof.com)") {|arg| @url = arg } opts.on("-d", "--[no-]delete", "Delete dump file after uploading (default true)") {|arg| @delete_dump = arg } opts.on("-s", "--seconds ", Integer, "Seconds to wait for the dump (default 300)") {|arg| @secs = arg } @@ -61,6 +59,10 @@ class MemprofUploader end end + # Make this default to https://memprof.com if the user didn't pass custom application URL. + @url ||= "https://memprof.com" + @upload_url = "#{@url}/upload" + # Make this default to true if the user didn't pass any preference. @delete_dump = true if @delete_dump.nil? @@ -142,8 +144,8 @@ class MemprofUploader file = File.open(filename, "r") - puts "\nUploading to memprof.com..." - response = RestClient.post(MEMPROF_URL, :upload => file, :name => name, :key => key) + puts "\nUploading to #{@url}..." + response = RestClient.post(@upload_url, :upload => file, :name => name, :key => key) puts "Response from server:" p response.to_s @@ -173,4 +175,4 @@ class MemprofUploader end -MemprofUploader.new(ARGV).run! \ No newline at end of file +MemprofUploader.new(ARGV).run! From 48871677f2e91434261135bae10d5a41cb824add Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Szajbe?= Date: Fri, 15 Jun 2012 11:34:01 +0200 Subject: [PATCH 2/3] fixed comment to reflect the actual code --- bin/memprof | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/memprof b/bin/memprof index 51e2ac4..f1fc378 100755 --- a/bin/memprof +++ b/bin/memprof @@ -66,7 +66,7 @@ class MemprofUploader # Make this default to true if the user didn't pass any preference. @delete_dump = true if @delete_dump.nil? - # Make this default to 60 if the user didn't pass the number of seconds. + # Make this default to 300 if the user didn't pass the number of seconds. @secs ||= 300 if @file From f4a62f85f4c1254605ee42b89253e35650f1a02d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Szajbe?= Date: Fri, 15 Jun 2012 11:39:15 +0200 Subject: [PATCH 3/3] validate --url option --- bin/memprof | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bin/memprof b/bin/memprof index f1fc378..55b7cef 100755 --- a/bin/memprof +++ b/bin/memprof @@ -61,6 +61,11 @@ class MemprofUploader # Make this default to https://memprof.com if the user didn't pass custom application URL. @url ||= "https://memprof.com" + + unless @url =~ /^https?:\/\/(([a-z0-9\-]+\.)+[a-z]{2,4}|(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}))(:\d+)?(\/.*)?$/i + fail_with("#{@url} does not look like a correct URL") + end + @upload_url = "#{@url}/upload" # Make this default to true if the user didn't pass any preference.