esp_sdk 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/bin/esp_repl ADDED
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.push 'lib'
4
+ require 'optparse'
5
+ require 'esp_sdk'
6
+
7
+ options = {}
8
+ opt_parser = OptionParser.new do |opt|
9
+ opt.on('-f', '--file FILE') do |file|
10
+ options[:signature] = File.read(file)
11
+ case File.extname(file)
12
+ when '.rb'
13
+ options[:language] = 'ruby'
14
+ when '.js'
15
+ options[:language] = 'javascript'
16
+ else
17
+ fail StandardError, 'Unkown extension type must be one of .rb or .js'
18
+ end
19
+ end
20
+
21
+ opt.on('--external_account_id EXTERNAL_ACCOUNT_ID') do |external_account_id|
22
+ options[:external_account_id] = external_account_id
23
+ end
24
+
25
+ opt.on('--region REGION') do |region|
26
+ options[:region] = region
27
+ end
28
+
29
+ opt.on('--password PASSWORD') do |password|
30
+ options[:password] = password
31
+ end
32
+
33
+ opt.on('--email EMAIL') do |email|
34
+ options[:email] = email
35
+ end
36
+
37
+ opt.on('-c') do
38
+ options[:console] = true
39
+ end
40
+ end
41
+
42
+ opt_parser.parse!
43
+ repl = EspSdk::Repl.new(options)
44
+
45
+ if options[:console]
46
+ require 'artii'
47
+ require 'pry'
48
+ AwesomePrint.pry!
49
+ Pry.config.prompt = proc { 'ESP::REPL > ' }
50
+ artii = Artii::Base.new(font: 'slant')
51
+ print <<-banner
52
+ #{artii.asciify('E.S.P')}
53
+ Evident Security Platform REPL #{EspSdk::VERSION}
54
+ Copyright (c) 2013-#{Time.now.year} Evident Security, All Rights Reserved.
55
+ http://www.evident.io
56
+ banner
57
+ Pry.start repl
58
+ else
59
+ ap repl.eval
60
+ end
data/esp_sdk.gemspec CHANGED
@@ -26,8 +26,10 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.4.1'
27
27
  spec.add_development_dependency 'mocha', '~> 1.1.0'
28
28
  spec.add_development_dependency 'fakeweb', '~> 1.3'
29
- spec.add_development_dependency 'awesome_print', '~> 1.2.0'
30
29
 
31
30
  spec.add_runtime_dependency 'activesupport', '~> 4.1.6'
32
31
  spec.add_runtime_dependency 'rest_client', '~> 1.7.3'
32
+ spec.add_runtime_dependency 'pry', '~> 0.10.1'
33
+ spec.add_runtime_dependency 'awesome_print', '~> 1.2.0'
34
+ spec.add_runtime_dependency 'artii', '~> 2.1.1'
33
35
  end
data/lib/esp_sdk/api.rb CHANGED
@@ -3,8 +3,8 @@ module EspSdk
3
3
  attr_reader :end_points, :config
4
4
 
5
5
  def initialize(options = {})
6
- fail MissingAttribute, 'Missing required email' if options[:email].blank?
7
- fail MissingAttribute, 'Missing required password or token' if options[:password].blank? && options[:token].blank?
6
+ options[:email] ||= options_errors(:email)
7
+ options_errors(:password) if options[:token].blank? && options[:password].blank?
8
8
  @config = Configure.new(options)
9
9
  @end_points = []
10
10
  define_methods
@@ -25,5 +25,9 @@ module EspSdk
25
25
  @end_points << send(name)
26
26
  end
27
27
  end
28
+
29
+ def options_errors(option)
30
+ ENV["ESP_#{option.upcase}"] || fail(EspSdk::MissingAttribute, "Missing required #{option}") # rubocop:disable all
31
+ end
28
32
  end
29
33
  end
@@ -18,11 +18,11 @@ module EspSdk
18
18
  end
19
19
 
20
20
  def valid_run_params
21
- [:id, :regions, :external_account_id]
21
+ [:id, :regions, :external_account_id, :language]
22
22
  end
23
23
 
24
24
  def valid_run_raw_params
25
- [:signature, :regions, :external_account_id]
25
+ [:signature, :regions, :external_account_id, :language]
26
26
  end
27
27
 
28
28
  def validate_run_params(valid_params, keys)
@@ -0,0 +1,61 @@
1
+ module EspSdk
2
+ # Current context in the ESP REPL
3
+ class Repl
4
+ attr_reader :client, :options, :results
5
+
6
+ def initialize(options = {})
7
+ @options = options
8
+ @client = EspSdk::Api.new(@options)
9
+ end
10
+
11
+ # Override eval to delegate to the scripting eval
12
+ def eval
13
+ @results = client.custom_signatures.run_raw(
14
+ signature: @options[:signature],
15
+ language: @options[:language],
16
+ regions: Array(@options[:region]),
17
+ external_account_id: @options[:external_account_id])
18
+ end
19
+
20
+ def signature
21
+ @options[:signature]
22
+ end
23
+
24
+ def set_signature(signature, language = :javascript)
25
+ @options[:signature] = signature
26
+ @options[:language] = language
27
+ true
28
+ end
29
+
30
+ def region
31
+ @options[:region]
32
+ end
33
+
34
+ def set_region(region)
35
+ @options[:region] = region
36
+ end
37
+
38
+ def external_account_id
39
+ @options[:external_account_id]
40
+ end
41
+
42
+ def set_external_account_id(id)
43
+ @options[:external_account_id] = id
44
+ end
45
+
46
+ # Used to reset the client
47
+ def reload!
48
+ @client = EspSdk::Api.new(@options)
49
+ 'Reloaded!'
50
+ end
51
+
52
+ # Delegate to @client
53
+ def method_missing(meth, *args, &block)
54
+ if client.respond_to?(meth)
55
+ client.send(meth, *args, &block)
56
+ else
57
+ super
58
+ end
59
+ end
60
+ end
61
+ end
@@ -1,3 +1,3 @@
1
1
  module EspSdk
