http_cannon 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/bin/http_cannon +257 -0
- data/http_cannon.gemspec +37 -0
- data/lib/http_cannon.rb +1 -0
- data/lib/http_cannon/version.rb +3 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a3d891289a6329927fbb08d756f3d141260afd3e
|
4
|
+
data.tar.gz: 40d3a760e7659bea427a4c0d79896ccaa375aad4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cb307aabe4c766ce505312d408b9a9d817cf179dbe7365eb5042b959d868f485945db28a2e4ccb53f040ca89108ed1b4f298c58dcaa15fa95080530e1d7a7e38
|
7
|
+
data.tar.gz: ae07bb451049378e4bd86931c9e449dcfef25aa86484bcc95d512cb1fd3582cee6389ed1fbaff6dc53ab8296647ab7a960d8c45e6799ca24cf7cdc40771390b6
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 arch4ngel
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# HttpCannon
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/http_cannon`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'http_cannon'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install http_cannon
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/http_cannon.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/http_cannon
ADDED
@@ -0,0 +1,257 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'net/https'
|
4
|
+
require 'json'
|
5
|
+
require 'base64'
|
6
|
+
require 'aastdlib'
|
7
|
+
require 'thor'
|
8
|
+
|
9
|
+
class Interface < Thor
|
10
|
+
|
11
|
+
req_struct = %^
|
12
|
+
{
|
13
|
+
# just the request uri
|
14
|
+
"http_uri":"https://www.someuri.com/with_resource?and_query=string"
|
15
|
+
|
16
|
+
# this can be any method, really
|
17
|
+
# no need to concern yourself with case or formatting
|
18
|
+
# spelling matters, of course
|
19
|
+
"http_method":"Get",
|
20
|
+
|
21
|
+
# http headers required for the request
|
22
|
+
"http_headers": {
|
23
|
+
"Content-Type": "application/json"
|
24
|
+
},
|
25
|
+
|
26
|
+
# Base64 encoded http body
|
27
|
+
"http_body": "aHR0cCBib2R5IHZhbHVl"
|
28
|
+
}^
|
29
|
+
|
30
|
+
long_desc = "Load the array of JSON objects and send all requests. Request Structure:\n"+req_struct
|
31
|
+
|
32
|
+
desc "fire", long_desc
|
33
|
+
|
34
|
+
option :input_file,
|
35
|
+
aliases: ["-i"],
|
36
|
+
required: true,
|
37
|
+
type: :string,
|
38
|
+
desc: "JSON file containing an array of requests."
|
39
|
+
|
40
|
+
option :ssl_verify,
|
41
|
+
required: false,
|
42
|
+
type: :boolean,
|
43
|
+
default: false,
|
44
|
+
desc: "Enable/disable verification of the service SSL certificate"
|
45
|
+
|
46
|
+
option :proxy_host,
|
47
|
+
required: false,
|
48
|
+
type: :string,
|
49
|
+
desc: "IP address or friendly name of an HTTP proxy"
|
50
|
+
|
51
|
+
option :proxy_port,
|
52
|
+
required: false,
|
53
|
+
type: :numeric,
|
54
|
+
desc: "Port number of the HTTP proxy"
|
55
|
+
|
56
|
+
option :throttle,
|
57
|
+
aliases: ["-t"],
|
58
|
+
required: false,
|
59
|
+
type: :numeric,
|
60
|
+
desc: "Throttle request time by n seconds. Also accepts floating point numbers (e.g. 1.8)"
|
61
|
+
|
62
|
+
option :verbose,
|
63
|
+
required: false,
|
64
|
+
type: :boolean,
|
65
|
+
default: false,
|
66
|
+
desc: "Be more verbose while making the requests. Error messages are more verbose as well."
|
67
|
+
|
68
|
+
def fire()
|
69
|
+
|
70
|
+
# dynamically define error classes
|
71
|
+
{
|
72
|
+
CannonHTTPMethodError: "Invalid HTTP method provided",
|
73
|
+
CannonHTTPURIError: "Invalid HTTP uri provided",
|
74
|
+
CannonHTTPBodyError: "Invalid HTTP body provided",
|
75
|
+
CannonHTTPHeaderError: "Invalid HTTP header provided"
|
76
|
+
}.each do |klass,message|
|
77
|
+
|
78
|
+
Object::const_set(klass,Class.new(StandardError))
|
79
|
+
.send(:define_method, :message, Proc.new {return message} )
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
$input_file_name = options[:input_file]
|
84
|
+
$proxy_host = options[:proxy_host]
|
85
|
+
$proxy_port = options[:proxy_port]
|
86
|
+
$verbose = options[:verbose]
|
87
|
+
$ssl_verify = options[:ssl_verify]
|
88
|
+
$throttle = options[:throttle]
|
89
|
+
|
90
|
+
fire_cannon()
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
# verbosely communicate error message to user
|
97
|
+
def verbose_error(error)
|
98
|
+
|
99
|
+
puts
|
100
|
+
puts "\t"+error.message
|
101
|
+
puts error.backtrace.map!{|l| "\t\t"+l}
|
102
|
+
puts
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
def fire_cannon()
|
107
|
+
|
108
|
+
payloads = nil
|
109
|
+
File::check_and_open($input_file_name) { |f| payloads = f.read() }
|
110
|
+
payloads = JSON::parse(payloads)
|
111
|
+
|
112
|
+
counter = 0
|
113
|
+
payloads.each do |payload|
|
114
|
+
|
115
|
+
begin
|
116
|
+
|
117
|
+
# parse the json payload
|
118
|
+
payload = JSON::parse(payload)
|
119
|
+
|
120
|
+
# convenience variables
|
121
|
+
uri = payload["http_uri"]
|
122
|
+
meth = payload["http_method"]
|
123
|
+
headers = payload["http_headers"]
|
124
|
+
body = payload["http_body"]
|
125
|
+
|
126
|
+
# create a URI object
|
127
|
+
uri = URI(uri)
|
128
|
+
|
129
|
+
# flag used to determine if ssl should be used
|
130
|
+
uri.scheme =~ /https/i ? use_ssl = true : use_ssl = false
|
131
|
+
|
132
|
+
# handle the http method
|
133
|
+
# capitalize the method name, e.g. sTuFF => Stuff
|
134
|
+
# convert the name to a symbol
|
135
|
+
meth = meth.capitalize.to_sym
|
136
|
+
|
137
|
+
# alert user of unsupported http method provided
|
138
|
+
raise(CannonHTTPMethodError) if !Net::HTTP::constants.include?(meth)
|
139
|
+
|
140
|
+
# derive a request object from the method name
|
141
|
+
req = Net::HTTP::const_get(meth).new(uri)
|
142
|
+
|
143
|
+
# handling http headers
|
144
|
+
if headers
|
145
|
+
|
146
|
+
if headers.respond_to?(:each)
|
147
|
+
|
148
|
+
headers.each { |k,v| req[k] = v }
|
149
|
+
|
150
|
+
else
|
151
|
+
|
152
|
+
raise(CannonHTTPHeaderError)
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
|
158
|
+
# handling the http body
|
159
|
+
body = Base64::decode64(body) if body
|
160
|
+
|
161
|
+
if use_ssl and !$ssl_verify
|
162
|
+
|
163
|
+
ssl_verify_mode = OpenSSL::SSL::VERIFY_NONE
|
164
|
+
|
165
|
+
else
|
166
|
+
|
167
|
+
ssl_verify_mode = OpenSSL::SSL::VERIFY_PEER
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
# make the http request
|
172
|
+
Net::HTTP::start(uri.host, uri.port, $proxy_host, $proxy_port, {use_ssl: use_ssl, verify_mode: ssl_verify_mode}) do |http|
|
173
|
+
|
174
|
+
# disable certificate verification
|
175
|
+
# http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
176
|
+
|
177
|
+
puts "Request #: #{counter}".prefix()
|
178
|
+
print "\tHTTP Method: "
|
179
|
+
puts req.method
|
180
|
+
print "\tRequest Body: "
|
181
|
+
|
182
|
+
if req.body
|
183
|
+
|
184
|
+
puts true.to_s.capitalize
|
185
|
+
|
186
|
+
else
|
187
|
+
|
188
|
+
puts false.to_s.capitalize
|
189
|
+
|
190
|
+
end
|
191
|
+
|
192
|
+
print "\tResponse: "
|
193
|
+
|
194
|
+
# send the request
|
195
|
+
response = http.request(req)
|
196
|
+
|
197
|
+
puts "#{response.code} -> #{response.message}"
|
198
|
+
|
199
|
+
# sleep for throttle time
|
200
|
+
if $throttle
|
201
|
+
|
202
|
+
puts
|
203
|
+
print "Sleeping for #{$throttle} seconds...".prefix()
|
204
|
+
sleep($throttle)
|
205
|
+
puts "done"
|
206
|
+
puts
|
207
|
+
|
208
|
+
end
|
209
|
+
|
210
|
+
end
|
211
|
+
|
212
|
+
rescue => error
|
213
|
+
|
214
|
+
case error
|
215
|
+
|
216
|
+
when CannonHTTPHeaderError, CannonHTTPBodyError,
|
217
|
+
CannonHTTPURIError, CannonHTTPMethodError
|
218
|
+
|
219
|
+
puts "Warning: #{error.message}".prefix()
|
220
|
+
puts "Skipping to next request".prefix()
|
221
|
+
verbose_error(error) if $verbose
|
222
|
+
next
|
223
|
+
|
224
|
+
when URI::Error
|
225
|
+
|
226
|
+
puts "Warning: Invalid URI provided."
|
227
|
+
puts "Skipping to next request".prefix()
|
228
|
+
verbose_error(error) if $verbose
|
229
|
+
next
|
230
|
+
|
231
|
+
when Net::HTTPExceptions
|
232
|
+
|
233
|
+
puts "Warning: HTTP error."
|
234
|
+
puts "Skipping to next request".prefix()
|
235
|
+
verbose_error(error) if $verbose
|
236
|
+
next
|
237
|
+
|
238
|
+
else
|
239
|
+
|
240
|
+
puts "Error: Unhandled exception occurred. Exiting!"
|
241
|
+
puts error.message
|
242
|
+
puts error.backtrace
|
243
|
+
exit
|
244
|
+
|
245
|
+
end
|
246
|
+
|
247
|
+
end
|
248
|
+
|
249
|
+
counter += 1
|
250
|
+
|
251
|
+
end
|
252
|
+
|
253
|
+
end
|
254
|
+
|
255
|
+
puts
|
256
|
+
Interface.start(ARGV)
|
257
|
+
puts
|
data/http_cannon.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "http_cannon/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "http_cannon"
|
8
|
+
spec.version = HttpCannon::VERSION
|
9
|
+
spec.authors = ["arch4ngel"]
|
10
|
+
spec.email = ["justinangel86@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Accepts an input file of JSON data structures and uses them as HTTP requests.}
|
13
|
+
spec.homepage = "https://github.com/arch4ngel/http_cannon"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
22
|
+
"public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
spec.bindir = "bin"
|
29
|
+
spec.executables = ["http_cannon"]
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
35
|
+
spec.add_dependency("thor")
|
36
|
+
spec.add_dependency("aastdlib")
|
37
|
+
end
|
data/lib/http_cannon.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'http_cannon/version'
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: http_cannon
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- arch4ngel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: thor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: aastdlib
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- justinangel86@gmail.com
|
86
|
+
executables:
|
87
|
+
- http_cannon
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/http_cannon
|
99
|
+
- http_cannon.gemspec
|
100
|
+
- lib/http_cannon.rb
|
101
|
+
- lib/http_cannon/version.rb
|
102
|
+
homepage: https://github.com/arch4ngel/http_cannon
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata:
|
106
|
+
allowed_push_host: https://rubygems.org
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.5.2
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: Accepts an input file of JSON data structures and uses them as HTTP requests.
|
127
|
+
test_files: []
|