upfluence-utils 0.8.0 → 0.9.1

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
  SHA256:
3
- metadata.gz: 9ceaeab38d91b29c5642efd418464634aff70d4b856e81838119cfb9bb51ea07
4
- data.tar.gz: d1bfcabd937fd21089a5a612c978975bfb076c247281b7e120be395898a85fc4
3
+ metadata.gz: 9ec2cb539b838a39c7070211a24f086723b4cb26a1532ee75f7319dbd303888c
4
+ data.tar.gz: 6c1ac4ba7d68a192a215ce1a59ca0d566bf0f854a06c137c90f2d4a448419b47
5
5
  SHA512:
6
- metadata.gz: dc7bca3bd0914d787e15e30900705037a845f98311df404e4a40f0f016241bd014691a235c340b543a30b51fc477eca413cadd49889e9ed36bf6c30e4a2bf4eb
7
- data.tar.gz: 14d6565989fff758bb50662eb7dfbb2e2e9423469f85656a4cf78c3eac0ca7ceaaa6ed620f72335c3c747ceb495bd96bf85c9c1e8d28733359e2c70d04fc9c86
6
+ metadata.gz: aade8b296ee62ff089107cbd10cca45a0d3059941966505d139b71ebc53901bd3f66938482b535b5fce5d4a1f13c64e48bb8de1fc14430c2741386568804ce4f
7
+ data.tar.gz: 8ccc8c8e00fe755375357b337b41c582e340b22a0c3b1b33dd3c265d4da9e3c53962b1614bbabc0a939b329b051fc5c27fa0ea1ab557e9d4623bd09ac4d33b52
@@ -0,0 +1,30 @@
1
+ ### What does this PR do?
2
+
3
+ <!-- A brief description of the context of this pull request and its purpose. -->
4
+
5
+ Fixes #<!-- enter issue number here -->
6
+
7
+ ### What are the observable changes?
8
+ <!-- This question could be adequate with multiple use cases, for example: -->
9
+
10
+ <!-- Frontend: explain the feature created / updated, give instructions telling how to see the change in staging -->
11
+ <!-- Performance: what metric should be impacted, link to the right graphana dashboard for exemple -->
12
+ <!-- Bug: a given issue trail on sentry should stop happening -->
13
+ <!-- Feature: Implements X thrift service / Z HTTP REST API added, provide instructions on how leverage your feature from staging or your workstation -->
14
+
15
+ ### Good PR checklist
16
+
17
+ - [ ] Title makes sense
18
+ - [ ] Is against the correct branch
19
+ - [ ] Only addresses one issue
20
+ - [ ] Properly assigned
21
+ - [ ] Added/updated tests
22
+ - [ ] Added/updated documentation
23
+ - [ ] Properly labeled
24
+
25
+ ### Additional Notes
26
+
27
+ <!--
28
+ You can add anything you want here, an explanation on the way you built your implementation,
29
+ precisions on the origin of the bug, gotchas you need to mention.
30
+ -->
@@ -0,0 +1,4 @@
1
+ require 'upfluence/http/server'
2
+
3
+ Upfluence::HTTP::Server.new do
4
+ end.serve
@@ -2,4 +2,4 @@ require 'upfluence/utils'
2
2
  require 'upfluence/endpoint/api_endpoint'
3
3
  require 'upfluence/mixin/strong_parameters'
4
4
  require 'upfluence/mixin/pagination'
5
- require 'upfluence/base/exceptions/validation_error'
5
+ require 'upfluence/resources'
@@ -1,12 +1,15 @@
1
1
  require 'sinatra'
2
2
  require 'active_record'
3
3
  require 'active_support/hash_with_indifferent_access'
4
+ require 'upfluence/http/endpoint/validation_error'
4
5
 
5
6
  module Upfluence
6
7
  module HTTP
7
8
  module Endpoint
8
9
  class BadRequest < StandardError; end
9
10
  class APIEndpoint < Sinatra::Base
11
+ VALIDATION_ERROR_KLASS = ValidationError
12
+
10
13
  disable :show_exceptions
