perimeter_x 1.1.0 → 1.2.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: 8821c69fed2516694f5cfc66c4fd86cb8350e1c6
4
- data.tar.gz: cb26bfa40459f6e0745c9d1d1bdb94a07ade258b
3
+ metadata.gz: 52e3418c30763e225706ca5ee7a3a88958c4a210
4
+ data.tar.gz: 4671a1eb52edc4cfdb9ba4e85932c2dcb7e33dbb
5
5
  SHA512:
6
- metadata.gz: 79d0af263099a0b1cc363546e26a2c7c3c42b80e71a7eb1b39c9f07a784ad5ad925598aa42be2036cc79620528762398c4ac58d1ee448ca792b55aa422bf2784
7
- data.tar.gz: a13e5dab8ce2a5a9380996921799a5e90bb3b141f10b08b13821b07ff36efaa6cb12c1b853f7071e7ebcc3d2ffa84e21233d8442f07a01aa3607a80f287edf77
6
+ metadata.gz: 13ca73c6ac3c22ff0d9d93d42cab42049a06e458f9596538cd2225a07dd1ea9e20db8bf4c6921519ed29c349e717eb929643051ef1510337b1414bf6ea8f6c01
7
+ data.tar.gz: 2bc1a8fe0845f3899537bb34151c545ea7c6a5343b271c7bceb4d221a9551d74dec174042e30b02e7e29d533d7e0453235163ee0635d2275576c75ed4758efd5
data/Dockerfile CHANGED
@@ -1,50 +1,21 @@
1
1
  # Based on manual compile instructions at http://wiki.nginx.org/HttpLuaModule#Installation
2
- FROM ubuntu:14.04
3
- RUN apt-get update && apt-get --force-yes -qq -y install \
4
- build-essential \
5
- ca-certificates \
6
- curl \
7
- git \
8
- libpcre3 \
9
- libpcre3-dev \
10
- libssl-dev \
11
- libreadline-dev \
12
- libyaml-dev \
13
- libgdbm-dev \
14
- libtool \
15
- automake \
16
- bison \
17
- lua-cjson \
18
- libncurses5-dev \
19
- m4 \
20
- libsqlite3-dev \
21
- rsyslog \
22
- sqlite3 \
23
- libxml2-dev \
24
- libxslt1-dev \
25
- libcurl4-openssl-dev \
26
- python-software-properties \
27
- libffi-dev \
28
- nodejs \
29
- wget \
30
- zlib1g-dev
2
+ FROM ruby:2.3.0
31
3
 
32
- RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3
33
- RUN /bin/bash -l -c "curl -L get.rvm.io | bash -s stable --rails"
34
- RUN /bin/bash -l -c "rvm install 2.3.0"
35
- RUN /bin/bash -l -c "rvm use 2.3.0"
36
- RUN /bin/bash -l -c "gem install bundler"
37
- RUN /bin/bash -l -c "gem install rails -v 4.2.0"
4
+ RUN apt-get update && apt-get --force-yes -qq -y install \
5
+ nodejs
6
+ ENV RAILS_VERSION 4.2.0
7
+ RUN gem install rails --version "$RAILS_VERSION"
8
+ RUN gem install bundler
38
9
  RUN mkdir -p /tmp/ruby_sandbox
39
10
  WORKDIR /tmp/ruby_sandbox
40
11
  RUN git clone https://github.com/PerimeterX/perimeterx-ruby-sdk.git
41
- RUN /bin/bash -l -c "rails new webapp"
12
+ RUN rails new webapp
42
13
  WORKDIR /tmp/ruby_sandbox/webapp
43
- RUN /bin/bash -l -c "rails generate controller home index"
14
+
15
+ RUN rails generate controller home index
44
16
  WORKDIR /tmp/ruby_sandbox/webapp
45
17
  EXPOSE 3000
46
- # TODO: make it take the files from git
47
18
  RUN sed -i '2i gem "perimeter_x", :path => "/tmp/ruby_sandbox/perimeterx-ruby-sdk"' /tmp/ruby_sandbox/webapp/Gemfile
48
- RUN /bin/bash -l -c "bundler update"
19
+ RUN bundler update
49
20
  COPY ./examples/ /tmp/ruby_sandbox/webapp
