apidragon 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.gitignore +4 -0
- data/Gemfile +21 -0
- data/Gemfile.lock +162 -0
- data/LICENSE.txt +20 -0
- data/README.md +69 -0
- data/README.rdoc +19 -0
- data/Rakefile +67 -0
- data/VERSION +1 -0
- data/bin/apidragon +22 -0
- data/lib/apidragon/api.rb +64 -0
- data/lib/apidragon/argbucket.rb +11 -0
- data/lib/apidragon/macro.rb +100 -0
- data/lib/apidragon/parser.rb +50 -0
- data/lib/apidragon.rb +2 -0
- data/test/helper.rb +34 -0
- data/test/test_apidragon.rb +7 -0
- metadata +288 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 38bbb98f2693cfd20b275f179ba287752f9bd5a5
|
4
|
+
data.tar.gz: 33eeb13c49ba6ad6c651da61eee20dd084e08d1b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3e830311e1b39982d0431a0d992ab62f6b1828a024acdb651f3182825180003a57de0a720b94c7f3cdb03a9b41a3211b9b8a38e1496bb6fd9ef65887d2751cb7
|
7
|
+
data.tar.gz: 0fb84f33bbdba04fbe8d9e3a4bb34a120248d514cdd7d99b8f7a41d5e08b48c078f319ec75f4edaf2743833eba06fcc582e610e94c1d6c3b4c6ef7137a0145f6
|
data/.document
ADDED
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem 'activesupport', '~> 4.2'
|
4
|
+
gem 'commander', '~> 4.3'
|
5
|
+
gem 'json', '~> 1.8'
|
6
|
+
gem 'rest-client', '~> 1.8'
|
7
|
+
gem 'settingslogic', '~> 2.0'
|
8
|
+
gem 'terminal-announce', '~> 1.0'
|
9
|
+
gem 'nokogiri', '~> 1.6'
|
10
|
+
|
11
|
+
group :development do
|
12
|
+
gem "bundler", "~> 1.0"
|
13
|
+
gem "jeweler", "~> 2.0"
|
14
|
+
gem "rdoc", "~> 3.12"
|
15
|
+
gem "reek", "~> 1.2"
|
16
|
+
gem "roodi", "~> 2.1"
|
17
|
+
gem "shoulda", "~> 3.5"
|
18
|
+
gem "rubocop", "~> 0.32"
|
19
|
+
gem "simplecov", "~> 0.10"
|
20
|
+
gem "yard", "~> 0.7"
|
21
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
abstract_type (0.0.7)
|
5
|
+
activesupport (4.2.5)
|
6
|
+
i18n (~> 0.7)
|
7
|
+
json (~> 1.7, >= 1.7.7)
|
8
|
+
minitest (~> 5.1)
|
9
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
10
|
+
tzinfo (~> 1.1)
|
11
|
+
adamantium (0.2.0)
|
12
|
+
ice_nine (~> 0.11.0)
|
13
|
+
memoizable (~> 0.4.0)
|
14
|
+
addressable (2.3.8)
|
15
|
+
ast (2.1.0)
|
16
|
+
astrolabe (1.3.1)
|
17
|
+
parser (~> 2.2)
|
18
|
+
builder (3.2.2)
|
19
|
+
commander (4.3.5)
|
20
|
+
highline (~> 1.7.2)
|
21
|
+
concord (0.1.5)
|
22
|
+
adamantium (~> 0.2.0)
|
23
|
+
equalizer (~> 0.0.9)
|
24
|
+
contracts (0.12.0)
|
25
|
+
descendants_tracker (0.0.4)
|
26
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
27
|
+
diff-lcs (1.2.5)
|
28
|
+
docile (1.1.5)
|
29
|
+
domain_name (0.5.25)
|
30
|
+
unf (>= 0.0.5, < 1.0.0)
|
31
|
+
equalizer (0.0.11)
|
32
|
+
faraday (0.9.2)
|
33
|
+
multipart-post (>= 1.2, < 3)
|
34
|
+
git (1.2.9.1)
|
35
|
+
github_api (0.13.0)
|
36
|
+
addressable (~> 2.3)
|
37
|
+
descendants_tracker (~> 0.0.4)
|
38
|
+
faraday (~> 0.8, < 0.10)
|
39
|
+
hashie (>= 3.4)
|
40
|
+
multi_json (>= 1.7.5, < 2.0)
|
41
|
+
nokogiri (~> 1.6.6)
|
42
|
+
oauth2
|
43
|
+
hashie (3.4.3)
|
44
|
+
highline (1.7.8)
|
45
|
+
http-cookie (1.0.2)
|
46
|
+
domain_name (~> 0.5)
|
47
|
+
i18n (0.7.0)
|
48
|
+
ice_nine (0.11.1)
|
49
|
+
jeweler (2.0.1)
|
50
|
+
builder
|
51
|
+
bundler (>= 1.0)
|
52
|
+
git (>= 1.2.5)
|
53
|
+
github_api
|
54
|
+
highline (>= 1.6.15)
|
55
|
+
nokogiri (>= 1.5.10)
|
56
|
+
rake
|
57
|
+
rdoc
|
58
|
+
json (1.8.3)
|
59
|
+
jwt (1.5.2)
|
60
|
+
memoizable (0.4.2)
|
61
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
62
|
+
mime-types (2.99)
|
63
|
+
mini_portile (0.6.2)
|
64
|
+
minitest (5.8.3)
|
65
|
+
multi_json (1.11.2)
|
66
|
+
multi_xml (0.5.5)
|
67
|
+
multipart-post (2.0.0)
|
68
|
+
netrc (0.11.0)
|
69
|
+
nokogiri (1.6.6.4)
|
70
|
+
mini_portile (~> 0.6.0)
|
71
|
+
oauth2 (1.0.0)
|
72
|
+
faraday (>= 0.8, < 0.10)
|
73
|
+
jwt (~> 1.0)
|
74
|
+
multi_json (~> 1.3)
|
75
|
+
multi_xml (~> 0.5)
|
76
|
+
rack (~> 1.2)
|
77
|
+
parser (2.2.3.0)
|
78
|
+
ast (>= 1.1, < 3.0)
|
79
|
+
powerpack (0.1.1)
|
80
|
+
procto (0.0.2)
|
81
|
+
rack (1.6.4)
|
82
|
+
rainbow (2.0.0)
|
83
|
+
rake (10.4.2)
|
84
|
+
rdoc (3.12.2)
|
85
|
+
json (~> 1.4)
|
86
|
+
reek (1.6.6)
|
87
|
+
parser (~> 2.2.0.pre.7)
|
88
|
+
rainbow (>= 1.99, < 3.0)
|
89
|
+
unparser (~> 0.2.2)
|
90
|
+
rest-client (1.8.0)
|
91
|
+
http-cookie (>= 1.0.2, < 2.0)
|
92
|
+
mime-types (>= 1.16, < 3.0)
|
93
|
+
netrc (~> 0.7)
|
94
|
+
roodi (2.2.0)
|
95
|
+
ruby_parser (~> 2.3.0)
|
96
|
+
rubocop (0.35.1)
|
97
|
+
astrolabe (~> 1.3)
|
98
|
+
parser (>= 2.2.3.0, < 3.0)
|
99
|
+
powerpack (~> 0.1)
|
100
|
+
rainbow (>= 1.99.1, < 3.0)
|
101
|
+
ruby-progressbar (~> 1.7)
|
102
|
+
tins (<= 1.6.0)
|
103
|
+
ruby-progressbar (1.7.5)
|
104
|
+
ruby_parser (2.3.1)
|
105
|
+
sexp_processor (~> 3.0)
|
106
|
+
settingslogic (2.0.9)
|
107
|
+
sexp_processor (3.2.0)
|
108
|
+
shoulda (3.5.0)
|
109
|
+
shoulda-context (~> 1.0, >= 1.0.1)
|
110
|
+
shoulda-matchers (>= 1.4.1, < 3.0)
|
111
|
+
shoulda-context (1.2.1)
|
112
|
+
shoulda-matchers (2.8.0)
|
113
|
+
activesupport (>= 3.0.0)
|
114
|
+
simplecov (0.10.0)
|
115
|
+
docile (~> 1.1.0)
|
116
|
+
json (~> 1.8)
|
117
|
+
simplecov-html (~> 0.10.0)
|
118
|
+
simplecov-html (0.10.0)
|
119
|
+
terminal-announce (1.0.0)
|
120
|
+
bundler
|
121
|
+
contracts
|
122
|
+
rainbow
|
123
|
+
thread_safe (0.3.5)
|
124
|
+
tins (1.6.0)
|
125
|
+
tzinfo (1.2.2)
|
126
|
+
thread_safe (~> 0.1)
|
127
|
+
unf (0.1.4)
|
128
|
+
unf_ext
|
129
|
+
unf_ext (0.0.7.1)
|
130
|
+
unparser (0.2.4)
|
131
|
+
abstract_type (~> 0.0.7)
|
132
|
+
adamantium (~> 0.2.0)
|
133
|
+
concord (~> 0.1.5)
|
134
|
+
diff-lcs (~> 1.2.5)
|
135
|
+
equalizer (~> 0.0.9)
|
136
|
+
parser (~> 2.2.2)
|
137
|
+
procto (~> 0.0.2)
|
138
|
+
yard (0.8.7.6)
|
139
|
+
|
140
|
+
PLATFORMS
|
141
|
+
ruby
|
142
|
+
|
143
|
+
DEPENDENCIES
|
144
|
+
activesupport (~> 4.2)
|
145
|
+
bundler (~> 1.0)
|
146
|
+
commander (~> 4.3)
|
147
|
+
jeweler (~> 2.0)
|
148
|
+
json (~> 1.8)
|
149
|
+
nokogiri (~> 1.6)
|
150
|
+
rdoc (~> 3.12)
|
151
|
+
reek (~> 1.2)
|
152
|
+
rest-client (~> 1.8)
|
153
|
+
roodi (~> 2.1)
|
154
|
+
rubocop (~> 0.32)
|
155
|
+
settingslogic (~> 2.0)
|
156
|
+
shoulda (~> 3.5)
|
157
|
+
simplecov (~> 0.10)
|
158
|
+
terminal-announce (~> 1.0)
|
159
|
+
yard (~> 0.7)
|
160
|
+
|
161
|
+
BUNDLED WITH
|
162
|
+
1.10.6
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2015 isand3r
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# apidragon: an Automated API Framework
|
2
|
+
|
3
|
+
These classes run a sequence of API calls using a configuration file.
|
4
|
+
- config.yaml is read and vars are dumped into an `arg_bucket`
|
5
|
+
- macros can specified in the config and run as commands
|
6
|
+
|
7
|
+
# Requirements:
|
8
|
+
- Ruby > 2.0
|
9
|
+
- Gems: `json`, `active_support`, `psych`, `rest-client`
|
10
|
+
|
11
|
+
# How to Use:
|
12
|
+
|
13
|
+
- Clone the Repo
|
14
|
+
- Create `config.yaml` according to the examples below
|
15
|
+
- Run from the command line with `./apidragon do [command]`
|
16
|
+
`command` is the name of a macro defined in the config file.
|
17
|
+
|
18
|
+
# Configuration:
|
19
|
+
Create `config.yaml`. Can contain any variable you need to access the API you are using.
|
20
|
+
- config.yaml:
|
21
|
+
```yaml
|
22
|
+
---
|
23
|
+
vars:
|
24
|
+
test: value
|
25
|
+
username: bob
|
26
|
+
password: saget
|
27
|
+
id: 123456abcdef
|
28
|
+
macros:
|
29
|
+
macro_1:
|
30
|
+
testcall:
|
31
|
+
function: username:password@test.net/api
|
32
|
+
input:
|
33
|
+
- id
|
34
|
+
output:
|
35
|
+
- status
|
36
|
+
mode: get
|
37
|
+
```
|
38
|
+
|
39
|
+
Each macro can have `n` number of calls like `testcall` in the example, each requiring a `function`, the necessary `input` and `output` variables, and the request `mode`.
|
40
|
+
|
41
|
+
# Request modes
|
42
|
+
Currently support modes:
|
43
|
+
- `get`
|
44
|
+
- `post`
|
45
|
+
- `curl_get` (uses curl instead of the `rest-client` gem for special cases)
|
46
|
+
|
47
|
+
Planned: `put`, `delete`, `curl_post`, `curl_put`, `curl_delete`
|
48
|
+
|
49
|
+
# Further Options
|
50
|
+
Each call can have a `record` option, where you can specify what output variables you want to record to your config.
|
51
|
+
|
52
|
+
e.g.:
|
53
|
+
```yaml
|
54
|
+
testcall:
|
55
|
+
output:
|
56
|
+
- id
|
57
|
+
record:
|
58
|
+
- id
|
59
|
+
```
|
60
|
+
|
61
|
+
Further, for more specific output parsing, you can specify a qualifier variable. As long as responses are returned as `xml` or `json`, output variables can be associated with one of your pre-defined values for cases like parsing lists of values that have several attribute fields.
|
62
|
+
|
63
|
+
e.g.
|
64
|
+
```yaml
|
65
|
+
testcall:
|
66
|
+
output:
|
67
|
+
- id: username
|
68
|
+
```
|
69
|
+
So if the call returns a list like this: `[{username => bob, id => 1234}, {username => alice, id => 5678}]`, you can always return the `id` associated with the `username` variable defined in the `vars` section.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= apidragon
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to apidragon
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2015 isand3r. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
17
|
+
gem.name = "apidragon"
|
18
|
+
gem.homepage = "http://github.com/isand3r/apidragon"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Ruby based CLI for accessing veracode's api}
|
21
|
+
gem.description = %Q{Ruby based CLI for accessing veracode's api}
|
22
|
+
gem.email = "isaiah.thiessen@live.ca"
|
23
|
+
gem.authors = ["isaiah thiessen"]
|
24
|
+
gem.files = `git ls-files`.split("\n")
|
25
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
26
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
27
|
+
gem.require_paths = ['lib']
|
28
|
+
# dependencies defined in Gemfile
|
29
|
+
end
|
30
|
+
Jeweler::RubygemsDotOrgTasks.new
|
31
|
+
|
32
|
+
require 'rake/testtask'
|
33
|
+
Rake::TestTask.new(:test) do |test|
|
34
|
+
test.libs << 'lib' << 'test'
|
35
|
+
test.pattern = 'test/**/test_*.rb'
|
36
|
+
test.verbose = true
|
37
|
+
end
|
38
|
+
|
39
|
+
require 'rubocop/rake_task'
|
40
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
41
|
+
task.patterns = ['lib/**/*.rb']
|
42
|
+
task.fail_on_error = false
|
43
|
+
end
|
44
|
+
|
45
|
+
desc "Code coverage detail"
|
46
|
+
task :simplecov do
|
47
|
+
ENV['COVERAGE'] = "true"
|
48
|
+
Rake::Task['test'].execute
|
49
|
+
end
|
50
|
+
|
51
|
+
require 'reek/rake/task'
|
52
|
+
Reek::Rake::Task.new do |t|
|
53
|
+
t.fail_on_error = true
|
54
|
+
t.verbose = false
|
55
|
+
t.source_files = 'lib/**/*.rb'
|
56
|
+
end
|
57
|
+
|
58
|
+
require 'roodi'
|
59
|
+
require 'roodi_task'
|
60
|
+
RoodiTask.new do |t|
|
61
|
+
t.verbose = false
|
62
|
+
end
|
63
|
+
|
64
|
+
task :default => :test
|
65
|
+
|
66
|
+
require 'yard'
|
67
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/apidragon
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'commander'
|
4
|
+
require 'apidragon'
|
5
|
+
require_relative '../lib/apidragon.rb'
|
6
|
+
require_relative 'api'
|
7
|
+
|
8
|
+
Commander.configure do
|
9
|
+
program :name, 'apidragon'
|
10
|
+
program :version, '0.0.1'
|
11
|
+
program :description, 'CLI for automating api requests'
|
12
|
+
program :help, 'Author', 'Isaiah Thiessen <isaiah.thiessen@telus.com>'
|
13
|
+
|
14
|
+
command :do do |c|
|
15
|
+
# c.syntax 'apidragon do'
|
16
|
+
# c.description 'Runs the specified command, described in the config file.'
|
17
|
+
c.action do |args|
|
18
|
+
api = Api.new args.first
|
19
|
+
api.go
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'active_support/core_ext/hash'
|
3
|
+
require 'rest-client'
|
4
|
+
require 'yaml'
|
5
|
+
require_relative 'macro'
|
6
|
+
require_relative 'argbucket'
|
7
|
+
|
8
|
+
CONFIG = '/tmp/apidragonconf.yaml'
|
9
|
+
|
10
|
+
class Api < ArgBucket
|
11
|
+
# Uses the configuration data in config.yaml to run a sequence of api calls.
|
12
|
+
# All variables are dumped into a variable bucket (@arg_bucket)
|
13
|
+
# so that they can be used as parameters for function calls.
|
14
|
+
attr_accessor :macro
|
15
|
+
|
16
|
+
def initialize(macro_name)
|
17
|
+
@arg_bucket = {}
|
18
|
+
@config = load_config
|
19
|
+
import @config['vars']
|
20
|
+
@macro = @config['macros'][macro_name]
|
21
|
+
if @macro.nil? then fail "Command: '#{macro_name}' is not defined." end
|
22
|
+
end
|
23
|
+
|
24
|
+
def macro_init
|
25
|
+
macro = @macro
|
26
|
+
@macro = []
|
27
|
+
macro.each_pair do |key, value|
|
28
|
+
@macro << Call.new(value['input'], value['output'], value['mode'], value['function'], @arg_bucket)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def load_config
|
33
|
+
YAML.load_file CONFIG
|
34
|
+
end
|
35
|
+
|
36
|
+
def go
|
37
|
+
@macro.each_pair do |key, value|
|
38
|
+
call = Call.new(value['input'], value['output'], value['mode'], value['function'], @arg_bucket)
|
39
|
+
@arg_bucket = call.run
|
40
|
+
if !value['record'].nil?
|
41
|
+
value['record'].each do |var|
|
42
|
+
add_config_var var, get(var)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def rest_get_request(url, **params)
|
49
|
+
RestClient.get url, params: params
|
50
|
+
end
|
51
|
+
|
52
|
+
def import(args)
|
53
|
+
args.each_pair do |key, value|
|
54
|
+
set key, value
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def add_config_var(key,value)
|
59
|
+
@config['vars'][key] = value
|
60
|
+
file = File.open CONFIG, 'w'
|
61
|
+
file.write(@config.to_yaml.gsub("\n-", "\n\n-"))
|
62
|
+
file.close
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require_relative 'parser'
|
2
|
+
|
3
|
+
class Call < ArgBucket
|
4
|
+
|
5
|
+
attr_accessor :input
|
6
|
+
|
7
|
+
def initialize(input, output, mode, function, args)
|
8
|
+
@arg_bucket = args
|
9
|
+
username = get 'username'
|
10
|
+
password = get 'password'
|
11
|
+
check_constraints mode, function
|
12
|
+
@function = "https://#{function}"
|
13
|
+
credential_sub username, password
|
14
|
+
@mode = mode
|
15
|
+
@output = output
|
16
|
+
@input = input
|
17
|
+
set_call_args unless input.nil?
|
18
|
+
end
|
19
|
+
|
20
|
+
def check_constraints(mode, function)
|
21
|
+
if mode.nil? then fail '"mode" not set. syntax= mode: get/post/put/delete.' end
|
22
|
+
if function.nil? then fail '"function" not set. syntax= function: api-url.' end
|
23
|
+
puts "WARNING: 'function' should have basic auth. (example syntax= function: username:password@example.com/apicall)" unless function.include?('username') && function.include?('password')
|
24
|
+
end
|
25
|
+
|
26
|
+
def credential_sub(username, password)
|
27
|
+
@function.gsub!('username', username) unless username.nil?
|
28
|
+
@function.gsub!('password', password) unless password.nil?
|
29
|
+
end
|
30
|
+
|
31
|
+
def set_call_args
|
32
|
+
input = @input
|
33
|
+
@input = {}
|
34
|
+
input.each do |arg|
|
35
|
+
value = get arg
|
36
|
+
if arg.nil? then puts 'WARNING: required argument not set.' end
|
37
|
+
@input[arg] = value
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def run
|
42
|
+
begin
|
43
|
+
case @mode
|
44
|
+
when 'get'
|
45
|
+
puts "making a get: #{@function} with #{@input}"
|
46
|
+
@response = RestClient.get @function, params: @input
|
47
|
+
when 'post'
|
48
|
+
puts 'making a post'
|
49
|
+
@response = RestClient.post @function, params: @input
|
50
|
+
when 'put'
|
51
|
+
puts 'making a put'
|
52
|
+
when 'delete'
|
53
|
+
puts 'making a delete'
|
54
|
+
when 'curl_get'
|
55
|
+
command = "curl --url #{@function}"
|
56
|
+
@input.each_pair do |key, value|
|
57
|
+
command << " -F #{key}='#{value}'"
|
58
|
+
end
|
59
|
+
@response = `#{command}`
|
60
|
+
else
|
61
|
+
puts "#{@mode} not supported."
|
62
|
+
end
|
63
|
+
rescue RestClient::Unauthorized
|
64
|
+
puts 'Username or password was invalid.'
|
65
|
+
rescue RestClient::Exception
|
66
|
+
puts 'Internal Error or requested resource was not found.'
|
67
|
+
end
|
68
|
+
log_response unless @response.nil?
|
69
|
+
parse_response unless @response.nil? || @output.nil?
|
70
|
+
return @arg_bucket
|
71
|
+
end
|
72
|
+
|
73
|
+
def log_response
|
74
|
+
# puts @response.code
|
75
|
+
# puts @response.body
|
76
|
+
puts @response
|
77
|
+
end
|
78
|
+
|
79
|
+
def xml_to_json
|
80
|
+
@response = Hash.from_xml(@response).to_json unless !@response.include?('<?xml')
|
81
|
+
end
|
82
|
+
|
83
|
+
def parse_response
|
84
|
+
xml_to_json
|
85
|
+
@response = JSON.parse @response
|
86
|
+
@output.each do |var|
|
87
|
+
if var.is_a? String
|
88
|
+
parser = Parser.new(var, nil, @response)
|
89
|
+
parser.parse
|
90
|
+
value = parser.output
|
91
|
+
set "#{var}", value
|
92
|
+
elsif var.is_a? Hash
|
93
|
+
parser = Parser.new(var.first[0], get(var.first[1]), @response)
|
94
|
+
parser.parse
|
95
|
+
value = parser.output
|
96
|
+
set var.first[0], value
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
class Parser
|
2
|
+
attr_accessor :output
|
3
|
+
|
4
|
+
def initialize(field_name, qualifier_value, hash)
|
5
|
+
@field_name = field_name
|
6
|
+
@qualifier_value = qualifier_value
|
7
|
+
@hash = hash
|
8
|
+
end
|
9
|
+
|
10
|
+
def parse
|
11
|
+
if @qualifier_value.nil?
|
12
|
+
recurse @hash
|
13
|
+
else
|
14
|
+
qualified_recurse @hash
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def recurse(object)
|
19
|
+
if object.is_a? Hash
|
20
|
+
if object.has_key? @field_name
|
21
|
+
@output = object[@field_name]
|
22
|
+
else
|
23
|
+
object.each_pair do |key, value|
|
24
|
+
qualified_recurse value
|
25
|
+
end
|
26
|
+
end
|
27
|
+
elsif object.is_a? Array
|
28
|
+
object.each do |element|
|
29
|
+
qualified_recurse element
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def qualified_recurse(object)
|
35
|
+
if object.is_a? Hash
|
36
|
+
if object.has_value? @qualifier_value
|
37
|
+
@output = object[@field_name]
|
38
|
+
else
|
39
|
+
object.each_pair do |key, value|
|
40
|
+
qualified_recurse value
|
41
|
+
end
|
42
|
+
end
|
43
|
+
elsif object.is_a? Array
|
44
|
+
object.each do |element|
|
45
|
+
qualified_recurse element
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
data/lib/apidragon.rb
ADDED
data/test/helper.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
|
3
|
+
module SimpleCov::Configuration
|
4
|
+
def clean_filters
|
5
|
+
@filters = []
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
SimpleCov.configure do
|
10
|
+
clean_filters
|
11
|
+
load_adapter 'test_frameworks'
|
12
|
+
end
|
13
|
+
|
14
|
+
ENV["COVERAGE"] && SimpleCov.start do
|
15
|
+
add_filter "/.rvm/"
|
16
|
+
end
|
17
|
+
require 'rubygems'
|
18
|
+
require 'bundler'
|
19
|
+
begin
|
20
|
+
Bundler.setup(:default, :development)
|
21
|
+
rescue Bundler::BundlerError => e
|
22
|
+
$stderr.puts e.message
|
23
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
24
|
+
exit e.status_code
|
25
|
+
end
|
26
|
+
require 'test/unit'
|
27
|
+
require 'shoulda'
|
28
|
+
|
29
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
30
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
31
|
+
require 'apidragon'
|
32
|
+
|
33
|
+
class Test::Unit::TestCase
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,288 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: apidragon
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- isaiah thiessen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: commander
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.3'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.8'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rest-client
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.8'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.8'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: settingslogic
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: terminal-announce
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: nokogiri
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.6'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.6'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: bundler
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: jeweler
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '2.0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '2.0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rdoc
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '3.12'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '3.12'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: reek
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '1.2'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '1.2'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: roodi
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '2.1'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '2.1'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: shoulda
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - "~>"
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '3.5'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - "~>"
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '3.5'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: rubocop
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - "~>"
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0.32'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - "~>"
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0.32'
|
209
|
+
- !ruby/object:Gem::Dependency
|
210
|
+
name: simplecov
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - "~>"
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: '0.10'
|
216
|
+
type: :development
|
217
|
+
prerelease: false
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - "~>"
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: '0.10'
|
223
|
+
- !ruby/object:Gem::Dependency
|
224
|
+
name: yard
|
225
|
+
requirement: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - "~>"
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: '0.7'
|
230
|
+
type: :development
|
231
|
+
prerelease: false
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - "~>"
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: '0.7'
|
237
|
+
description: Ruby based CLI for accessing veracode's api
|
238
|
+
email: isaiah.thiessen@live.ca
|
239
|
+
executables:
|
240
|
+
- apidragon
|
241
|
+
extensions: []
|
242
|
+
extra_rdoc_files:
|
243
|
+
- LICENSE.txt
|
244
|
+
- README.md
|
245
|
+
- README.rdoc
|
246
|
+
files:
|
247
|
+
- ".document"
|
248
|
+
- ".gitignore"
|
249
|
+
- Gemfile
|
250
|
+
- Gemfile.lock
|
251
|
+
- LICENSE.txt
|
252
|
+
- README.md
|
253
|
+
- README.rdoc
|
254
|
+
- Rakefile
|
255
|
+
- VERSION
|
256
|
+
- bin/apidragon
|
257
|
+
- lib/apidragon.rb
|
258
|
+
- lib/apidragon/api.rb
|
259
|
+
- lib/apidragon/argbucket.rb
|
260
|
+
- lib/apidragon/macro.rb
|
261
|
+
- lib/apidragon/parser.rb
|
262
|
+
- test/helper.rb
|
263
|
+
- test/test_apidragon.rb
|
264
|
+
homepage: http://github.com/isand3r/apidragon
|
265
|
+
licenses:
|
266
|
+
- MIT
|
267
|
+
metadata: {}
|
268
|
+
post_install_message:
|
269
|
+
rdoc_options: []
|
270
|
+
require_paths:
|
271
|
+
- lib
|
272
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
273
|
+
requirements:
|
274
|
+
- - ">="
|
275
|
+
- !ruby/object:Gem::Version
|
276
|
+
version: '0'
|
277
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
278
|
+
requirements:
|
279
|
+
- - ">="
|
280
|
+
- !ruby/object:Gem::Version
|
281
|
+
version: '0'
|
282
|
+
requirements: []
|
283
|
+
rubyforge_project:
|
284
|
+
rubygems_version: 2.5.0
|
285
|
+
signing_key:
|
286
|
+
specification_version: 4
|
287
|
+
summary: Ruby based CLI for accessing veracode's api
|
288
|
+
test_files: []
|