11
14
  disable :logging
12
15
  disable :dump_errors
@@ -44,7 +47,7 @@ module Upfluence
44
47
  def respond_with(resource, *args)
45
48
  if resource.respond_to?(:errors) && resource.errors.any?
46
49
  status = 422
47
- result = Base::Exceptions::ValidationError.from_model(
50
+ result = VALIDATION_ERROR_KLASS.from_model(
48
51
  resource
49
52
  ).to_json
50
53
  else
@@ -0,0 +1,31 @@
1
+ module Upfluence
2
+ module HTTP
3
+ module Endpoint
4
+ class ValidationError
5
+ def initialize(validations)
6
+ @validations = validations
7
+ end
8
+
9
+ class << self
10
+ def from_model(model)
11
+ validations = model.errors.details.map do |error_field, errors|
12
+ errors.map do |error|
13
+ OpenStruct.new(
14
+ ressource: model.model_name.singular,
15
+ field: error_field.to_s,
16
+ code: error[:error].to_s
17
+ )
18
+ end
19
+ end.flatten
20
+
21
+ new(validations)
22
+ end
23
+ end
24
+
25
+ def to_json
26
+ { errors: @validations }.to_json
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -81,7 +81,7 @@ module Upfluence
81
81
 
82
82
  path = Rack::Request.new(env).path
83
83
 
84
- splitted_template = route.split(' ').last.split('/').rejext do |v|
84
+ splitted_template = route.split(' ').last.split('/').reject do |v|
85
85
  v.eql?('')
86
86
  end.reverse
87
87
 
@@ -14,7 +14,6 @@ require 'upfluence/http/middleware/application_headers'
14
14
  require 'upfluence/http/middleware/handle_exception'
15
15
  require 'upfluence/http/middleware/prometheus'
16
16
  require 'upfluence/http/middleware/cors'
17
- require 'upfluence/handler/base'
18
17
 
19
18
  module Upfluence
20
19
  module HTTP
@@ -29,13 +28,14 @@ module Upfluence
29
28
  push_gateway_interval: 15, # sec
30
29
  app_name: ENV['APP_NAME'] || 'uhttp-rb-server',
31
30
  unit_name: ENV['UNIT_NAME'] || 'uhttp-rb-server-anonymous',
31
+ base_processor_klass: nil,
32
+ base_handler_klass: nil,
32
33
  debug: ENV['DEBUG']
33
- }.freeze
34
+ }
34
35
 
35
36
  def initialize(options = {}, &block)
36
37
  @options = DEFAULT_OPTIONS.dup.merge(options)
37
38
  opts = @options
38
- base_handler = Handler::Base.new(opts[:interfaces])
39
39
 
40
40
  @builder = Builder.new do
41
41
  use Middleware::Logger
@@ -54,13 +54,16 @@ module Upfluence
54
54
  run(opts[:healthcheck_endpoint] || Endpoint::Healthcheck.new)
55
55
  end
56
56
 
57
- map '/base' do
58
- run_thrift Base::Base_service::BaseService::Processor, base_handler
57
+ if opts[:base_processor_klass] && opts[:base_handler_klass]
58
+ map '/base' do
59
+ run_thrift(
60
+ opts[:base_processor_klass],
61
+ opts[:base_handler_klass].new(@options[:interfaces])
62
+ )
63
+ end
59
64
  end
60
65
 
61
- map '/debug' do
62
- run Endpoint::Profiler.new
63
- end if opts[:debug]
66
+ map('/debug') { run(Endpoint::Profiler.new) } if opts[:debug]
64
67
 
65
68
  instance_eval(&block)
66
69
  end
