apidragon 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38f447a14c74741ccc26b5d641ac6bf3be90315f
4
- data.tar.gz: 6a320529e79a2f3e3816a1e3224629d2d5e38fc1
3
+ metadata.gz: 057fea4ff820d0007256be6ae77b2ad5f41af564
4
+ data.tar.gz: dff236d10ed490abbb2df35b7c0d1874b4f902ea
5
5
  SHA512:
6
- metadata.gz: 1d403ce82e3d9a20be2837ed6b9b0dd2021008d3a7434a3d4e226dee06d8a30f6c122996d35d13149c1234cf060199f88e7804913e37ed853c837a63cf270e53
7
- data.tar.gz: 761f6f6613eeca86d341b3ef4f478c26ba0c444f6118a2d130b6465a1ecbb79048486a66ad47246a0489a2aa7cbaba17741cf6f9d2ffd151ced1c715961cea6a
6
+ metadata.gz: 2037bb17194a23285ed05b67c3573e19c1500ae7dec6d3c5d1ce0778f9c90424007757234ec63882be0086b5a0eca8b990b32fe62df5aceb3186fbbeb6a7397f
7
+ data.tar.gz: 52cb232fd49bf6410c47ae7f4169f9df67a518f2b9e8fe16932417759f7b92804916fadec4b38cf9316fda85c035ee716ef1a5d93381f883c5afd59a412d2b03
data/README.md CHANGED
@@ -50,23 +50,28 @@ Each macro can have `n` number of calls like `testcall` in the example, each req
50
50
  Currently supported modes:
51
51
  - `get`
52
52
  - `post`
53
- - `curl_get` (uses curl instead of the `rest-client` gem for special cases)
54
-
55
- Planned: `put`, `delete`, `curl_post`, `curl_put`, `curl_delete`
53
+ - `put`
54
+ - `delete`
55
+ - `curl_get`, `curl_post` (uses curl instead of the `rest-client` gem for special cases)
56
+ - `eval` (not yet stable)
57
+ - Planned: `curl_put`, `curl_delete`
56
58
 
57
59
  # Further Options
60
+
61
+ ## `record`
58
62
  Each call can have a `record` option, where you can specify what output variables you want to record to your config.
59
63
 
60
64
  - e.g.:
61
65
  ```yaml
62
66
  testcall:
63
- output:
67
+ output:
64
68
  - id
65
69
  - userinfo
66
70
  record:
67
71
  - id
68
72
  ```
69
73
 
74
+ ## Qualifier variables
70
75
  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.
71
76
 
72
77
  - e.g.:
