ocean-rails 7.0.5 → 7.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0838aa1ceee275569e027e38341000b6ef6d052b
4
- data.tar.gz: 7a215e48eb6d666f8611123ad34265118b78c9dc
3
+ metadata.gz: 5d602214f6705ec4f0af21ed3adcc1ce63de746e
4
+ data.tar.gz: e99a2a9a8d7484a8da4b3dc7e52bddb5e65838df
5
5
  SHA512:
6
- metadata.gz: 65e6de0a1effb6a88b960c991ddfcea0baa36fade0969edc36490a87acfd8df16515f870a3f38b452eb945dc7fe8439d4198da9d5751e0d18e2c8f1a3ab7c87c
7
- data.tar.gz: cc138ac59d2dd8e2de3e03b43ee5fe09bbcba3a9ab82cb25d64d96d0a9d9d3e54cd968841f0a740a0946fd00783bf0432a21c3f1e154b72dc0aad4ac35cdce92
6
+ metadata.gz: 67ca3ce19054513e77fb2697668bc659a8813ddc90955573802e9ffff443c6266554701e86fe7116b268c396e35dc157730525e8d10c2c896eeacb41f9be8c5f
7
+ data.tar.gz: c19110d878f51a4fd403734ea90fe680a79181ff4aecec25718cf8f7f65e1e19a16bc9762ebac8b38edbc015a57efdd04170721d1b3391f61f9bac836aaece9b
@@ -13,7 +13,7 @@ else
13
13
 
14
14
  # This is the tailored file, not under source control.
15
15
  f = File.join(Rails.root, "config/aws.yml")
16
-
16
+
17
17
  # If the tailored file doesn't exist, and we're running in test mode
18
18
  # (which is the case under TeamCity), use the example file as-is.
19
19
  unless File.exists?(f)
@@ -3,16 +3,16 @@
3
3
  # YOU SHOULD NEVER CHANGE THE CONTENTS OF THIS FILE.
4
4
  #
5
5
  # Backend developers should never need to override the value here.
6
- # The reason for this is that when developing services locally,
7
- # their tests run in isolation with all external calls mocked away,
8
- # and thus it doesn't matter what URLs a service generates when
6
+ # The reason for this is that when developing services locally,
7
+ # their tests run in isolation with all external calls mocked away,
8
+ # and thus it doesn't matter what URLs a service generates when
9
9
  # running tests locally on a developer's machine.
10
10
  #
11
11
  # If you're a frontend developer, however, the point of your testing
12
- # is to exercise the entire SOA and thus you need access to a
12
+ # is to exercise multiple services and thus you need access to a
13
13
  # complete and fully functional system (which might or might not
14
14
  # make calls to partners' systems, such as for hotel bookings).
15
- #
15
+ #
16
16
  # Thus, if you are a frontend developer, you override the string
17
17
  # constant here to reflect the Ocean environment (dev, staging)
18
18
  # you wish to run your local tests against by defining the environment
@@ -21,11 +21,11 @@
21
21
 
22
22
  BASE_DOMAIN = "example.com" unless defined?(BASE_DOMAIN) # For the Rails template generator
23
23
 
