itg 0.1.5 → 0.1.7

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: 86eb7558363b2ef248adcb708a48c7c4d5c3a615e771571218225ed96f9079bb
4
- data.tar.gz: f60b1f4edcbf79c70baaa664e585bdb62d1dfdbeb805485d31f642d4b2c88be8
3
+ metadata.gz: e1bd046d2cba513820497be3bb7a44105bbaee3d420ba96f22bb016d096c14ac
4
+ data.tar.gz: 26615592add3b3bc1c68845962ef49425efc5ab47127548c8c0a73ce6ceaa09b
5
5
  SHA512:
6
- metadata.gz: 43eb1e25ed87c074ea3880120c76f54c667c0fe257e1eb7754ee766525011da14f2b56dd60b7fb063318582e857fab6aed4097d02f4f344af4e8a24693b5f56e
7
- data.tar.gz: bad235cb3e0311e5e85deb1780c684387957073edc6fe1bcf462ed907cb98bd0ede53eecb1c78e5cdad82534727fb6dc4444c8bd74c9aa2c1ebeb3e61526da39
6
+ metadata.gz: 951fc43e0fcb89077b1e75c0f9bad2d5594b7bf51e0515c6b073214b215dbc07f0214f95c429abfa4007f5954eb4ff3c96af82c0a2ed8b50ae3d698751714ce2
7
+ data.tar.gz: 6d17eaeab84070b5498cfd39791321ea5cffb360c32816f67a89d5acbe75b8728890d7642384d813ea1242e45a3407e21e07507aa31dbcf676dca3905f6d14c1
@@ -0,0 +1 @@
1
+ Mongoid.load!("mongoid.yml")
@@ -0,0 +1,110 @@
1
+ <% unless Rails.env.production? %>
2
+ <% raise "[mongoid] Credentials missing! (mongodb, env: #{Rails.env})" if Rails.application.credentials.mongodb.nil? %>
3
+ <% raise "[mongoid] Credentials missing! (mongodb.md, env: #{Rails.env})" if Rails.application.credentials.mongodb.md.nil? %>
4
+ <% raise "[mongoid] Credentials missing! (mongodb.dd, env: #{Rails.env})" if Rails.application.credentials.mongodb.dd.nil? %>
5
+ <% raise "[mongoid] Credentials missing! (mongodb.itg, env: #{Rails.env})" if Rails.application.credentials.mongodb.itg.nil? %>
6
+ <% raise "[mongoid] Credentials missing! (mongodb.test, env: #{Rails.env})" if Rails.application.credentials.mongodb.test.nil? %>
7
+ <% raise "[mongoid] Credentials missing! (mongodb.staging, env: #{Rails.env})" if Rails.application.credentials.mongodb.staging.nil? %>
8
+ <% end %>
9
+ <%# unless Rails.env.production? %>
10
+ # <%# raise "[mongoid] Credentials missing! (mongodb, env: #{Rails.env})" if Rails.application.credentials.mongodb.nil? %>
11
+ # <%# raise "[mongoid] Credentials missing! (mongodb.dd, env: #{Rails.env})" if Rails.application.credentials.mongodb.dd.nil? %>
12
+ # <%# raise "[mongoid] Credentials missing! (mongodb.md, env: #{Rails.env})" if Rails.application.credentials.mongodb.md.nil? %>
13
+ <%# end %>
14
+ development:
15
+ clients:
16
+ default:
17
+ # local server
18
+ database: itg_backend_dev
19
+ hosts:
20
+ - localhost:27017
21
+ options:
22
+ server_selection_timeout: 1
23
+ # MongoDb Atlas server
24
+ # uri: mongodb+srv://<%#= Rails.application.credentials.mongodb.main.user %>:<%#= Rails.application.credentials.mongodb.main.psw %>@<%#= Rails.application.credentials.mongodb.main.cluster %>.mongodb.net/itg_backend?retryWrites=true&w=majority
25
+ # options:
26
+ # server_selection_timeout: 5
27
+ udd:
28
+ # local server
29
+ database: itg_backend_dev
30
+ hosts:
31
+ - localhost:27017
32
+ options:
33
+ server_selection_timeout: 1
34
+ # MongoDb Atlas server
35
+ # uri: mongodb+srv://<%#= Rails.application.credentials.mongodb.dd.user %>:<%#= Rails.application.credentials.mongodb.dd.psw %>@<%#= Rails.application.credentials.mongodb.dd.cluster %>.mongodb.net/udd-main?retryWrites=true&w=majority
36
+ # options:
37
+ # server_selection_timeout: 5
38
+
39
+ itgmain:
40
+ database: itg_main_dev
41
+ hosts:
42
+ - localhost:27017
43
+ options:
44
+ read:
45
+ mode: :primary
46
+ max_pool_size: 1
47
+
48
+ options:
49
+ raise_not_found_error: false
50
+
51
+ test:
52
+ clients:
53
+ default:
54
+ database: itg_backend_test
55
+ hosts:
56
+ - localhost:27017
57
+ options:
58
+ read:
59
+ mode: :primary
60
+ max_pool_size: 1
61
+ udd:
62
+ # local server
63
+ database: itg_backend_dev
64
+ hosts:
65
+ - localhost:27017
66
+ options:
67
+ server_selection_timeout: 1
68
+ # MongoDb Atlas server
69
+ # uri: mongodb+srv://<%#= Rails.application.credentials.mongodb.dd.user %>:<%#= Rails.application.credentials.mongodb.dd.psw %>@<%#= Rails.application.credentials.mongodb.dd.cluster %>.mongodb.net/udd-main?retryWrites=true&w=majority
70
+ # options:
71
+ # server_selection_timeout: 5
72
+
73
+ itgmain:
74
+ database: itg_main_test
75
+ hosts:
76
+ - localhost:27017
77
+ options:
78
+ read:
79
+ mode: :primary
80
+ max_pool_size: 1
81
+
82
+ options:
83
+ raise_not_found_error: false
84
+
85
+ staging:
86
+ clients:
87
+ default:
88
+ # uri: mongodb+srv://<%#= Rails.application.credentials.mongodb.main.user %>:<%#= Rails.application.credentials.mongodb.main.psw %>@<%#= Rails.application.credentials.mongodb.main.cluster %>.mongodb.net/itg_backend?retryWrites=true&w=majority
89
+ uri: mongodb+srv://<%= Rails.application.credentials.mongodb.md.user %>:<%= Rails.application.credentials.mongodb.md.psw %>@<%= Rails.application.credentials.mongodb.md.cluster %>.mongodb.net/md?retryWrites=true&w=majority
90
+ options:
91
+ udd:
92
+ uri: mongodb+srv://<%= Rails.application.credentials.mongodb.dd.user %>:<%= Rails.application.credentials.mongodb.dd.psw %>@<%= Rails.application.credentials.mongodb.dd.cluster %>.mongodb.net/udd-main?retryWrites=true&w=majority
93
+ options:
94
+ options:
95
+ raise_not_found_error: false
96
+
97
+ production:
98
+ clients:
99
+ default:
100
+ # uri: mongodb+srv://<%#= Rails.application.credentials.mongodb.main.user %>:<%#= Rails.application.credentials.mongodb.main.psw %>@<%#= Rails.application.credentials.mongodb.main.cluster %>.mongodb.net/itg_backend?retryWrites=true&w=majority
101
+ uri: mongodb+srv://<%= Rails.application.credentials.mongodb.md.user %>:<%= Rails.application.credentials.mongodb.md.psw %>@<%= Rails.application.credentials.mongodb.md.cluster %>.mongodb.net/md?retryWrites=true&w=majority
102
+ options:
103
+ udd:
104
+ uri: mongodb+srv://<%= Rails.application.credentials.mongodb.dd.user %>:<%= Rails.application.credentials.mongodb.dd.psw %>@<%= Rails.application.credentials.mongodb.dd.cluster %>.mongodb.net/udd-main?retryWrites=true&w=majority
105
+ options:
106
+ itgmain:
107
+ uri: mongodb+srv://<%= Rails.application.credentials.mongodb.itg.user %>:<%= Rails.application.credentials.mongodb.itg.psw %>@<%= Rails.application.credentials.mongodb.itg.cluster %>.mongodb.net/itg-main?retryWrites=true&w=majority
108
+ options:
109
+ options:
110
+ raise_not_found_error: false
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Itg
4
+ # Api Key Authenticatable class
5
+ module ApiKeyAuthenticatable
6
+ include ActionController::HttpAuthentication::Basic::ControllerMethods
7
+ include ActionController::HttpAuthentication::Token::ControllerMethods
8
+
9
+ extend ActiveSupport::Concern
10
+
11
+ attr_reader :current_api_key
12
+ attr_reader :current_bearer
13
+
14
+ # Use this to raise an error and automatically respond with a 401 HTTP status
15
+ # code when API key authentication fails
16
+ def authenticate_with_api_key!
17
+ @current_bearer = authenticate_or_request_with_http_token(&method(:authenticator))
18
+ end
19
+
20
+ # Use this for optional API key authentication
21
+ def authenticate_with_api_key
22
+ @current_bearer = authenticate_with_http_token(&method(:authenticator))
23
+ end
24
+
25
+ private
26
+
27
+ attr_writer :current_api_key
28
+ attr_writer :current_bearer
29
+
30
+ def authenticator(token, options)
31
+ @current_api_key = ApiKey.authenticate_by_token token
32
+
33
+ current_api_key&.bearer
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ItgApiKeyBase module
4
+ module Itg
5
+ module ApiKeyBase
6
+ extend ActiveSupport::Concern
7
+
8
+
9
+
10
+ # include Itg::MongoBase
11
+ # include Itg::Sec
12
+ # include Mongoid::Fields
13
+ #
14
+ # field :bearer_id, type: Integer
15
+ # field :bearer_type, type: String
16
+ # field :token_digest, type: String
17
+ #
18
+ # index({ bearer_id: 1, bearer_type: 1}, { name: "bearer_id_type_index" })
19
+ # index({ token_digest: 1 }, { unique: true, name: "token_digest_index" })
20
+
21
+ included do
22
+ include Itg::MongoBase
23
+ include Itg::Sec
24
+
25
+ field :bearer_id, type: Integer
26
+ field :bearer_type, type: String
27
+ field :token_digest, type: String
28
+
29
+ index({ bearer_id: 1, bearer_type: 1}, { name: 'bearer_id_type_index' })
30
+ index({ token_digest: 1 }, { unique: true, name: 'token_digest_index' })
31
+
32
+ attr_accessor :token
33
+
34
+ belongs_to :bearer, polymorphic: true
35
+
36
+ before_create :generate_token_hmac
37
+
38
+ def serializable_hash(options = nil)
39
+ h = super options.merge(except: "token_digest")
40
+ h.merge! "token" => token if token.present?
41
+ h
42
+ end
43
+
44
+ private
45
+
46
+ def generate_token_hmac
47
+ raise Mongoid::Errors::InvalidValue, 'token is required' unless token.present?
48
+
49
+ digest = OpenSSL::HMAC.hexdigest 'SHA256', self.class.hmac_secret_key, token
50
+
51
+ self.token_digest = digest
52
+ end
53
+ end
54
+
55
+ class_methods do
56
+ attr_reader :hmac_secret_key
57
+
58
+ def authenticate_by_token!(token)
59
+ digest = OpenSSL::HMAC.hexdigest "SHA256", hmac_secret_key, token
60
+
61
+ find_by! token_digest: digest
62
+ end
63
+
64
+ def authenticate_by_token(token)
65
+ authenticate_by_token! token
66
+ rescue Mongoid::Errors::DocumentNotFound
67
+ nil
68
+ end
69
+
70
+ private
71
+
72
+ def itg_api_key_base(hmac_secret_key: "not-yet-specified")
73
+ @hmac_secret_key = hmac_secret_key
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,7 @@
1
+ module Itg
2
+ module Response
3
+ def json_response(object, status = :ok)
4
+ render json: object, status: status
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Itg
4
+ # ItgSec concern class
5
+ module Sec
6
+ extend ActiveSupport::Concern
7
+
8
+ DB_NAME = begin
9
+ if Rails.env.production?
10
+ "itgsec"
11
+ else
12
+ "itgsecdev"
13
+ end
14
+ rescue StandardError
15
+ # Used only because the gem does not have the Rails initialized!
16
+ "itgsecdev"
17
+ end
18
+ CLIENT_NAME = "itgmain"
19
+
20
+ included do
21
+ begin
22
+ puts ">>>>>> itg_sec - include it....."
23
+ unless Rails.env.test?
24
+ store_in database: DB_NAME, client: CLIENT_NAME
25
+ puts "[itg_sec] set db details: #{DB_NAME}, #{CLIENT_NAME}"
26
+ end
27
+ self.itg_print_db_info
28
+ rescue NameError => e
29
+ # Ignored - Used only because the gem does not have the Rails initialized!
30
+ raise if e.message != "uninitialized constant Itg::Sec::Rails"
31
+ end
32
+ end
33
+
34
+ class_methods do
35
+ end
36
+ end
37
+ end
data/lib/itg/version.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Itg
4
- VERSION = "0.1.5"
5
- DATE = "17/2/2024"
4
+ VERSION = "0.1.7"
5
+ DATE = "18/2/2024"
6
6
 