@@ -78,6 +83,43 @@ Further, for more specific output parsing, you can specify a qualifier variable.
78
83
  ```
79
84
  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.
80
85
 
86
+ ## `logging`
87
+ For each call, set `logging` to `true` to enable or `false` to disable.
88
+
89
+ - e.g.:
90
+ ```yaml
91
+ testcall:
92
+ logging: true
93
+ ```
94
+
95
+ ## `plugin` (unstable)
96
+ apidragon will automatically `require_relative` any `.rb` files at `/tmp/apidragonplugins/`.
97
+ Call the code in the plugin file like so:
98
+
99
+ - e.g.:
100
+ - example.rb: (in `/tmp/apidragonplugins/`)
101
+ ```ruby
102
+ class Example
103
+ def initialize(message)
104
+ @message = message
105
+ end
106
+
107
+ def out
108
+ puts "#{@message}"
109
+ end
110
+ end
111
+ ```
112
+ - apidragonconf.yaml:
113
+ ```yaml
114
+ hellocall:
115
+ function: Example.new('hello').out
116
+ mode: eval
117
+ plugin: example
118
+ ```
119
+
120
+ # Planned Features
121
+ - The ability to include custom scripts at the end of a call for extensibility
122
+
81
123
  #License
82
124
 
83
125
  [MIT](https://tldrlegal.com/license/mit-license)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
data/apidragon.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: apidragon 1.0.0 ruby lib
5
+ # stub: apidragon 1.1.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "apidragon"
9
- s.version = "1.0.0"
9
+ s.version = "1.1.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["isaiah thiessen"]
14
- s.date = "2015-11-27"
14
+ s.date = "2015-11-30"
15
15
  s.description = "Ruby based CLI for accessing veracode's api"
16
16
  s.email = "isaiah.thiessen@live.ca"
17
17
  s.executables = ["apidragon"]
@@ -34,6 +34,7 @@ Gem::Specification.new do |s|
34
34
  "lib/apidragon.rb",
35
35
  "lib/apidragon/api.rb",
36
36
  "lib/apidragon/argbucket.rb",
37
+ "lib/apidragon/log.rb",
37
38
  "lib/apidragon/macro.rb",
38
39
  "lib/apidragon/parser.rb",
39
40
  "test/helper.rb",
data/lib/apidragon/api.rb CHANGED
@@ -6,6 +6,8 @@ require_relative 'macro'
6
6
  require_relative 'argbucket'
7
7
 
8
8
  CONFIG = '/tmp/apidragonconf.yaml'
9
+ PLUGINS = '/tmp/apidragonplugins/'
10
+ LOG = '/tmp/apidragon.log'
9
11
 
10
12
  class Api < ArgBucket
11
13
  # Uses the configuration data in config.yaml to run a sequence of api calls.
@@ -21,27 +23,19 @@ class Api < ArgBucket
21
23
  if @macro.nil? then fail "Command: '#{macro_name}' is not defined." end
22
24
  end
23
25
 
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
26
  def load_config
33
27
  YAML.load_file CONFIG
34
28
  end
35
29
 
36
30
  def go
37
31
  @macro.each_pair do |key, value|
38
- call = Call.new(value['input'], value['output'], value['mode'], value['function'], @arg_bucket)
32
+ call = Call.new(value['input'], value['output'], value['mode'], value['function'], @arg_bucket, value['logging'], value['plugin'])
39
33
  @arg_bucket = call.run
40
34
  if !value['record'].nil?
41
35
  value['record'].each do |var|
42
36
  add_config_var var, get(var)
43
37
  end
44
- end
38
+ end
45
39
  end
46
40
  end
47
41
 
@@ -0,0 +1,23 @@
1
+ class ResponseLogger
2
+
3
+ def object_log(function, code, body)
4
+ log = File.open "#{LOG}", 'a+'
5
+ log.write "call @ #{timestamp}"
6
+ log.write "HTTP #{code}\n"
7
+ log.write body
8
+ log.write "\n"
9
+ log.close
10
+ end
11
+
12
+ def string_log(function, response)
13
+ log = File.open "#{LOG}", 'a+'
14
+ log.write "call @ #{timestamp}"
15
+ log.write response
16
+ log.write "\n"
17
+ log.close
18
+ end
19
+
20
+ def timestamp
21
+ `date`
22
+ end
23
+ end
@@ -1,12 +1,12 @@
1
1
  require_relative 'parser'
2
2
  require_relative 'argbucket'
3
+ require_relative 'log'
3
4
 
4
5
  class Call < ArgBucket
5
6
 
6
- attr_accessor :input
7
-
8
- def initialize(input, output, mode, function, args)
7
+ def initialize(input, output, mode, function, args, logging=false, plugin=nil)
9
8
  @arg_bucket = args
9
+ require_relative "#{PLUGINS}#{plugin}" unless plugin.nil?
10
10
  username = get 'username'
11
11
  password = get 'password'
12
12
  check_constraints mode, function
@@ -15,13 +15,14 @@ class Call < ArgBucket
15
15
  @mode = mode
16
16
  @output = output
17
17
  @input = input
18
+ @logging = logging
18
19
  set_call_args unless input.nil?
19
20
  end
20
21
 
21
22
  def check_constraints(mode, function)
22
23
  if mode.nil? then fail '"mode" not set. syntax= mode: get/post/put/delete.' end
23
24
  if function.nil? then fail '"function" not set. syntax= function: api-url.' end
24
- puts "WARNING: 'function' should have basic auth. (example syntax= function: username:password@example.com/apicall)" unless function.include?('username') && function.include?('password')
25
+ puts "WARNING: 'function' should have basic auth. (example syntax= function: username:password@example.com/apicall)" unless function.include?('username') && function.include?('password') || @mode == 'eval'
25
26
  end
26
27
 
27
28
  def credential_sub(username, password)
@@ -55,17 +56,19 @@ class Call < ArgBucket
55
56
  puts "making a delete: #{@function} with #{@input}"
56
57
  @response = RestClient.delete @function, params: @input
57
58
  when 'curl_get'
58
- command = "curl --url #{@function}"
59
+ command = "curl -v --url #{@function}"
59
60
  @input.each_pair do |key, value|
60
61
  command << " -F #{key}='#{value}'"
61
62
  end
62
63
  @response = `#{command}`
63
64
  when 'curl_post'
64
- command = "curl -X POST --url #{@function}"
65
+ command = "curl -v -X POST --url #{@function}"
65
66
  @input.each_pair do |key, value|
66
67
  command << " -F #{key}='#{value}'"
67
68
  end
68
69
  @response = `#{command}`
70
+ when 'eval'
71
+ @response = eval(@function)
69
72
  else
70
73
  puts "#{@mode} not supported."
71
74
  end
@@ -74,15 +77,20 @@ class Call < ArgBucket
74
77
  rescue RestClient::Exception
75
78
  puts 'Internal Error or requested resource was not found.'
76
79
  end
77
- log_response unless @response.nil?
78
- parse_response unless @response.nil? || @output.nil?
80
+ if !@response.nil?
81
+ log_response unless @logging == false
82
+ parse_response unless @output.nil?
83
+ end
79
84
  return @arg_bucket
80
85
  end
81
86
 
82
87
  def log_response
83
- # puts @response.code
84
- # puts @response.body
85
- puts @response
88
+ logger = ResponseLogger.new
89
+ if !@response.is_a? String
90
+ logger.object_log @function, @response.code, @response.body
91
+ else
92
+ logger.string_log @function, @response
93
+ end
86
94
  end
87
95
 
88
96
  def xml_to_json
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apidragon
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - isaiah thiessen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-27 00:00:00.000000000 Z
11
+ date: 2015-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -257,6 +257,7 @@ files:
257
257
  - lib/apidragon.rb
258
258
  - lib/apidragon/api.rb
259
259
  - lib/apidragon/argbucket.rb
260
+ - lib/apidragon/log.rb
260
261
  - lib/apidragon/macro.rb
261
262
  - lib/apidragon/parser.rb
262
263
  - test/helper.rb