24
- OCEAN_API_HOST = (ENV['OCEAN_API_HOST'] ||
25
- (Rails.env == 'test' && "forbidden.#{BASE_DOMAIN}") ||
24
+ OCEAN_API_HOST = (ENV['OCEAN_API_HOST'] ||
25
+ (Rails.env == 'test' && "forbidden.#{BASE_DOMAIN}") ||
26
26
  "dev-api.#{BASE_DOMAIN}"
27
27
  ).sub("<default>", "dev")
28
-
28
+
29
29
  OCEAN_API_URL = "https://#{OCEAN_API_HOST}"
30
30
 
31
31
  INTERNAL_OCEAN_API_URL = OCEAN_API_URL.sub("https://", "http://")
@@ -1,4 +1,4 @@
1
- if Rails.env == 'production' && ENV['NO_ZEROMQ_LOGGING'].blank?
1
+ if false # Rails.env == 'production'
2
2
 
3
3
  def remove_existing_log_subscriptions
4
4
  ActiveSupport::LogSubscriber.log_subscribers.each do |subscriber|
@@ -84,10 +84,10 @@ if Rails.env == 'production' && ENV['NO_ZEROMQ_LOGGING'].blank?
84
84
  data[:remote_ip] = request.remote_ip
85
85
  data[:path] = request.filtered_path
86
86
 
87
- if (ac = request.env["action_controller.instance"]) &&
88
- (response = ac.response) &&
87
+ if (ac = request.env["action_controller.instance"]) &&
88
+ (response = ac.response) &&
89
89
  (body = response.body) &&
90
- body.present? &&
90
+ body.present? &&
91
91
  body =~ /\A\{"_api_error"/
92
92
  data[:_api_error] = JSON.parse(body)['_api_error']
93
93
  end
@@ -97,7 +97,7 @@ if Rails.env == 'production' && ENV['NO_ZEROMQ_LOGGING'].blank?
97
97
  end
98
98
 
99
99
  ex = request.env["action_dispatch.exception"]
100
- if ex
100
+ if ex
101
101
  if data[:status] == 404
102
102
  data[:path] = request.env["REQUEST_PATH"]
103
103
  else
@@ -3,7 +3,7 @@
3
3
  # You can use this file as a template: simply copy it, rename it and tailor its
4
4
  # contents. All data in this file will be used to define constants in your application
5
5
  # namespace. Please note that both config.yml and config.yml.example must exist.
6
- #
6
+ #
7
7
  # Any constants declared here can be overridden by corresponding environment variables
8
8
  # starting with OVERRIDE_. Thus, BASE_DOMAIN can be overridden by the environment
9
9
  # variable OVERRIDE_BASE_DOMAIN, and so forth. The API_PASSWORD receives special
@@ -32,12 +32,6 @@ BASE_DOMAIN: example.com
32
32
  API_VERSIONS:
33
33
  _default: v1
34
34
 
35
- # This is the list of IP numbers for the Varnish instances. (For PURGE and BAN.)
36
- LOAD_BALANCERS: []
37
-
38
- # This is the list of IP numbers for the ZeroMQ log hosts. (Only used in production.)
39
- LOG_HOSTS: []
40
-
41
35
  # The Ocean environment
42
36
  OCEAN_ENV: master
43
37
 
@@ -58,10 +52,3 @@ test:
58
52
 
59
53
 
60
54
  production:
61
- LOAD_BALANCERS:
62
- - 1.1.1.1
63
- - 2.2.2.2
64
-
65
- LOG_HOSTS:
66
- - 3.3.3.3
67
- - 4.4.4.4
@@ -7,11 +7,9 @@ require "ocean/ocean_resource_model" if defined? ActiveRecord || defined? OceanD
7
7
  require "ocean/ocean_resource_controller" if defined? ActionController
8
8
  require "ocean/ocean_application_controller"
9
9
 
10
- if ENV['RAILS_ENV'] == "production" && ENV['NO_ZEROMQ_LOGGING'].blank?
11
- require "ocean/zero_log"
12
- require "ocean/zeromq_logger"
13
- require "ocean/selective_rack_logger"
14
- end
10
+ #if ENV['RAILS_ENV'] == "production"
11
+ # require "ocean/selective_rack_logger"
12
+ #end
15
13
 
16
14
  require "ocean/api_remote_resource"
17
15
 
@@ -26,16 +24,16 @@ UUID_REGEX = /([0-9a-f]+-){4}[0-9a-f]+/
26
24
 
27
25
  module Ocean
28
26
 
29
- if ENV['RAILS_ENV'] == "production" && ENV['NO_ZEROMQ_LOGGING'].blank?
27
+ if ENV['RAILS_ENV'] == "production"
30
28
  class Railtie < Rails::Railtie
31
29
  # Silence the /alive action
32
- initializer "ocean.swap_logging_middleware" do |app|
33
- app.middleware.swap Rails::Rack::Logger, SelectiveRackLogger
34
- end
30
+ #initializer "ocean.swap_logging_middleware" do |app|
31
+ # app.middleware.swap Rails::Rack::Logger, SelectiveRackLogger
32
+ #end
35
33
  # Make sure the generators use the gem's templates first
36
34
  config.app_generators do |g|
37
35
  g.templates.unshift File::expand_path('../templates', __FILE__)
38
- end
36
+ end
39
37
  end
40
38
  end
41
39
 
@@ -44,15 +42,15 @@ end
44
42
 
45
43
  #
46
44
  # For stubbing successful authorisation calls. Makes <tt>Api.permitted?</tt> return
47
- # the status, and a body containing a partial authentication containing the +user_id+
45
+ # the status, and a body containing a partial authentication containing the +user_id+
48
46
  # and +creator_uri+ given by the parameters. It also allows the value of 'right' to
49
47
  # be specified: this will restrict all SQL queries accordingly.
50
48
  #
51
49
  def permit_with(status, user_id: "1-2-3-4-5", creator_uri: "https://api.example.com/v1/api_users/#{user_id}",
52
50
  right: nil, group_names: [])
53
51
  allow(Api).to receive(:permitted?).
54
- and_return(double(:status => status,
55
- :body => {'authentication' =>
52
+ and_return(double(:status => status,
53
+ :body => {'authentication' =>
56
54
  {'right' => right,
57
55
  'group_names' => group_names,
58
56
  '_links' => { 'creator' => {'href' => creator_uri,
@@ -66,7 +64,7 @@ end
66
64
  #
67
65
  def deny_with(status, *error_messages)
68
66
  allow(Api).to receive(:permitted?).
69
- and_return(double(:status => status,
67
+ and_return(double(:status => status,
70
68
  :body => {'_api_error' => error_messages}))
71
69
  end
72
70
 
@@ -113,8 +111,8 @@ def hyperlinks(links={})
113
111
  result = {}
114
112
  links.each do |qi, val|
115
113
  next unless val.present?
116
- result[qi.to_s] = {
117
- "href" => val.kind_of?(String) ? val : val[:href],
114
+ result[qi.to_s] = {
115
+ "href" => val.kind_of?(String) ? val : val[:href],
118
116
  "type" => val.kind_of?(String) ? "application/json" : val[:type]
119
117
  }
120
118
  end
@@ -142,11 +140,11 @@ end
142
140
  # authorisation belongs to one or more of a list of Groups.
143
141
  #
144
142
  def member_of_group?(*names)
145
- @group_names && @group_names.intersect?(names.to_set)
143
+ @group_names && @group_names.intersect?(names.to_set)
146
144
  end
147
145
 
148
146
  #
149
- # Returns true if the ApiUser behind the current authorisation belongs
147
+ # Returns true if the ApiUser behind the current authorisation belongs
150
148
  # to the Ocean Group "Superusers".
151
149
  #
152
150
  def superuser?
@@ -0,0 +1,114 @@
1
+ #
2
+ # This class is a drop-in replacement for the standard Rails logger. It
3
+ # implements enough of the Logger interface to allow it to override the
4
+ # standard logger.
5
+ #
6
+ class OceanLogger
7
+
8
+ attr_accessor :level, :formatter
9
+
10
+ #
11
+ # Obtains the IP of the current process, initialises the @logger object
12
+ # by instantiating a ZeroLog object which then is used to set up the
13
+ # log data sender.
14
+ #
15
+ def initialize
16
+ super
17
+ # Get info about our environment
18
+ @ip = Socket.ip_address_list.detect{|intf| intf.ipv4_private?}.getnameinfo[0]
19
+ # Set up the logger
20
+ @logger = ZeroLog.new "/tmp/sub_push_#{Process.pid}", @log_hosts
21
+ @formatter = ::Logger::Formatter.new
22
+ end
23
+
24
+ #
25
+ # Utility function which returns true if the current log level is +DEBUG+ or lower.
26
+ #
27
+ def debug?() @level <= 0; end
28
+
29
+ #
30
+ # Utility function which returns true if the current log level is +INFO+ or lower.
31
+ #
32
+ def info?() @level <= 1; end
33
+
34
+ #
35
+ # Utility function which returns true if the current log level is +WARN+ or lower.
36
+ #
37
+ def warn?() @level <= 2; end
38
+
39
+ #
40
+ # Utility function which returns true if the current log level is +ERROR+ or lower.
41
+ #
42
+ def error?() @level <= 3; end
43
+
44
+ #
45
+ # Utility function which returns true if the current log level is +FATAL+ or lower.
46
+ #
47
+ def fatal?() @level <= 4; end
48
+
49
+
50
+ #
51
+ # This is the core method to add new log messages to the Rails log. It does nothing
52
+ # if the level of the message is lower than the current log level, or if the message
53
+ # is blank. Otherwise it creates a JSON log message as a hash, with data for the
54
+ # following keys:
55
+ #
56
+ # +timestamp+: The time in milliseconds since the start of the Unix epoch.
57
+ #
58
+ # +ip+: The IP of the logging entity.
59
+ #
60
+ # +pid+: The Process ID of the logging process.
61
+ #
62
+ # +service+: The name of the service.
63
+ #
64
+ # +level+: The log level of the message (0=debug, 1=info, 2=warn, etc).
65
+ #
66
+ # +msg+: The log message itself.
67
+ #
68
+ def add(level, msg)
69
+ return true if level < @level
70
+ return true if msg.blank?
71
+ # Compensate for bug in Rails 4.2.x
72
+ return true if msg =~ /Couldn't find template for digesting/
73
+ data = { ip: @ip,
74
+ pid: Process.pid,
75
+ service: APP_NAME,
76
+ level: level
77
+ }
78
+ data[:token] = Thread.current[:x_api_token] if Thread.current[:x_api_token].present?
79
+ data[:username] = Thread.current[:username] if Thread.current[:username].present?
80
+ data[:msg] = msg if msg.is_a?(String)
81
+ data[:timestamp] = (Time.now.utc.to_f * 1000).to_i unless data[:timestamp]
82
+ data[:metadata] = Thread.current[:metadata] if Thread.current[:metadata].present?
83
+ data = data.merge msg if msg.is_a?(Hash)
84
+ @logger.log data
85
+ true
86
+ end
87
+
88
+
89
+ def debug(*args)
90
+ return if args.blank?
91
+ add 0, *args
92
+ end
93
+
94
+ def info(*args)
95
+ return if args.blank?
96
+ add 1, *args
97
+ end
98
+
99
+ def warn(*args)
100
+ return if args.blank?
101
+ add 2, *args
102
+ end
103
+
104
+ def error(*args)
105
+ return if args.blank?
106
+ add 3, *args
107
+ end
108
+
109
+ def fatal(*args)
110
+ return if args.blank?
111
+ add 4, *args
112
+ end
113
+
114
+ end
@@ -2,6 +2,8 @@
2
2
  # This custom Rack middleware is used to turn off logging of requests made to
3
3
  # <code>/alive</code>.
4
4
  #
5
+ # NB: This file is no longer loaded. It needs to be updated before it works again.
6
+ #
5
7
  class SelectiveRackLogger < Rails::Rack::Logger
6
8
 
7
9
  #
@@ -1,3 +1,3 @@
1
1
  module Ocean
2
- VERSION = "7.0.5"
2
+ VERSION = "7.0.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ocean-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.5
4
+ version: 7.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Bengtson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-28 00:00:00.000000000 Z
11
+ date: 2017-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus
@@ -24,34 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: ffi
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: ffi-rzmq
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
27
  - !ruby/object:Gem::Dependency
56
28
  name: rack-attack
57
29
  requirement: !ruby/object:Gem::Requirement
@@ -192,23 +164,27 @@ dependencies:
192
164
  - - "~>"
193
165
  - !ruby/object:Gem::Version
194
166
  version: '4.0'
195
- description: "== Ocean\n\nOcean is an architecture for creating server-oriented architectures
196
- (SOAs) in the cloud. \nIt consists of two separate parts which can be used separately
197
- or in conjunction: Ocean and OceanFront.\n\nOcean is a complete and very scalable
198
- back end solution for RESTful JSON web services and web applications, \nfeaturing
199
- aggressive caching and full HTTP client abstraction. Ocean fully implements HATEOAS
200
- principles, \nallowing the programming object model to move fully out onto the net,
201
- while maintaining a very high degree \nof decoupling.\n\nOcean is also a development,
202
- staging and deployment pipeline featuring continuous integration and testing in
203
- a \nTDD and/or BDD environment. Ocean can be used for continuous deployment or for
204
- scheduled releases. Front end tests \nare run in parallel using a matrix of operating
205
- systems and browser types. The pipeline can very easily be extended \nwith new development
206
- branches and quality assurance environments with automatic testing and deployment.\n\nOceanFront
207
- is a cross-platform Javascript front end browser client library supporting all major
208
- browsers and \nplatforms. OceanFront is object oriented, widget-based and HTML-less.\n\nTogether,
209
- Ocean and OceanFront allow you to write front end code completely independent of
210
- browser type and client \nOS, and back end code completely agnostic of whether it
211
- is called by a client browser or another server system."
167
+ description: |-
168
+ == Ocean
169
+
170
+ Ocean is an architecture for creating server-oriented architectures (SOAs) in the cloud.
171
+ It consists of two separate parts which can be used separately or in conjunction: Ocean and OceanFront.
172
+
173
+ Ocean is a complete and very scalable back end solution for RESTful JSON web services and web applications,
174
+ featuring aggressive caching and full HTTP client abstraction. Ocean fully implements HATEOAS principles,
175
+ allowing the programming object model to move fully out onto the net, while maintaining a very high degree
176
+ of decoupling.
177
+
178
+ Ocean is also a development, staging and deployment pipeline featuring continuous integration and testing in a
179
+ TDD and/or BDD environment. Ocean can be used for continuous deployment or for scheduled releases. Front end tests
180
+ are run in parallel using a matrix of operating systems and browser types. The pipeline can very easily be extended
181
+ with new development branches and quality assurance environments with automatic testing and deployment.
182
+
183
+ OceanFront is a cross-platform Javascript front end browser client library supporting all major browsers and
184
+ platforms. OceanFront is object oriented, widget-based and HTML-less.
185
+
186
+ Together, Ocean and OceanFront allow you to write front end code completely independent of browser type and client
187
+ OS, and back end code completely agnostic of whether it is called by a client browser or another server system.
212
188
  email:
213
189
  - peter@peterbengtson.com
214
190
  executables: []
@@ -223,7 +199,7 @@ files:
223
199
  - config/initializers/_api_constants.rb
224
200
  - config/initializers/_aws_config.rb
225
201
  - config/initializers/_ocean_constants.rb
226
- - config/initializers/_zeromq_logger.rb
202
+ - config/initializers/_ocean_logger.rb
227
203
  - config/routes.rb
228
204
  - lib/generators/ocean_scaffold/USAGE
229
205
  - lib/generators/ocean_scaffold/ocean_scaffold_generator.rb
@@ -265,6 +241,7 @@ files:
265
241
  - lib/ocean/api_resource.rb
266
242
  - lib/ocean/engine.rb
267
243
  - lib/ocean/ocean_application_controller.rb
244
+ - lib/ocean/ocean_logger.rb
268
245
  - lib/ocean/ocean_resource_controller.rb
269
246
  - lib/ocean/ocean_resource_model.rb
270
247
  - lib/ocean/selective_rack_logger.rb