@@ -0,0 +1 @@
1
+ require 'upfluence/resources/countries'
@@ -0,0 +1,23 @@
1
+ module Upfluence
2
+ module Resources
3
+ COUNTRIES = %w[
4
+ US FR GB DE CH AF AL DZ AS AD AO AI
5
+ AG AR AM AW AU AT AZ BS BH BD BB BY
6
+ BE BZ BJ BM BT BO BA BW BR BN BG BF
7
+ BI CV KH CM CA KY CF TD CL CN CO KM
8
+ CG CD CK CI HR CU CY CZ DK DJ DM DO
9
+ GW GY HT VA HN HK HU IS IN ID IR IQ
10
+ IE IM IL IT JM JP JE JO KZ KE KI KP
11
+ KR KW KG LA LV LB LI LS LR LY LT LU
12
+ MO MK MG MW MY MV ML MT MH MQ MR MU
13
+ MX FM MD MC MN ME MS MA MZ MM NA NR
14
+ NP NL NC NZ NI NE NG NO OM PK PW PS
15
+ PA PG PY PE PH PL PT PR QA RE RO RU
16
+ RW KN LC VC WS SM ST SA SN RS SC SL
17
+ SG SK SI SB SO ZA ES LK SD SR SZ SE
18
+ SY TW TJ TZ TH TL TG TO TT TN TR TM
19
+ TC TV UG UA AE GB UY UZ VU VE VN VG
20
+ VI EH YE ZM ZW CR
21
+ ].freeze
22
+ end
23
+ end
@@ -1,5 +1,5 @@
1
1
  module Upfluence
2
2
  module Utils
3
- VERSION = '0.8.0'.freeze
3
+ VERSION = '0.9.1'.freeze
4
4
  end
5
5
  end
@@ -19,8 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.add_development_dependency "bundler", "~> 1.12"
20
20
  spec.add_development_dependency "rake", ">= 12.3.3"
21
21
  spec.add_development_dependency "rspec", "~> 3.0"
22
- spec.add_runtime_dependency 'upfluence-thrift', '~> 2.1'
23
- spec.add_runtime_dependency 'base-thrift', '>= 0.1.0'
22
+ spec.add_runtime_dependency 'upfluence-thrift'
24
23
  spec.add_runtime_dependency 'sinatra'
25
24
  spec.add_runtime_dependency 'redis'
26
25
  spec.add_runtime_dependency 'sentry-raven'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upfluence-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Upfluence
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-13 00:00:00.000000000 Z
11
+ date: 2021-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -54,32 +54,18 @@ dependencies:
54
54
  version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: upfluence-thrift
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '2.1'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '2.1'
69
- - !ruby/object:Gem::Dependency
70
- name: base-thrift
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
59
  - - ">="
74
60
  - !ruby/object:Gem::Version
75
- version: 0.1.0
61
+ version: '0'
76
62
  type: :runtime
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
66
  - - ">="
81
67
  - !ruby/object:Gem::Version
82
- version: 0.1.0
68
+ version: '0'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: sinatra
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -234,13 +220,14 @@ dependencies:
234
220
  - - ">="
235
221
  - !ruby/object:Gem::Version
236
222
  version: '0'
237
- description:
223
+ description:
238
224
  email:
239
225
  - dev@upfluence.com
240
226
  executables: []
241
227
  extensions: []
242
228
  extra_rdoc_files: []
243
229
  files:
230
+ - ".github/pull_request_template.md"
244
231
  - ".gitignore"
245
232
  - ".rspec"
246
233
  - ".travis.yml"
@@ -248,19 +235,19 @@ files:
248
235
  - LICENSE.txt
249
236
  - README.md
250
237
  - Rakefile
238
+ - lib/test.rb
251
239
  - lib/upfluence.rb
252
240
  - lib/upfluence/amqp/server.rb
253
- - lib/upfluence/base/exceptions/validation_error.rb
254
241
  - lib/upfluence/endpoint/api_endpoint.rb
255
242
  - lib/upfluence/environment.rb
256
243
  - lib/upfluence/error_logger.rb
257
244
  - lib/upfluence/error_logger/null.rb
258
245
  - lib/upfluence/error_logger/sentry.rb
259
- - lib/upfluence/handler/base.rb
260
246
  - lib/upfluence/http/builder.rb
261
247
  - lib/upfluence/http/endpoint/api_endpoint.rb
262
248
  - lib/upfluence/http/endpoint/healthcheck.rb
263
249
  - lib/upfluence/http/endpoint/profiler.rb
