itg 0.1.5 → 0.1.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 +4 -4
- data/config/intializers/mongoid.rb +1 -0
- data/config/mongoid.yml +110 -0
- data/lib/itg/itg_api_key_authenticatable.rb +36 -0
- data/lib/itg/itg_api_key_base.rb +45 -0
- data/lib/itg/itg_response.rb +7 -0
- data/lib/itg/itg_sec.rb +37 -0
- data/lib/itg/version.rb +1 -1
- data/lib/itg.rb +2 -1
- metadata +7 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: afb1a619f9859827f857cc4558a198ae8d753e3f86df4bb0c308df46abecd107
|
|
4
|
+
data.tar.gz: 5969d0683fc63c024cc789f5e3a8fcf39cdb1238ad8b416cb1f1c5222f2839b0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 636803d0bbf4672919fc52e95c0cac4c6d4390af1463e304bfe96889b1d6d2ac39516d71ed3492833d83e25c4aabba0412c5a21cb04f77cfdda9f480064e2e40
|
|
7
|
+
data.tar.gz: 1ba56414129bef246771f1b7d401a6a26563af8d6de49e456ba27220f936781ff2b718c0f86412d959295bc82bdc6763da873c6b7fb269aa4ea9aff386e5d9e9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Mongoid.load!("mongoid.yml")
|
data/config/mongoid.yml
ADDED
|
@@ -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,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# ItgApiKeyBase module
|
|
4
|
+
module Itg
|
|
5
|
+
module ApiKeyBase
|
|
6
|
+
extend ActiveSupport::Concern
|
|
7
|
+
|
|
8
|
+
# include Itg::MongoBase
|
|
9
|
+
# include Itg::Sec
|
|
10
|
+
# include Mongoid::Fields
|
|
11
|
+
#
|
|
12
|
+
# field :bearer_id, type: Integer
|
|
13
|
+
# field :bearer_type, type: String
|
|
14
|
+
# field :token_digest, type: String
|
|
15
|
+
#
|
|
16
|
+
# index({ bearer_id: 1, bearer_type: 1}, { name: "bearer_id_type_index" })
|
|
17
|
+
# index({ token_digest: 1 }, { unique: true, name: "token_digest_index" })
|
|
18
|
+
|
|
19
|
+
included do
|
|
20
|
+
include Itg::MongoBase
|
|
21
|
+
include Itg::Sec
|
|
22
|
+
|
|
23
|
+
# field :bearer_id, type: Integer
|
|
24
|
+
# field :bearer_type, type: String
|
|
25
|
+
# field :token_digest, type: String
|
|
26
|
+
#
|
|
27
|
+
# index({ bearer_id: 1, bearer_type: 1}, { name: "bearer_id_type_index" })
|
|
28
|
+
# index({ token_digest: 1 }, { unique: true, name: "token_digest_index" })
|
|
29
|
+
|
|
30
|
+
# Virtual attribute for raw token value, allowing us to respond with the
|
|
31
|
+
# API key's non-hashed token value. but only directly after creation.
|
|
32
|
+
# attr_accessor :token
|
|
33
|
+
#
|
|
34
|
+
# belongs_to :bearer, polymorphic: true
|
|
35
|
+
|
|
36
|
+
# Add virtual token attribute to serializable attributes, and exclude
|
|
37
|
+
# the token's HMAC digest
|
|
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
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
data/lib/itg/itg_sec.rb
ADDED
|
@@ -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
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,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: itg
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- aAon
|
|
@@ -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
|