union_station_hooks_core 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,161 @@
1
+ # Union Station - https://www.unionstationapp.com/
2
+ # Copyright (c) 2010-2015 Phusion Holding B.V.
3
+ #
4
+ # "Union Station" and "Passenger" are trademarks of Phusion Holding B.V.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+
24
+ require 'base64'
25
+
26
+ module UnionStationHooks
27
+ # Various utility methods.
28
+ #
29
+ # @private
30
+ module Utils
31
+ extend self # Make methods available as class methods.
32
+
33
+ def self.included(klass)
34
+ # When included into another class, make sure that Utils
35
+ # methods are made private.
36
+ public_instance_methods(false).each do |method_name|
37
+ klass.send(:private, method_name)
38
+ end
39
+ end
40
+
41
+ def require_key(options, key)
42
+ if !options.key?(key)
43
+ raise ArgumentError, "Option #{key.inspect} is required"
44
+ end
45
+ end
46
+
47
+ def require_non_empty_key(options, key)
48
+ value = options[key]
49
+ if value.nil? || value.empty?
50
+ raise ArgumentError, "Option #{key.inspect} is required " \
51
+ 'and must be non-empty'
52
+ else
53
+ value
54
+ end
55
+ end
56
+
57
+ def get_socket_address_type(address)
58
+ if address =~ %r{^unix:.}
59
+ :unix
60
+ elsif address =~ %r{^tcp://.}
61
+ :tcp
62
+ else
63
+ :unknown
64
+ end
65
+ end
66
+
67
+ def connect_to_server(address)
68
+ case get_socket_address_type(address)
69
+ when :unix
70
+ UNIXSocket.new(address.sub(/^unix:/, ''))
71
+ when :tcp
72
+ host, port = address.sub(%r{^tcp://}, '').split(':', 2)
73
+ port = port.to_i
74
+ TCPSocket.new(host, port)
75
+ else
76
+ raise ArgumentError, "Unknown socket address type for '#{address}'."
77
+ end
78
+ end
79
+
80
+ def local_socket_address?(address)
81
+ case get_socket_address_type(address)
82
+ when :unix
83
+ return true
84
+ when :tcp
85
+ host, _port = address.sub(%r{^tcp://}, '').split(':', 2)
86
+ host == '127.0.0.1' || host == '::1' || host == 'localhost'
87
+ else
88
+ raise ArgumentError, "Unknown socket address type for '#{address}'."
89
+ end
90
+ end
91
+
92
+ def encoded_timestamp(time = Time.now)
93
+ timestamp = time.to_i * 1_000_000 + time.usec
94
+ timestamp.to_s(36)
95
+ end
96
+
97
+ if Base64.respond_to?(:strict_encode64)
98
+ def base64(data)
99
+ Base64.strict_encode64(data)
100
+ end
101
+ else
102
+ # Base64-encodes the given data. Newlines are removed.
103
+ # This is like `Base64.strict_encode64`, but also works
104
+ # on Ruby 1.8 which doesn't have that method.
105
+ def base64(data)
106
+ result = Base64.encode64(data)
107
+ result.delete!("\n")
108
+ result
109
+ end
110
+ end
111
+
112
+ def process_ust_router_reply(channel, error_description,
113
+ error_class = RuntimeError,
114
+ unexpected_error_class = RuntimeError)
115
+ result = channel.read
116
+ if result.nil?
117
+ raise unexpected_error_class,
118
+ "#{error_description}: UstRouter did not send a reply"
119
+ end
120
+ process_ust_router_reply_message(result, error_description,
121
+ error_class, unexpected_error_class)
122
+ result
123
+ end
124
+
125
+ def process_ust_router_reply_message(message, error_description,
126
+ error_class = RuntimeError,
127
+ unexpected_error_class = RuntimeError)
128
+ if message[0] != 'status'
129
+ raise unexpected_error_class,
130
+ "#{error_description}: expected UstRouter to respond with " \
131
+ "'status', but got #{message.inspect} instead"
132
+ end
133
+
134
+ if message[1] == 'error'
135
+ if message[2]
136
+ raise error_class, "#{error_description}: #{message[2]}"
137
+ else
138
+ raise error_class, "#{error_description} (no server message given)"
139
+ end
140
+ elsif message[1] != 'ok'
141
+ raise unexpected_error_class,
142
+ "#{error_description}: expected UstRouter to respond with " \
143
+ "'ok' or 'error', but got #{message.inspect} instead"
144
+ end
145
+ end
146
+
147
+ if defined?(PhusionPassenger::NativeSupport)
148
+ def process_times
149
+ PhusionPassenger::NativeSupport.process_times
150
+ end
151
+ else
152
+ ProcessTimes = Struct.new(:utime, :stime)
153
+
154
+ def process_times
155
+ times = Process.times
156
+ ProcessTimes.new((times.utime * 1_000_000).to_i,
157
+ (times.stime * 1_000_000).to_i)
158
+ end
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,32 @@
1
+ # Union Station - https://www.unionstationapp.com/
2
+ # Copyright (c) 2010-2015 Phusion Holding B.V.
3
+ #
4
+ # "Union Station" and "Passenger" are trademarks of Phusion Holding B.V.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+
24
+
25
+ module UnionStationHooks
26
+ version_file = File.expand_path('version_data.rb', File.dirname(__FILE__))
27
+ version_data = eval(File.read(version_file))
28
+ MAJOR_VERSION = version_data[:major]
29
+ MINOR_VERSION = version_data[:minor]
30
+ TINY_VERSION = version_data[:tiny]
31
+ VERSION_STRING = version_data[:string]
32
+ end
@@ -0,0 +1,44 @@
1
+ # Union Station - https://www.unionstationapp.com/
2
+ # Copyright (c) 2010-2015 Phusion Holding B.V.
3
+ #
4
+ # "Union Station" and "Passenger" are trademarks of Phusion Holding B.V.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+
24
+ # This file contains union_station_hook_core's version number. It is meant
25
+ # to be read and evaluated by the gemspec. We do not define any functions or
26
+ # modules here because we need to support the following situation:
27
+ #
28
+ # 1. Passenger loads its vendored union_station_hooks_* gems. This defines
29
+ # various modules.
30
+ # 2. The app specified union_station_hooks_* gems in its Gemfile, which
31
+ # indicates that it wants to override Passenger's vendored
32
+ # union_station_hooks_* gems with its own versions. This will cause Bundler
33
+ # to load union_station_hooks_*.gemspec.
34
+ #
35
+ # To make the gemspecs load properly and without affecting the already-loaded
36
+ # union_station_hooks_* gems code, we must not define any functions or modules
37
+ # here.
38
+
39
+ {
40
+ :major => 1,
41
+ :minor => 0,
42
+ :tiny => 0,
43
+ :string => '1.0.0'
44
+ }
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: union_station_hooks_core
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Hongli Lai
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-09 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Union Station Ruby hooks core code.
14
+ email: info@phusion.nl
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - LICENSE.md
20
+ - README.md
21
+ - lib/union_station_hooks_core.rb
22
+ - lib/union_station_hooks_core/api.rb
23
+ - lib/union_station_hooks_core/connection.rb
24
+ - lib/union_station_hooks_core/context.rb
25
+ - lib/union_station_hooks_core/lock.rb
26
+ - lib/union_station_hooks_core/log.rb
27
+ - lib/union_station_hooks_core/message_channel.rb
28
+ - lib/union_station_hooks_core/request_reporter.rb
29
+ - lib/union_station_hooks_core/request_reporter/basics.rb
30
+ - lib/union_station_hooks_core/request_reporter/controllers.rb
31
+ - lib/union_station_hooks_core/request_reporter/misc.rb
32
+ - lib/union_station_hooks_core/request_reporter/view_rendering.rb
33
+ - lib/union_station_hooks_core/spec_helper.rb
34
+ - lib/union_station_hooks_core/time_point.rb
35
+ - lib/union_station_hooks_core/transaction.rb
36
+ - lib/union_station_hooks_core/utils.rb
37
+ - lib/union_station_hooks_core/version.rb
38
+ - lib/union_station_hooks_core/version_data.rb
39
+ homepage: https://github.com/phusion/union_station_hooks_core
40
+ licenses:
41
+ - MIT
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 2.2.2
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Union Station Ruby hooks core code
63
+ test_files: []
64
+ has_rdoc: