esp_sdk 1.1.0 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -2
  3. data/.rubocop.yml +53 -6
  4. data/.ruby-version +1 -1
  5. data/.travis.yml +8 -2
  6. data/Gemfile.lock +171 -0
  7. data/Guardfile +47 -0
  8. data/README.md +230 -5
  9. data/Rakefile +14 -1
  10. data/assets/logo.png +0 -0
  11. data/bin/esp_console +71 -0
  12. data/esp_sdk.gemspec +27 -18
  13. data/lib/esp/exceptions.rb +3 -0
  14. data/lib/esp/extensions/active_resource/formats/json_api_format.rb +105 -0
  15. data/lib/esp/extensions/active_resource/paginated_collection.rb +198 -0
  16. data/lib/esp/extensions/active_resource/validations.rb +45 -0
  17. data/lib/esp/resources/alert.rb +135 -0
  18. data/lib/esp/resources/cloud_trail_event.rb +45 -0
  19. data/lib/esp/resources/concerns/stat_totals.rb +79 -0
  20. data/lib/esp/resources/contact_request.rb +42 -0
  21. data/lib/esp/resources/custom_signature.rb +224 -0
  22. data/lib/esp/resources/dashboard.rb +31 -0
  23. data/lib/esp/resources/external_account.rb +89 -0
  24. data/lib/esp/resources/organization.rb +61 -0
  25. data/lib/esp/resources/region.rb +46 -0
  26. data/lib/esp/resources/report.rb +100 -0
  27. data/lib/esp/resources/resource.rb +66 -0
  28. data/lib/esp/resources/service.rb +31 -0
  29. data/lib/esp/resources/signature.rb +106 -0
  30. data/lib/esp/resources/stat.rb +124 -0
  31. data/lib/esp/resources/stat_custom_signature.rb +121 -0
  32. data/lib/esp/resources/stat_region.rb +121 -0
  33. data/lib/esp/resources/stat_service.rb +121 -0
  34. data/lib/esp/resources/stat_signature.rb +121 -0
  35. data/lib/esp/resources/sub_organization.rb +69 -0
  36. data/lib/esp/resources/suppression/region.rb +99 -0
  37. data/lib/esp/resources/suppression/signature.rb +107 -0
  38. data/lib/esp/resources/suppression/unique_identifier.rb +60 -0
  39. data/lib/esp/resources/suppression.rb +86 -0
  40. data/lib/esp/resources/tag.rb +45 -0
  41. data/lib/esp/resources/team.rb +79 -0
  42. data/lib/esp/resources/user.rb +46 -0
  43. data/lib/esp/version.rb +3 -0
  44. data/lib/esp.rb +95 -0
  45. data/lib/esp_sdk.rb +9 -45
  46. data/lib/tasks/rubocop.rake +2 -0
  47. data/lib/tasks/testing.rake +3 -0
  48. data/rdoc/ActiveResource/Formats.html +176 -0
  49. data/rdoc/ActiveResource/PaginatedCollection.html +910 -0
  50. data/rdoc/ActiveResource.html +180 -0
  51. data/rdoc/ESP/Alert.html +771 -0
  52. data/rdoc/ESP/CloudTrailEvent.html +375 -0
  53. data/rdoc/ESP/ContactRequest.html +366 -0
  54. data/rdoc/ESP/CustomSignature.html +746 -0
  55. data/rdoc/ESP/Dashboard.html +355 -0
  56. data/rdoc/ESP/ExternalAccount.html +565 -0
  57. data/rdoc/ESP/Organization.html +590 -0
  58. data/rdoc/ESP/Region.html +399 -0
  59. data/rdoc/ESP/Report.html +622 -0
  60. data/rdoc/ESP/Service.html +380 -0
  61. data/rdoc/ESP/Signature.html +555 -0
  62. data/rdoc/ESP/Stat.html +1778 -0
  63. data/rdoc/ESP/StatCustomSignature.html +1599 -0
  64. data/rdoc/ESP/StatRegion.html +1598 -0
  65. data/rdoc/ESP/StatService.html +1598 -0
  66. data/rdoc/ESP/StatSignature.html +1598 -0
  67. data/rdoc/ESP/SubOrganization.html +540 -0
  68. data/rdoc/ESP/Suppression/Region.html +454 -0
  69. data/rdoc/ESP/Suppression/Signature.html +470 -0
  70. data/rdoc/ESP/Suppression/UniqueIdentifier.html +417 -0
  71. data/rdoc/ESP/Suppression.html +649 -0
  72. data/rdoc/ESP/Tag.html +371 -0
  73. data/rdoc/ESP/Team.html +584 -0
  74. data/rdoc/ESP/User.html +483 -0
  75. data/rdoc/ESP.html +546 -0
  76. data/rdoc/README_md.html +501 -0
  77. data/rdoc/created.rid +30 -0
  78. data/rdoc/images/add.png +0 -0
  79. data/rdoc/images/arrow_up.png +0 -0
  80. data/rdoc/images/brick.png +0 -0
  81. data/rdoc/images/brick_link.png +0 -0
  82. data/rdoc/images/bug.png +0 -0
  83. data/rdoc/images/bullet_black.png +0 -0
  84. data/rdoc/images/bullet_toggle_minus.png +0 -0
  85. data/rdoc/images/bullet_toggle_plus.png +0 -0
  86. data/rdoc/images/date.png +0 -0
  87. data/rdoc/images/delete.png +0 -0
  88. data/rdoc/images/find.png +0 -0
  89. data/rdoc/images/loadingAnimation.gif +0 -0
  90. data/rdoc/images/macFFBgHack.png +0 -0
  91. data/rdoc/images/package.png +0 -0
  92. data/rdoc/images/page_green.png +0 -0
  93. data/rdoc/images/page_white_text.png +0 -0
  94. data/rdoc/images/page_white_width.png +0 -0
  95. data/rdoc/images/plugin.png +0 -0
  96. data/rdoc/images/ruby.png +0 -0
  97. data/rdoc/images/tag_blue.png +0 -0
  98. data/rdoc/images/tag_green.png +0 -0
  99. data/rdoc/images/transparent.png +0 -0
  100. data/rdoc/images/wrench.png +0 -0
  101. data/rdoc/images/wrench_orange.png +0 -0
  102. data/rdoc/images/zoom.png +0 -0
  103. data/rdoc/index.html +134 -0
  104. data/rdoc/js/darkfish.js +155 -0
  105. data/rdoc/js/jquery.js +4 -0
  106. data/rdoc/js/navigation.js +142 -0
  107. data/rdoc/js/search.js +94 -0
  108. data/rdoc/js/search_index.js +1 -0
  109. data/rdoc/js/searcher.js +228 -0
  110. data/rdoc/rdoc.css +595 -0
  111. data/rdoc/table_of_contents.html +927 -0
  112. data/test/esp/extensions/active_resource/formats/json_api_format_test.rb +109 -0
  113. data/test/esp/extensions/active_resource/paginated_collection_test.rb +435 -0
  114. data/test/esp/extensions/active_resource/validations_test.rb +59 -0
  115. data/test/esp/resources/alert_test.rb +263 -0
  116. data/test/esp/resources/cloud_trail_event_test.rb +98 -0
  117. data/test/esp/resources/contact_request_test.rb +73 -0
  118. data/test/esp/resources/custom_signature_test.rb +241 -0
  119. data/test/esp/resources/dashboard_test.rb +71 -0
  120. data/test/esp/resources/external_account_test.rb +125 -0
  121. data/test/esp/resources/organization_test.rb +175 -0
  122. data/test/esp/resources/region_test.rb +84 -0
  123. data/test/esp/resources/report_test.rb +180 -0
  124. data/test/esp/resources/resource_test.rb +183 -0
  125. data/test/esp/resources/service_test.rb +64 -0
  126. data/test/esp/resources/signature_test.rb +177 -0
  127. data/test/esp/resources/stat_custom_signature_test.rb +115 -0
  128. data/test/esp/resources/stat_region_test.rb +114 -0
  129. data/test/esp/resources/stat_service_test.rb +114 -0
  130. data/test/esp/resources/stat_signature_test.rb +115 -0
  131. data/test/esp/resources/stat_test.rb +159 -0
  132. data/test/esp/resources/sub_organization_test.rb +127 -0
  133. data/test/esp/resources/suppression/region_test.rb +115 -0
  134. data/test/esp/resources/suppression/signature_test.rb +117 -0
  135. data/test/esp/resources/suppression/unique_identifier_test.rb +79 -0
  136. data/test/esp/resources/suppression_test.rb +226 -0
  137. data/test/esp/resources/tag_test.rb +98 -0
  138. data/test/esp/resources/team_test.rb +140 -0
  139. data/test/esp/resources/user_test.rb +113 -0
  140. data/test/esp_test.rb +139 -0
  141. data/test/factories/alerts.rb +234 -0
  142. data/test/factories/cloud_trail_events.rb +16 -0
  143. data/test/factories/contact_requests.rb +14 -0
  144. data/test/factories/custom_signatures.rb +30 -0
  145. data/test/factories/dashboards.rb +91 -0
  146. data/test/factories/errors.rb +24 -0
  147. data/test/factories/external_accounts.rb +44 -0
  148. data/test/factories/organizations.rb +48 -0
  149. data/test/factories/regions.rb +9 -0
  150. data/test/factories/reports.rb +56 -0
  151. data/test/factories/services.rb +12 -0
  152. data/test/factories/signatures.rb +28 -0
  153. data/test/factories/stat_custom_signatures.rb +97 -0
  154. data/test/factories/stat_regions.rb +97 -0
  155. data/test/factories/stat_services.rb +97 -0
  156. data/test/factories/stat_signautures.rb +97 -0
  157. data/test/factories/stats.rb +129 -0
  158. data/test/factories/sub_organizations.rb +34 -0
  159. data/test/factories/suppression/regions.rb +90 -0
  160. data/test/factories/suppression/signatures.rb +117 -0
  161. data/test/factories/suppression/unique_identifiers.rb +111 -0
  162. data/test/factories/suppressions.rb +71 -0
  163. data/test/factories/tags.rb +12 -0
  164. data/test/factories/teams.rb +32 -0
  165. data/test/factories/users.rb +54 -0
  166. data/test/json_strategy.rb +25 -0
  167. data/test/test_helper.rb +44 -5
  168. metadata +387 -119
  169. data/bin/esp_repl +0 -60
  170. data/lib/esp_sdk/api.rb +0 -33
  171. data/lib/esp_sdk/client.rb +0 -62
  172. data/lib/esp_sdk/configure.rb +0 -40
  173. data/lib/esp_sdk/end_points/base.rb +0 -102
  174. data/lib/esp_sdk/end_points/contact_requests.rb +0 -6
  175. data/lib/esp_sdk/end_points/custom_signatures.rb +0 -41
  176. data/lib/esp_sdk/end_points/dashboard.rb +0 -35
  177. data/lib/esp_sdk/end_points/external_accounts.rb +0 -9
  178. data/lib/esp_sdk/end_points/organizations.rb +0 -6
  179. data/lib/esp_sdk/end_points/reports.rb +0 -6
  180. data/lib/esp_sdk/end_points/services.rb +0 -6
  181. data/lib/esp_sdk/end_points/signatures.rb +0 -39
  182. data/lib/esp_sdk/end_points/sub_organizations.rb +0 -6
  183. data/lib/esp_sdk/end_points/teams.rb +0 -6
  184. data/lib/esp_sdk/end_points/users.rb +0 -6
  185. data/lib/esp_sdk/exceptions.rb +0 -8
  186. data/lib/esp_sdk/extensions/rest_client/request.rb +0 -9
  187. data/lib/esp_sdk/repl.rb +0 -61
  188. data/lib/esp_sdk/version.rb +0 -3
  189. data/test/esp_sdk/api_test.rb +0 -36
  190. data/test/esp_sdk/client_test.rb +0 -129
  191. data/test/esp_sdk/configure_test.rb +0 -65
  192. data/test/esp_sdk/end_points/.keep +0 -0
  193. data/test/esp_sdk/end_points/base_test.rb +0 -230
  194. data/test/esp_sdk/end_points/custom_signatures_test.rb +0 -90
  195. data/test/esp_sdk/end_points/dashboard_test.rb +0 -55
  196. data/test/esp_sdk/end_points/external_accounts_test.rb +0 -20
  197. data/test/esp_sdk/end_points/signatures_test.rb +0 -83
  198. data/test/esp_sdk/exceptions_test.rb +0 -41
  199. data/test/esp_sdk_test.rb +0 -70