250
+ - lib/upfluence/http/endpoint/validation_error.rb
264
251
  - lib/upfluence/http/middleware/application_headers.rb
265
252
  - lib/upfluence/http/middleware/cors.rb
266
253
  - lib/upfluence/http/middleware/handle_exception.rb
@@ -272,6 +259,8 @@ files:
272
259
  - lib/upfluence/mixin/strong_parameters.rb
273
260
  - lib/upfluence/peer.rb
274
261
  - lib/upfluence/pool.rb
262
+ - lib/upfluence/resources.rb
263
+ - lib/upfluence/resources/countries.rb
275
264
  - lib/upfluence/utils.rb
276
265
  - lib/upfluence/utils/http/middleware/null.rb
277
266
  - lib/upfluence/utils/semaphore.rb
@@ -288,7 +277,7 @@ homepage: https://github.com/upfluence/rbutils
288
277
  licenses:
289
278
  - MIT
290
279
  metadata: {}
291
- post_install_message:
280
+ post_install_message:
292
281
  rdoc_options: []
293
282
  require_paths:
294
283
  - lib
@@ -304,7 +293,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
304
293
  version: '0'
305
294
  requirements: []
306
295
  rubygems_version: 3.0.3
307
- signing_key:
296
+ signing_key:
308
297
  specification_version: 4
309
298
  summary: Upfluence common utils for Ruby projects
310
299
  test_files: []
@@ -1,35 +0,0 @@
1
- require 'thrift/exceptions'
2
- require 'base/exceptions/exceptions_types'
3
-
4
- module Base
5
- module Exceptions
6
- class ValidationError < ::Thrift::Exception
7
- class << self
8
- attr_accessor :domain
9
-
10
- def from_model(model)
11
- validation_errors = model.errors.details.map do |error_field, errors|
12
- errors.map do |error|
13
- Base::Exceptions::Validation.new(
14
- domain: domain,
15
- model: model.model_name.singular,
16
- field: error_field.to_s,
17
- error: error[:error].to_s
18
- )
19
- end
20
- end.flatten
21
-
22
- new(validations: validation_errors)
23
- end
24
- end
25
-
26
- def to_json
27
- {
28
- errors: validations.map do |v|
29
- { resource: v.model, field: v.field, code: v.error }
30
- end
31
- }.to_json
32
- end
33
- end
34
- end
35
- end
@@ -1,56 +0,0 @@
1
- require 'base/base_service/base_service'
2
- require 'base/version/version_types'
3
- require 'base/version'
4
-
5
- module Upfluence
6
- module Handler
7
- class Base
8
- def initialize(modules = [])
9
- @alive_since = Time.now.to_i
10
- @modules = modules.reduce({ 'base' => ::Base::VERSION }) do |acc, cur|
11
- acc.merge cur.name.downcase => cur::VERSION
12
- end
13
- end
14
-
15
- def getVersion
16
- semantic_version = if ENV['SEMVER_VERSION']
17
- major, minor, patch = ENV['SEMVER_VERSION'].split('.')
18
- ::Base::Version::SemanticVersion.new(
19
- major: major[1..-1].to_i,
20
- minor: minor.to_i,
21
- patch: patch.to_i
22
- )
23
- end
24
-
25
- git_version = if ENV['GIT_COMMIT']
26
- ::Base::Version::GitVersion.new(
27
- commit: ENV['GIT_COMMIT'],
28
- branch: ENV['GIT_BRANCH'],
29
- remote: ENV['GIT_REMOTE']
30
- )
31
- end
32
-
33
- ::Base::Version::Version.new(
34
- semantic_version: semantic_version,
35
- git_version: git_version
36
- )
37
- end
38
-
39
- def getName
40
- ENV['UNIT_NAME'] || 'default'
41
- end
42
-
43
- def getStatus
44
- ::Base::Base_service::Status::ALIVE
45
- end
46
-
47
- def aliveSince
48
- @alive_since
49
- end
50
-
51
- def getInterfaceVersions
52
- @modules
53
- end
54
- end
55
- end
56
- end