50
- CMD ["/bin/bash", "-l", "-c", "rails server -b 0.0.0.0;"]
21
+ CMD ["rails","server","-b","0.0.0.0"]
data/changelog.md CHANGED
@@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
6
6
  and this project adheres to [Semantic Versioning](http://semver.org/).
7
7
 
8
+ ## [1.2.0] - 2017-06-04
9
+ ### Fixed
10
+ - Default timeouts for post api requests
11
+ - Fixed Dockerfile
12
+ ### Changed
13
+ - Removed httpclient and instead using typheous
14
+ ### Added
15
+ - Using concurrent-ruby for async post requests
16
+
8
17
  ## [1.1.0] - 2017-06-04
9
18
  ### Added
10
19
  - Added support for sensitive routes
@@ -17,9 +17,9 @@ module PxModule
17
17
  :encryption_enabled => true,
18
18
  :blocking_score => 70,
19
19
  :sensitive_headers => ["http-cookie", "http-cookies"],
20
- :api_connect_timeout => 0,
21
- :api_timeout => 0,
22
- :max_buffer_len => 30,
20
+ :api_connect_timeout => 1,
21
+ :api_timeout => 1,
22
+ :max_buffer_len => 10,
23
23
  :send_page_activities => false,
24
24
  :send_block_activities => true,
25
25
  :sdk_name => PxModule::SDK_NAME,
@@ -3,12 +3,10 @@ require 'perimeterx/internal/clients/perimeter_x_risk_client'
3
3
  module PxModule
4
4
  class PerimeterxActivitiesClient < PerimeterxRiskClient
5
5
 
6
- attr_accessor :activities
7
6
 
8
7
  def initialize(px_config, http_client)
9
8
  super(px_config, http_client)
10
9
  @logger.debug("PerimeterxActivitiesClients[initialize]")
11
- @activities = [];
12
10
  end
13
11
 
14
12
  def send_to_perimeterx(activity_type, px_ctx, details = [])
@@ -41,13 +39,10 @@ module PxModule
41
39
  "Content-Type" => "application/json"
42
40
  };
43
41
 
44
- @activities.push(px_data)
45
- if (@activities.size == @px_config[:max_buffer_len])
46
- @logger.debug("PerimeterxActivitiesClients[send_to_perimeterx]: max buffer length reached, sending activities")
47
- @http_client.async_post(PxModule::API_V1_S2S, @activities, headers)
48
-
49
- @activities.clear
50
- end
42
+ s = Time.now
43
+ @http_client.async.post(PxModule::API_V1_S2S, px_data, headers)
44
+ e = Time.now
45
+ @logger.debug("PerimeterxActivitiesClients[send_to_perimeterx]: post runtime #{(e-s)*1000}")
51
46
  end
52
47
 
53
48
  def send_block_activity(px_ctx)
@@ -27,7 +27,7 @@ module PxModule
27
27
  "Content-Type" => "application/json"
28
28
  };
29
29
 
30
- return @http_client.post(PxModule::API_V1_CAPTCHA, request_body, headers, @px_config[:api_timeout])
30
+ return @http_client.post(PxModule::API_V1_CAPTCHA, request_body, headers, @px_config[:api_timeout], @px_config[:api_timeout_connection])
31
31
 
32
32
  end
33
33
 
@@ -67,9 +67,9 @@ module PxModule
67
67
 
68
68
  # Custom risk handler
69
69
  if (risk_mode == PxModule::ACTIVE_MODE && @px_config.key?(:custom_risk_handler))
70
- response = @px_config[:custom_risk_handler].call(PxModule::API_V2_RISK, request_body, headers, @px_config[:api_timeout])
70
+ response = @px_config[:custom_risk_handler].call(PxModule::API_V2_RISK, request_body, headers, @px_config[:api_timeout], @px_config[:api_timeout_connection])
71
71
  else
72
- response = @http_client.post(PxModule::API_V2_RISK , request_body, headers)
72
+ response = @http_client.post(PxModule::API_V2_RISK , request_body, headers, @px_config[:api_timeout], @px_config[:api_timeout_connection])
73
73
  end
74
74
  return response
75
75
  end
@@ -83,9 +83,9 @@ module PxModule
83
83
  px_ctx.context[:made_s2s_risk_api_call] = true
84
84
 
85
85
  # From here response should be valid, if success or error
86
- response_body = eval(response.content);
86
+ response_body = eval(response.body);
87
87
  # When success
88
- if (response.status == 200 && response_body.key?(:score) && response_body.key?(:action))
88
+ if (response.code == 200 && response_body.key?(:score) && response_body.key?(:action))
89
89
  @logger.debug("PerimeterxS2SValidator[verify]: response ok")
90
90
  score = response_body[:score]
91
91
  px_ctx.context[:score] = score
@@ -100,7 +100,7 @@ module PxModule
100
100
  end #end success response
101
101
 
102
102
  # When error
103
- if(response.status != 200)
103
+ if(response.code != 200)
104
104
  @logger.warn("PerimeterxS2SValidator[verify]: bad response, return code #{response.code}")
105
105
  px_ctx.context[:uuid] = ""
106
106
  px_ctx.context[:s2s_error_msg] = response_body[:message]
@@ -1,53 +1,47 @@
1
- require "perimeterx/utils/px_logger"
2
- require "httpclient"
1
+ require 'perimeterx/utils/px_logger'
2
+ require 'typhoeus'
3
+ require 'concurrent'
3
4
 
4
5
  module PxModule
5
6
  class PxHttpClient
7
+ include Concurrent::Async
8
+
6
9
  attr_accessor :px_config
7
- attr_accessor :BASE_URL
8
- attr_accessor :http_client
10
+ attr_accessor :px_client
9
11
 
10
12
  def initialize(px_config)
11
13
  @px_config = px_config
12
- @http_client = HTTPClient.new(:base_url => px_config[:perimeterx_server_host])
13
14
  @logger = px_config[:logger]
14
15
  @logger.debug("PxHttpClient[initialize]: HTTP client is being initilized with base_uri: #{px_config[:perimeterx_server_host]}")