data/bin/esp_repl DELETED
@@ -1,60 +0,0 @@
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/lib/esp_sdk/api.rb DELETED
@@ -1,33 +0,0 @@
1
- module EspSdk
2
- class Api
3
- attr_reader :end_points, :config
4
-
5
- def initialize(options = {})
6
- options[:email] ||= options_errors(:email)
7
- options_errors(:password) if options[:token].blank? && options[:password].blank?
8
- @config = Configure.new(options)
9
- @end_points = []
10
- define_methods
11
- end
12
-
13
- private
14
-
15
- def define_methods
16
- end_points = EspSdk::EndPoints.constants - [:Base]
17
-
18
- end_points.each do |end_point|
19
- name = end_point.to_s.underscore
20
- define_singleton_method name do
21
- return instance_variable_get(:"@#{name}") if instance_variable_get(:"@#{name}").present?
22
- instance_variable_set(:"@#{name}", EspSdk::EndPoints.const_get(end_point).new(config))
23
- end
24
-
25
- @end_points << send(name)
26
- end
27
- end
28
-
29
- def options_errors(option)
30
- ENV["ESP_#{option.upcase}"] || fail(EspSdk::MissingAttribute, "Missing required #{option}") # rubocop:disable all
31
- end
32
- end
33
- end
@@ -1,62 +0,0 @@
1
- require 'rest_client'
2
- require_relative 'extensions/rest_client/request'
3
-
4
- module EspSdk
5
- # Client class for our endpoints. Every endpoint gets its own client.
6
- class Client
7
- attr_reader :config, :errors
8
-
9
- def initialize(config)
10
- @config = config
11
- end
12
-
13
- def connect(url, type = :get, payload = {})
14
- payload = { payload_key => payload } if payload.present?
15
-
16
- begin
17
- if type == :get || type == :delete
18
- if payload.present?
19
- response = RestClient.send(type, url, headers.merge(params: payload))
20
- else
21
- response = RestClient.send(type, url, headers)
22
- end
23
- else
24
- # The rest of our actions will require a payload
25
- fail MissingAttribute, 'Missing required attributes' if payload.blank?
26
- response = RestClient.send(type, url, payload, headers)
27
- end
28
- rescue RestClient::Unauthorized => e
29
- fail EspSdk::Unauthorized, 'Unauthorized request'
30
- rescue RestClient::UnprocessableEntity => e
31
- response = e.response
32
- body = JSON.load(response.body) if response.body.present?
33
- check_errors(body)
34
- end
35
-
36
- response
37
- end
38
-
39
- private
40
-
41
- def headers
42
- @headers ||= { 'Authorization' => @config.token, 'Authorization-Email' => @config.email, 'Content-Type' => 'application/json', 'Accept' => 'application/json' }
43
- end
44
-
45
- def payload_key
46
- @payload_key ||= self.class.to_s.demodulize.singularize.underscore
47
- end
48
-
49
- def check_errors(body)
50
- @errors = body['errors'] if body.present? && body.is_a?(Hash) && body['errors'].present?
51
- return unless @errors.present?
52
-
53
- if @errors.select { |error| error.to_s.include?('Token has expired') }.present?
54
- fail TokenExpired, 'Token has expired'
55
- elsif (error = @errors.select { |error| error.to_s.include?('Record not found') }[0]).present?
56
- fail RecordNotFound, error
57
- else
58
- fail EspSdk::Exception, "#{@errors.join('. ')}"
59
- end
60
- end
61
- end
62
- end
@@ -1,40 +0,0 @@
1
- module EspSdk
2
- class Configure
3
- attr_accessor :token, :email, :version, :token_expires_at, :end_point, :domain
4
-
5
- def initialize(options)
6
- self.email = options[:email]
7
- self.version = options[:version] || 'v1'
8
- self.domain = options[:domain]
9
- self.token = options[:password] || options[:token]
10
- self.end_point = options[:password].present? ? 'new' : 'valid'
11
- token_setup
12
- end
13
-
14
- def url(endpoint)
15
- "#{domain}/api/#{version}/#{endpoint}"
16
- end
17
-
18
- def domain
19
- return @domain if @domain.present?
20
- if EspSdk.production?
21
- self.domain = 'https://api.evident.io'
22
- elsif EspSdk.release?
23
- self.domain = 'https://api-rel.evident.io'
24
- else
25
- self.domain = 'http://0.0.0.0:3000'
26
- end
27
- end
28
-
29
- private
30
-
31
- def token_setup
32
- client = Client.new(self)
33
- response = client.connect(url("token/#{end_point}"))
34
- user = JSON.load(response.body)
35
- self.token = user['authentication_token']
36
- self.token_expires_at = user['token_expires_at'].to_s.to_datetime.utc ||
37
- 1.hour.from_now.to_datetime.utc
38
- end
39
- end
40
- end
@@ -1,102 +0,0 @@
1
- require 'json'
2
-
3
- module EspSdk
4
- module EndPoints
5
- class Base < EspSdk::Client
6
- attr_reader :current_page, :current_record
7
-
8
- def next_page
9
- return list if current_page.blank?
10
-
11
- if @page_links['next'].present?
12
- response = connect(@page_links['next'], :get)
13
- pagination_links(response)
14
- self.current_page = JSON.load(response.body)
15
- else
16
- @current_page
17
- end
18
- end
19
-
20
- def prev_page
21
- return list if current_page.blank?
22
-
23
- if @page_links['prev'].present?
24
- response = connect(@page_links['prev'], :get)
25
- pagination_links(response)
26
- self.current_page = JSON.load(response.body)
27
- else
28
- @current_page
29
- end
30
- end
31
-
32
- # Get a pageable list of records
33
- def list
34
- response = connect(base_url, :get)
35
- pagination_links(response)
36
- self.current_page = JSON.load(response.body)
37
- end
38
-
39
- # Get a single record
40
- def show(params = {})
41
- validate_id(params)
42
- submit(id_url(params.delete(:id)), :get)
43
- end
44
-
45
- # Update a single record
46
- def update(params = {})
47
- validate_id(params)
48
- submit(id_url(params.delete(:id)), :patch, params)
49
- end
50
-
51
- # Destroy a single record
52
- def destroy(params = {})
53
- validate_id(params)
54
- submit(id_url(params.delete(:id)), :delete)
55
- end
56
-
57
- # Create a new record
58
- def create(params = {})
59
- submit(base_url, :post, params)
60
- end
61
-
62
- private
63
-
64
- def validate_id(params)
65
- fail MissingAttribute, 'Missing required attribute id' if params[:id].blank?
66
- end
67
-
68
- def id_url(id)
69
- "#{base_url}/#{id}"
70
- end
71
-
72
- def base_url
73
- config.url(self.class.to_s.demodulize.underscore)
74
- end
75
-
76
- def submit(url, type, options = {})
77
- response = connect(url, type, options)
78
- @current_record = ActiveSupport::HashWithIndifferentAccess.new(JSON.load(response.body))
79
- end
80
-
81
- # Converts the link header into a hash of links
82
- #
83
- # "<http://test.host/api/v1/custom_signatures?page=2>; rel=\"last\", <http://test.host/api/v1/custom_signatures?page=2>; rel=\"next\""
84
- # => { "last" => "http://test.host/api/v1/custom_signatures?page=2",
85
- # "next" => "http://test.host/api/v1/custom_signatures?page=2" }
86
- def pagination_links(response)
87
- @page_links = ActiveSupport::HashWithIndifferentAccess.new(JSON.load(response.headers[:link]))
88
- rescue JSON::ParserError
89
- @page_links = ActiveSupport::HashWithIndifferentAccess.new.tap do |page_links|
90
- response.headers[:link].to_s.split(',').each do |link|
91
- /<(?<link>.*)>; rel="(?<key>\w*)"/ =~ link
92
- page_links[key] = link
93
- end
94
- end
95
- end
96
-
97
- def current_page=(values)
98
- @current_page = values.map(&:with_indifferent_access)
99
- end
100
- end
101
- end
102
- end
@@ -1,6 +0,0 @@
1
- module EspSdk
2
- module EndPoints
3
- class ContactRequests < Base
4
- end
5
- end
6
- end
@@ -1,41 +0,0 @@
1
- module EspSdk
2
- module EndPoints
3
- class CustomSignatures < Base
4
- def run(params = {})
5
- validate_run_params(valid_run_params, params.keys)
6
- submit(run_url, :post, params)
7
- end
8
-
9
- def run_raw(params = {})
10
- validate_run_params(valid_run_raw_params, params.keys)
11
- submit(run_url, :post, params)
12
- end
13
-
14
- private
15
-
16
- def run_url
17
- "#{base_url}/run"
18
- end
19
-
20
- def valid_run_params
21
- [:id, :regions, :external_account_id, :language]
22
- end
23
-
24
- def valid_run_raw_params
25
- [:signature, :regions, :external_account_id, :language]
26
- end
27
-
28
- def validate_run_params(valid_params, keys)
29
- # Check that all the valid params are present
30
- valid_params.each do |param|
31
- fail MissingAttribute, "Missing required attribute #{param}" unless keys.include?(param)
32
- end
33
-
34
- # Check for invalid params
35
- keys.each do |key|
36
- fail UnknownAttribute, "Unknown attribute #{key}" unless valid_params.include?(key)
37
- end
38
- end
39
- end
40
- end
41
- end
@@ -1,35 +0,0 @@
1
- module EspSdk
2
- module EndPoints
3
- class Dashboard < Base
4
- def list
5
- response = connect(base_url, :get)
6
- @current_page = JSON.load(response.body).with_indifferent_access
7
- end
8
-
9
- def timewarp(params = {})
10
- validate_timewarp_params(params.keys)
11
- submit(timewarp_url, :post, params)
12
- end
13
-
14
- private
15
-
16
- def timewarp_url
17
- "#{base_url}/timewarp"
18
- end
19
-
20
- def validate_timewarp_params(keys)
21
- valid_timewarp_params = [:time]
22
-
23
- # Check that all the valid params are present
24
- valid_timewarp_params.each do |param|
25
- fail MissingAttribute, "Missing required attribute #{param}" unless keys.include?(param)
26
- end
27
-
28
- # Check for invalid params
29
- keys.each do |key|
30
- fail UnknownAttribute, "Unknown attribute #{key}" unless valid_timewarp_params.include?(key)
31
- end
32
- end
33
- end
34
- end
35
- end
@@ -1,9 +0,0 @@
1
- module EspSdk
2
- module EndPoints
3
- class ExternalAccounts < Base
4
- def generate_external_id
5
- SecureRandom.uuid
6
- end
7
- end
8
- end
9
- end
@@ -1,6 +0,0 @@
1
- module EspSdk
2
- module EndPoints
3
- class Organizations < Base
4
- end
5
- end
6
- end
@@ -1,6 +0,0 @@
1
- module EspSdk
2
- module EndPoints
3
- class Reports < Base
4
- end
5
- end
6
- end
@@ -1,6 +0,0 @@
1
- module EspSdk
2
- module EndPoints
3
- class Services < Base
4
- end
5
- end
6
- end
@@ -1,39 +0,0 @@
1
- module EspSdk
2
- module EndPoints
3
- class Signatures < Base
4
- def run(params = {})
5
- validate_run_params(params)
6
- submit(run_url, :post, params)
7
- end
8
-
9
- def names
10
- submit(name_url, :get)
11
- end
12
-
13
- private
14
-
15
- def run_url
16
- "#{base_url}/run"
17
- end
18
-
19
- def name_url
20
- "#{base_url}/signature_names"
21
- end
22
-
23
- def validate_run_params(options)
24
- valid_params = [:signature_name, :regions, :external_account_id]
25
- keys = options.keys
26
-
27
- # Check that all the valid params are present
28
- valid_params.each do |param|
29
- fail EspSdk::MissingAttribute, "Missing required attribute #{param}" unless keys.include?(param)
30
- end
31
-
32
- # Check for invalid params
33
- keys.each do |key|
34
- fail EspSdk::UnknownAttribute, "Unknown attribute #{key}" unless valid_params.include?(key)
35
- end
36
- end
37
- end
38
- end
39
- end
@@ -1,6 +0,0 @@
1
- module EspSdk
2
- module EndPoints
3
- class SubOrganizations < Base
4
- end
5
- end
6
- end
@@ -1,6 +0,0 @@
1
- module EspSdk
2
- module EndPoints
3
- class Teams < Base
4
- end
5
- end
6
- end
@@ -1,6 +0,0 @@
1
- module EspSdk
2
- module EndPoints
3
- class Users < Base
4
- end
5
- end
6
- end
@@ -1,8 +0,0 @@
1
- module EspSdk
2
- class MissingAttribute < StandardError; end
3
- class UnknownAttribute < StandardError; end
4
- class TokenExpired < StandardError; end
5
- class RecordNotFound < StandardError; end
6
- class Exception < StandardError; end
7
- class Unauthorized < StandardError; end
8
- end
@@ -1,9 +0,0 @@
1
- module RestClient
2
- class Request
3
- # Override execute to always use SSLv23
4
- def self.execute(args, &block)
5
- args.merge!(ssl_version: 'SSLv23')
6
- new(args).execute(& block)
7
- end
8
- end
9
- end
data/lib/esp_sdk/repl.rb DELETED
@@ -1,61 +0,0 @@
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 +0,0 @@
1
- module EspSdk
2
- VERSION = '1.1.0'
3
- end
@@ -1,36 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
-
3
- class ApiTest < ActiveSupport::TestCase
4
- context 'Api' do
5
- context '#initalize' do
6
- should 'raise a MissingAttribute error for a missing email' do
7
- e = assert_raises EspSdk::MissingAttribute do
8
- EspSdk::Api.new()
9
- end
10
-
11
- assert_equal 'Missing required email', e.message
12
- end
13
- should 'raise a MissingAttribute error for a missing token and password' do
14
- e = assert_raises EspSdk::MissingAttribute do
15
- EspSdk::Api.new(email: 'test@evident.io')
16
- end
17
-
18
- assert_equal 'Missing required password', e.message
19
- end
20
-
21
- should 'define our endpoint methods and add them to the end_points array' do
22
- # Stub the token setup for our configuration object
23
- EspSdk::Configure.any_instance.expects(:token_setup).returns(nil).at_least_once
24
- api = EspSdk::Api.new(email: 'test@evident.io', password: 'password')
25
- end_points = (EspSdk::EndPoints.constants - [:Base]).map(&:to_s).map(&:underscore)
26
- methods = api.singleton_methods.map(&:to_s)
27
-
28
- assert_equal end_points.count, api.end_points.count
29
-
30
- methods.each do |method|
31
- assert_includes end_points, method
32
- end
33
- end
34
- end
35
- end
36
- end