2
- VERSION = '1.0.5'
2
+ VERSION = '1.0.6'
3
3
  end
data/lib/esp_sdk.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'active_support/all'
2
+ require 'awesome_print'
2
3
  require_relative 'esp_sdk/version'
3
4
  require_relative 'esp_sdk/configure'
4
5
  require_relative 'esp_sdk/client'
@@ -15,6 +16,7 @@ require_relative 'esp_sdk/end_points/dashboard'
15
16
  require_relative 'esp_sdk/end_points/contact_requests'
16
17
  require_relative 'esp_sdk/end_points/services'
17
18
  require_relative 'esp_sdk/api'
19
+ require_relative 'esp_sdk/repl'
18
20
  require_relative 'esp_sdk/exceptions'
19
21
 
20
22
  module EspSdk
@@ -14,7 +14,7 @@ class ApiTest < ActiveSupport::TestCase
14
14
  e = assert_raises EspSdk::MissingAttribute do
15
15
  EspSdk::Api.new(email: 'test@evident.io')
16
16
  end
17
- assert_equal 'Missing required password or token', e.message
17
+ assert_equal 'Missing required password', e.message
18
18
 
19
19
  end
20
20
 
@@ -33,4 +33,4 @@ class ApiTest < ActiveSupport::TestCase
33
33
  end
34
34
  end
35
35
  end
36
- end
36
+ end
@@ -80,7 +80,7 @@ class CustomSignaturesTest < ActiveSupport::TestCase
80
80
  should 'raise an error for an unknown attribute' do
81
81
  e = assert_raises EspSdk::UnknownAttribute do
82
82
  @custom_signatures.send(:validate_run_params, @valid_params, { id: 1, regions: [:us_east_1],
83
- external_account_id: 1, bad_param: 1}.keys)
83
+ external_account_id: 1, bad_param: 1, language: 'javascript'}.keys)
84
84
  end
85
85
 
86
86
  assert_equal 'Unknown attribute bad_param', e.message
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: esp_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evident.io
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-08 00:00:00.000000000 Z
11
+ date: 2015-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -137,51 +137,80 @@ dependencies:
137
137
  - !ruby/object:Gem::Version
138
138
  version: '1.3'
139
139
  - !ruby/object:Gem::Dependency
140
- name: awesome_print
140
+ name: activesupport
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: 1.2.0
146
- type: :development
145
+ version: 4.1.6
146
+ type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: 1.2.0
152
+ version: 4.1.6
153
153
  - !ruby/object:Gem::Dependency
154
- name: activesupport
154
+ name: rest_client
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: 4.1.6
159
+ version: 1.7.3
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: 4.1.6
166
+ version: 1.7.3
167
167
  - !ruby/object:Gem::Dependency
168
- name: rest_client
168
+ name: pry
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: 1.7.3
173
+ version: 0.10.1
174
174
  type: :runtime
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - "~>"
179
179
  - !ruby/object:Gem::Version
180
- version: 1.7.3
180
+ version: 0.10.1
181
+ - !ruby/object:Gem::Dependency
182
+ name: awesome_print
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: 1.2.0
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: 1.2.0
195
+ - !ruby/object:Gem::Dependency
196
+ name: artii
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: 2.1.1
202
+ type: :runtime
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: 2.1.1
181
209
  description:
182
210
  email:
183
211
  - support@evident.io
184
- executables: []
212
+ executables:
213
+ - esp_repl
185
214
  extensions: []
186
215
  extra_rdoc_files: []
187
216
  files:
@@ -193,6 +222,7 @@ files:
193
222
  - LICENSE.txt
194
223
  - README.md
195
224
  - Rakefile
225
+ - bin/esp_repl
196
226
  - esp_sdk.gemspec
197
227
  - lib/esp_sdk.rb
198
228
  - lib/esp_sdk/api.rb
@@ -212,6 +242,7 @@ files:
212
242
  - lib/esp_sdk/end_points/users.rb
213
243
  - lib/esp_sdk/exceptions.rb
214
244
  - lib/esp_sdk/extensions/rest_client/request.rb
245
+ - lib/esp_sdk/repl.rb
215
246
  - lib/esp_sdk/version.rb
216
247
  - test/esp_sdk/api_test.rb
217
248
  - test/esp_sdk/client_test.rb
@@ -245,7 +276,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
245
276
  version: '0'
246
277
  requirements: []
247
278
  rubyforge_project:
248
- rubygems_version: 2.2.2
279
+ rubygems_version: 2.4.5
249
280
  signing_key:
250
281
  specification_version: 4
251
282
  summary: SDK for interacting with the ESP API.