15
16
  end
16
17
 
17
- def post(path, body, headers, api_timeout = 0, timeoute = 0)
18
- s = Time.now
19
- begin
20
- @logger.debug("PxHttpClient[post]: posting to #{path} headers {#{headers.to_json()}} body: {#{body.to_json()}} ")
21
- response = @http_client.post(path,
22
- :header => headers,
23
- :body => body.to_json(),
24
- :timeout => api_timeout
25
- )
26
- rescue Net::OpenTimeout, Net::ReadTimeout => error
27
- @logger.warn("PerimeterxS2SValidator[verify]: request timedout")
28
- return false
29
- end
30
- e = Time.now
31
- @logger.debug("PxHttpClient[post]: runtime: #{e-s}")
32
- return response
33
- end
18
+ # Runs a POST commant to Perimeter X servers
19
+ # Params:
20
+ # +path+:: string containing uri
21
+ # +body+:: hash object, containing the request body, must be converted to json format
22
+ # +headers+:: hash object, hold headers
23
+ # +api_timeout+:: int, sets the timeout for a request
24
+ # +connection_timeout+:: int, sets the timeout for opening a connection
34
25
 
35
- def async_post(path, body, headers, api_timeout = 0, timeoute = 0)
36
- @logger.debug("PxHttpClient[async_post]: posting to #{path} headers {#{headers.to_json()}} body: {#{body.to_json()}} ")
26
+ def post(path, body, headers, api_timeout = 1, connection_timeout = 1)
37
27
  s = Time.now
38
28
  begin
39
29
  @logger.debug("PxHttpClient[post]: posting to #{path} headers {#{headers.to_json()}} body: {#{body.to_json()}} ")
40
- response = @http_client.post_async(path,
41
- :header => headers,
42
- :body => body.to_json(),
43
- :timeout => api_timeout
44
- )
45
- rescue Net::OpenTimeout, Net::ReadTimeout => error
46
- @logger.warn("PerimeterxS2SValidator[verify]: request timedout")
47
- return false
30
+ response = Typhoeus.post(
31
+ "#{px_config[:perimeterx_server_host]}#{path}",
32
+ headers: headers,
33
+ body: body.to_json,
34
+ timeout: api_timeout,
35
+ connecttimeout: connection_timeout
36
+ )
37
+ if response.timed_out?
38
+ @logger.warn('PerimeterxS2SValidator[verify]: request timed out')
39
+ return false
40
+ end
41
+ ensure
42
+ e = Time.now
43
+ @logger.debug("PxHttpClient[post]: runtime: #{(e-s) * 1000.0}")
48
44
  end
49
- e = Time.now
50
- @logger.debug("PxHttpClient[post]: runtime: #{e-s}")
51
45
  return response
52
46
  end
53
47
 
@@ -1,3 +1,3 @@
1
1
  module PxModule
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
data/perimeter_x.gemspec CHANGED
@@ -30,7 +30,8 @@ Gem::Specification.new do |gem|
30
30
 
31
31
  gem.required_ruby_version = '>= 2.3'
32
32
 
33
- gem.add_dependency('httpclient', '2.8.2.4')
33
+ gem.add_dependency('concurrent-ruby', '~> 1.0', '>= 1.0.5')
34
+ gem.add_dependency('typhoeus', '~> 1.1', '>= 1.1.2')
34
35
  gem.add_dependency('mustache', '~> 1.0', '>= 1.0.3')
35
36
  gem.add_dependency('activesupport', '>= 4.2.0')
36
37
 
data/readme.md CHANGED
@@ -31,7 +31,8 @@ Table of Contents
31
31
 
32
32
  - Ruby version 2.3+
33
33
  - Rails version 4.2
34
- - [httpclient](https://rubygems.org/gems/httpclient/versions/2.8.3)
34
+ - [concurrent-ruby](https://github.com/ruby-concurrency/concurrent-ruby)
35
+ - [typhoeus](https://github.com/typhoeus/typhoeus)
35
36
  - [mustache](https://rubygems.org/gems/mustache)
36
37
 
37
38
  <a name="installation"></a> Installation
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: perimeter_x
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nitzan Goldfeder
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-04 00:00:00.000000000 Z
11
+ date: 2017-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -39,19 +39,45 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: httpclient
42
+ name: concurrent-ruby
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '='
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ - - ">="
46
49
  - !ruby/object:Gem::Version
47
- version: 2.8.2.4
50
+ version: 1.0.5
48
51
  type: :runtime
49
52
  prerelease: false
50
53
  version_requirements: !ruby/object:Gem::Requirement
51
54
  requirements:
52
- - - '='
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '1.0'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 1.0.5
61
+ - !ruby/object:Gem::Dependency
62
+ name: typhoeus
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.1'
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: 1.1.2
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '1.1'
78
+ - - ">="
53
79
  - !ruby/object:Gem::Version
54
- version: 2.8.2.4
80
+ version: 1.1.2
55
81
  - !ruby/object:Gem::Dependency
56
82
  name: mustache
57
83
  requirement: !ruby/object:Gem::Requirement