7
7
  def self.version_info
8
8
  "Itg gem v.#{VERSION} #{DATE}"
data/lib/itg.rb CHANGED
@@ -4,10 +4,11 @@ require_relative "itg/version"
4
4
  require_relative "itg/itg_model_base"
5
5
  require_relative "itg/itg_mongo_base"
6
6
  require_relative "itg/itg_printable"
7
- require_relative "itg/itg_sec"
7
+ # require_relative "itg/itg_sec"
8
8
  require_relative "itg/itg_api_key_base"
9
9
  require_relative "itg/itg_api_key_authenticatable"
10
10
  require_relative "itg/itg_response"
11
+ require_relative "itg/itg_sec"
11
12
 
12
13
  module Itg
13
14
  class Error < StandardError; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - aAon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-17 00:00:00.000000000 Z
11
+ date: 2024-02-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -25,11 +25,17 @@ files:
25
25
  - LICENSE.txt
26
26
  - README.md
27
27
  - Rakefile
28
+ - config/intializers/mongoid.rb
29
+ - config/mongoid.yml
28
30
  - itg.gemspec
29
31
  - lib/itg.rb
32
+ - lib/itg/itg_api_key_authenticatable.rb
33
+ - lib/itg/itg_api_key_base.rb
30
34
  - lib/itg/itg_model_base.rb
31
35
  - lib/itg/itg_mongo_base.rb
32
36
  - lib/itg/itg_printable.rb
37
+ - lib/itg/itg_response.rb
38
+ - lib/itg/itg_sec.rb
33
39
  - lib/itg/version.rb
34
40
  - sig/itg.rbs
35
41
  homepage: https://aaon.aggate.gr