virtuatable-core 1.0.0 → 1.2.1

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.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/lib/core/controllers/base.rb +63 -0
  3. data/lib/core/controllers.rb +9 -0
  4. data/lib/core/helpers/accounts.rb +22 -0
  5. data/lib/core/helpers/applications.rb +26 -0
  6. data/lib/core/helpers/declarators.rb +83 -0
  7. data/lib/core/helpers/errors/bad_request.rb +15 -0
  8. data/lib/core/helpers/errors/base.rb +36 -0
  9. data/lib/core/helpers/errors/forbidden.rb +15 -0
  10. data/lib/core/helpers/errors/not_found.rb +15 -0
  11. data/lib/core/helpers/errors.rb +48 -0
  12. data/lib/core/helpers/fields.rb +35 -0
  13. data/lib/core/helpers/parameters.rb +25 -0
  14. data/lib/core/helpers/responses.rb +50 -0
  15. data/lib/core/helpers/routes.rb +21 -0
  16. data/lib/core/helpers/sessions.rb +30 -0
  17. data/lib/core/helpers.rb +18 -0
  18. data/lib/core/models/account.rb +2 -5
  19. data/lib/core/models/authentication/session.rb +2 -0
  20. data/lib/core/models/campaign.rb +7 -1
  21. data/lib/core/models/campaigns/invitation.rb +2 -0
  22. data/lib/core/models/campaigns/map.rb +37 -0
  23. data/lib/core/models/campaigns/tag.rb +2 -0
  24. data/lib/core/models/campaigns/token.rb +31 -0
  25. data/lib/core/models/campaigns/token_position.rb +39 -0
  26. data/lib/core/models/campaigns.rb +3 -0
  27. data/lib/core/models/chatrooms/campaign.rb +3 -0
  28. data/lib/core/models/chatrooms/message.rb +3 -1
  29. data/lib/core/models/concerns/activable.rb +1 -1
  30. data/lib/core/models/concerns/premiumable.rb +1 -1
  31. data/lib/core/models/concerns.rb +0 -1
  32. data/lib/core/models/files/document.rb +2 -0
  33. data/lib/core/models/files/permission.rb +2 -0
  34. data/lib/core/models/notification.rb +1 -1
  35. data/lib/core/models/oauth/access_token.rb +2 -0
  36. data/lib/core/models/oauth/application.rb +3 -1
  37. data/lib/core/models/oauth/authorization.rb +2 -0
  38. data/lib/core/models/oauth/refresh_token.rb +2 -0
  39. data/lib/core/models/permissions/category.rb +2 -0
  40. data/lib/core/models/permissions/group.rb +5 -3
  41. data/lib/core/models/permissions/right.rb +2 -0
  42. data/lib/core/models/{monitoring → permissions}/route.rb +7 -16
  43. data/lib/core/models/permissions.rb +1 -0
  44. data/lib/core/models/ruleset.rb +2 -0
  45. data/lib/core/models.rb +0 -3
  46. data/lib/core/services/accounts.rb +16 -0
  47. data/lib/core/services/base.rb +11 -0
  48. data/lib/core/services/registry.rb +15 -0
  49. data/lib/core/services/sessions.rb +33 -0
  50. data/lib/core/services.rb +8 -0
  51. data/lib/core/version.rb +1 -1
  52. data/lib/core.rb +3 -0
  53. metadata +84 -43
  54. data/lib/core/models/chatrooms/conversation.rb +0 -9
  55. data/lib/core/models/chatrooms/membership.rb +0 -17
  56. data/lib/core/models/concerns/diagnosticable.rb +0 -24
  57. data/lib/core/models/decorators/errors/env_variable_missing.rb +0 -16
  58. data/lib/core/models/decorators/errors.rb +0 -11
  59. data/lib/core/models/decorators/gateway.rb +0 -111
  60. data/lib/core/models/factories/errors/gateway_not_found.rb +0 -16
  61. data/lib/core/models/factories/errors.rb +0 -11
  62. data/lib/core/models/factories.rb +0 -10
  63. data/lib/core/models/monitoring/service.rb +0 -33
  64. data/lib/core/models/monitoring.rb +0 -10
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: virtuatable-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Courtois
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-07 00:00:00.000000000 Z
11
+ date: 2022-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: database_cleaner
@@ -30,28 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 6.1.0
33
+ version: 6.2.1
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 6.1.0
41
- - !ruby/object:Gem::Dependency
42
- name: factory_girl
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - '='
46
- - !ruby/object:Gem::Version
47
- version: 4.8.1
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '='
53
- - !ruby/object:Gem::Version
54
- version: 4.8.1
40
+ version: 6.2.1
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: faker
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +94,20 @@ dependencies:
108
94
  - - '='
109
95
  - !ruby/object:Gem::Version
110
96
  version: 1.1.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: require_all
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 3.0.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 3.0.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rspec
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -179,21 +179,21 @@ dependencies:
179
179
  - !ruby/object:Gem::Version
180
180
  version: 0.9.25
181
181
  - !ruby/object:Gem::Dependency
182
- name: mongoid
182
+ name: activemodel
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
185
  - - '='
186
186
  - !ruby/object:Gem::Version
187
- version: 7.1.0
187
+ version: 6.0.3.2
188
188
  type: :runtime
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
192
  - - '='
193
193
  - !ruby/object:Gem::Version
194
- version: 7.1.0
194
+ version: 6.0.3.2
195
195
  - !ruby/object:Gem::Dependency
196
- name: activemodel
196
+ name: activesupport
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
199
  - - '='
@@ -207,47 +207,75 @@ dependencies:
207
207
  - !ruby/object:Gem::Version
208
208
  version: 6.0.3.2
209
209
  - !ruby/object:Gem::Dependency
210
- name: activesupport
210
+ name: bcrypt
211
211
  requirement: !ruby/object:Gem::Requirement
212
212
  requirements:
213
213
  - - '='
214
214
  - !ruby/object:Gem::Version
215
- version: 6.0.3.2
215
+ version: 3.1.13
216
216
  type: :runtime
217
217
  prerelease: false
218
218
  version_requirements: !ruby/object:Gem::Requirement
219
219
  requirements:
220
220
  - - '='
221
221
  - !ruby/object:Gem::Version
222
- version: 6.0.3.2
222
+ version: 3.1.13
223
223
  - !ruby/object:Gem::Dependency
224
- name: bcrypt
224
+ name: dotenv
225
225
  requirement: !ruby/object:Gem::Requirement
226
226
  requirements:
227
227
  - - '='
228
228
  - !ruby/object:Gem::Version
229
- version: 3.1.13
229
+ version: 2.7.6
230
230
  type: :runtime
231
231
  prerelease: false
232
232
  version_requirements: !ruby/object:Gem::Requirement
233
233
  requirements:
234
234
  - - '='
235
235
  - !ruby/object:Gem::Version
236
- version: 3.1.13
236
+ version: 2.7.6
237
237
  - !ruby/object:Gem::Dependency
238
- name: dotenv
238
+ name: mongoid
239
239
  requirement: !ruby/object:Gem::Requirement
240
240
  requirements:
241
241
  - - '='
242
242
  - !ruby/object:Gem::Version
243
- version: 2.7.6
243
+ version: 7.4.0
244
244
  type: :runtime
245
245
  prerelease: false
246
246
  version_requirements: !ruby/object:Gem::Requirement
247
247
  requirements:
248
248
  - - '='
249
249
  - !ruby/object:Gem::Version
250
- version: 2.7.6
250
+ version: 7.4.0
251
+ - !ruby/object:Gem::Dependency
252
+ name: sinatra
253
+ requirement: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - '='
256
+ - !ruby/object:Gem::Version
257
+ version: 2.1.0
258
+ type: :runtime
259
+ prerelease: false
260
+ version_requirements: !ruby/object:Gem::Requirement
261
+ requirements:
262
+ - - '='
263
+ - !ruby/object:Gem::Version
264
+ version: 2.1.0
265
+ - !ruby/object:Gem::Dependency
266
+ name: sinatra-contrib
267
+ requirement: !ruby/object:Gem::Requirement
268
+ requirements:
269
+ - - '='
270
+ - !ruby/object:Gem::Version
271
+ version: 2.1.0
272
+ type: :runtime
273
+ prerelease: false
274
+ version_requirements: !ruby/object:Gem::Requirement
275
+ requirements:
276
+ - - '='
277
+ - !ruby/object:Gem::Version
278
+ version: 2.1.0
251
279
  description: This gem holds the model layer for my table-top RPG games application.
252
280
  email: courtois.vincent@outlook.com
253
281
  executables: []
@@ -255,6 +283,22 @@ extensions: []
255
283
  extra_rdoc_files: []
256
284
  files:
257
285
  - lib/core.rb
286
+ - lib/core/controllers.rb
287
+ - lib/core/controllers/base.rb
288
+ - lib/core/helpers.rb
289
+ - lib/core/helpers/accounts.rb
290
+ - lib/core/helpers/applications.rb
291
+ - lib/core/helpers/declarators.rb
292
+ - lib/core/helpers/errors.rb
293
+ - lib/core/helpers/errors/bad_request.rb
294
+ - lib/core/helpers/errors/base.rb
295
+ - lib/core/helpers/errors/forbidden.rb
296
+ - lib/core/helpers/errors/not_found.rb
297
+ - lib/core/helpers/fields.rb
298
+ - lib/core/helpers/parameters.rb
299
+ - lib/core/helpers/responses.rb
300
+ - lib/core/helpers/routes.rb
301
+ - lib/core/helpers/sessions.rb
258
302
  - lib/core/models.rb
259
303
  - lib/core/models/account.rb
260
304
  - lib/core/models/authentication.rb
@@ -262,35 +306,26 @@ files:
262
306
  - lib/core/models/campaign.rb
263
307
  - lib/core/models/campaigns.rb
264
308
  - lib/core/models/campaigns/invitation.rb
309
+ - lib/core/models/campaigns/map.rb
265
310
  - lib/core/models/campaigns/tag.rb
311
+ - lib/core/models/campaigns/token.rb
312
+ - lib/core/models/campaigns/token_position.rb
266
313
  - lib/core/models/chatrooms.rb
267
314
  - lib/core/models/chatrooms/base.rb
268
315
  - lib/core/models/chatrooms/campaign.rb
269
- - lib/core/models/chatrooms/conversation.rb
270
- - lib/core/models/chatrooms/membership.rb
271
316
  - lib/core/models/chatrooms/message.rb
272
317
  - lib/core/models/concerns.rb
273
318
  - lib/core/models/concerns/activable.rb
274
- - lib/core/models/concerns/diagnosticable.rb
275
319
  - lib/core/models/concerns/enumerable.rb
276
320
  - lib/core/models/concerns/historizable.rb
277
321
  - lib/core/models/concerns/mime_typable.rb
278
322
  - lib/core/models/concerns/premiumable.rb
279
323
  - lib/core/models/concerns/sluggable.rb
280
324
  - lib/core/models/concerns/typable.rb
281
- - lib/core/models/decorators/errors.rb
282
- - lib/core/models/decorators/errors/env_variable_missing.rb
283
- - lib/core/models/decorators/gateway.rb
284
325
  - lib/core/models/event.rb
285
- - lib/core/models/factories.rb
286
- - lib/core/models/factories/errors.rb
287
- - lib/core/models/factories/errors/gateway_not_found.rb
288
326
  - lib/core/models/files.rb
289
327
  - lib/core/models/files/document.rb
290
328
  - lib/core/models/files/permission.rb
291
- - lib/core/models/monitoring.rb
292
- - lib/core/models/monitoring/route.rb
293
- - lib/core/models/monitoring/service.rb
294
329
  - lib/core/models/notification.rb
295
330
  - lib/core/models/oauth.rb
296
331
  - lib/core/models/oauth/access_token.rb
@@ -301,7 +336,13 @@ files:
301
336
  - lib/core/models/permissions/category.rb
302
337
  - lib/core/models/permissions/group.rb
303
338
  - lib/core/models/permissions/right.rb
339
+ - lib/core/models/permissions/route.rb
304
340
  - lib/core/models/ruleset.rb
341
+ - lib/core/services.rb
342
+ - lib/core/services/accounts.rb
343
+ - lib/core/services/base.rb
344
+ - lib/core/services/registry.rb
345
+ - lib/core/services/sessions.rb
305
346
  - lib/core/version.rb
306
347
  homepage: https://rubygems.org/gems/virtuatable-core
307
348
  licenses:
@@ -1,9 +0,0 @@
1
- module Core
2
- module Models
3
- module Chatrooms
4
- class Conversation < Core::Models::Chatrooms::Base
5
- has_many :memberships, class_name: 'Core::Models::Chatrooms::Membership', inverse_of: :chatroom
6
- end
7
- end
8
- end
9
- end
@@ -1,17 +0,0 @@
1
- module Core
2
- module Models
3
- module Chatrooms
4
- class Membership
5
- include Mongoid::Document
6
- include Mongoid::Timestamps
7
- include Core::Models::Concerns::Enumerable
8
-
9
- enum_field :status, [:shown, :hidden], default: :shown
10
-
11
- belongs_to :chatroom, class_name: 'Core::Models::Chatrooms::Private', inverse_of: :memberships
12
-
13
- belongs_to :account, class_name: 'Core::Models::Account', inverse_of: :memberships
14
- end
15
- end
16
- end
17
- end
@@ -1,24 +0,0 @@
1
- module Core
2
- module Models
3
- module Concerns
4
- # Includes the diagnostic URL field, and the related validations.
5
- # @author Vincent Courtois <courtois.vincent@outlook.com>
6
- module Diagnosticable
7
- extend ActiveSupport::Concern
8
-
9
- # Module holding the class methods for the classes including this concern.
10
- # @author Vincent Courtois <courtois.vincent@outlook.com>
11
- included do
12
- # @!attribute [rw] diagnostic
13
- # @return [String] the diagnostic URL to know the status of an entity (usually a gateway, or an instance of a service).
14
- field :diagnostic, type: String, default: '/status'
15
-
16
- validates :diagnostic,
17
- presence: {message: "required"},
18
- length: {minimum: 4, message: "minlength"},
19
- format: {with: /\A(\/[a-z]+)+\z/, message: "pattern"}
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,16 +0,0 @@
1
- module Core
2
- module Models
3
- module Decorators
4
- module Errors
5
- # Error raised if the application key variable is missing.
6
- # @author Vincent Courtois <courtois.vincent@outlook.com>
7
- class EnvVariableMissing < Core::Models::Utils::Errors::HTTPError
8
-
9
- def initialize(action:)
10
- super(action, 'app_key', 'not_found', 404)
11
- end
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,11 +0,0 @@
1
- module Core
2
- module Models
3
- module Decorators
4
- # Module holding all the errors concerning the code of the decorators.
5
- # @author Vincent Courtois <courtois.vincent@outlook.com>
6
- module Errors
7
- autoload :EnvVariableMissing, 'core/models/decorators/errors/env_variable_missing'
8
- end
9
- end
10
- end
11
- end
@@ -1,111 +0,0 @@
1
- module Core
2
- module Models
3
- module Decorators
4
- # Decorator for a service, providing methods to make requests on it.
5
- # @author Vincent Courtois <courtois.vincent@outlook.com>
6
- class Gateway < Draper::Decorator
7
- delegate_all
8
-
9
- # @!attribute [rw] action
10
- # @return [String] the action of the route using this API.
11
- attr_accessor :action
12
-
13
- attr_accessor :logger
14
-
15
- def initialize(action, _object)
16
- super(_object)
17
- @logger = Logger.new(STDOUT)
18
- @action = action
19
- end
20
-
21
- # Shortcut to make a DELETE request on the API.
22
- # @param session [Core::Models::Authentication::Session] the session of the user requesting the API.
23
- # @param url [String] the URL you want to reach on the service.
24
- # @param params [Hash] the additional parameters to pass in the JSON body.
25
- def delete(session:, url:, params:)
26
- return make_request_without_body(verb: 'delete', session: session, url: url, params: params)
27
- end
28
-
29
- # Shortcut to make a GET request on the API.
30
- # @param session [Core::Models::Authentication::Session] the session of the user requesting the API.
31
- # @param url [String] the URL you want to reach on the service.
32
- # @param params [Hash] the additional parameters to pass in the JSON body.
33
- def get(session:, url:, params:)
34
- return make_request_without_body(verb: 'get', session: session, url: url, params: params)
35
- end
36
-
37
- # Shortcut to make a POST request on the API.
38
- # @param session [Core::Models::Authentication::Session] the session of the user requesting the API.
39
- # @param url [String] the URL you want to reach on the service.
40
- # @param params [Hash] the additional parameters to pass in the JSON body.
41
- def post(session:, url:, params:)
42
- return make_request(verb: 'post', session: session, url: url, params: params)
43
- end
44
-
45
- # Shortcut to make a PUT request on the API.
46
- # @param session [Core::Models::Authentication::Session] the session of the user requesting the API.
47
- # @param url [String] the URL you want to reach on the service.
48
- # @param params [Hash] the additional parameters to pass in the JSON body.
49
- def put(session:, url:, params:)
50
- return make_request(verb: 'put', session: session, url: url, params: params)
51
- end
52
-
53
- private
54
-
55
- # Makes a POST request to the given service with the following steps :
56
- # 1. Gets an active and running instance of the service to make the request.
57
- # 2. Creates a Faraday connection to use it as a pipeline for the request.
58
- # 3. Makes the actual request and returns an object with the status and body of the response.
59
- #
60
- # @param verb [String] the HTTP verb to use for this request.
61
- # @param session [Core::Models::Authentication::Session] the session of the user requesting the API.
62
- # @param url [String] the URL you want to reach on the service.
63
- # @param params [Hash] the additional parameters to pass in the JSON body.
64
- #
65
- # @return [Hash, Boolean] FALSE if no instance are found, or an object with :status and :body keys correspding
66
- # to the status and body of the response to the request
67
- def make_request(verb:, session:, url:, params:)
68
- params = before_requests(session, params)
69
- connection = get_connection
70
-
71
- response = connection.send(verb) do |req|
72
- req.url url
73
- req.headers['Content-Type'] = 'application/json'
74
- req.body = params.to_json
75
- end
76
-
77
- return {
78
- status: response.status,
79
- body: JSON.parse(response.body)
80
- }
81
- end
82
-
83
- def make_request_without_body(verb:, session:, url:, params:)
84
- params = before_requests(session, params)
85
- connection = get_connection
86
- response = connection.send(verb) do |req|
87
- req.url url, params
88
- req.headers['Content-Type'] = 'application/json'
89
- end
90
- end
91
-
92
- def before_requests(session, params)
93
- if ENV['APP_KEY'].nil?
94
- raise Core::Models::Decorators::Errors::EnvVariableMissing.new(action: action)
95
- end
96
- params[:app_key] = ENV['APP_KEY']
97
- params[:session_id] = session.token
98
- return params
99
- end
100
-
101
- def get_connection
102
- Faraday.new(object.url) do |faraday|
103
- faraday.request :url_encoded
104
- faraday.response :logger
105
- faraday.adapter Faraday.default_adapter
106
- end
107
- end
108
- end
109
- end
110
- end
111
- end
@@ -1,16 +0,0 @@
1
- module Core
2
- module Models
3
- module Factories
4
- module Errors
5
- # Error raised when not gateway active and running is found in the factory.
6
- # @author Vincent Courtois <courtois.vincent@outlook.com>
7
- class GatewayNotFound < Core::Models::Utils::Errors::HTTPError
8
-
9
- def initialize(action:)
10
- super(action, 'gateway_id', 'not_found', 404)
11
- end
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,11 +0,0 @@
1
- module Core
2
- module Models
3
- module Factories
4
- # Module holding all the errors concerning the code of the factories.
5
- # @author Vincent Courtois <courtois.vincent@outlook.com>
6
- module Errors
7
- autoload :GatewayNotFound, 'core/models/factories/errors/gateway_not_found'
8
- end
9
- end
10
- end
11
- end
@@ -1,10 +0,0 @@
1
- module Core
2
- module Models
3
- # Static factories are used to create decorated objects easily.
4
- # @author Vincent Courtois <courtois.vincent@outlook.com>
5
- module Factories
6
- autoload :Gateways, 'core/models/factories/gateways'
7
- autoload :Errors , 'core/models/factories/errors'
8
- end
9
- end
10
- end
@@ -1,33 +0,0 @@
1
- module Core
2
- module Models
3
- module Monitoring
4
- # A service is the representation of one of the applications composing the API.
5
- # @author Vincent Courtois <courtois.vincent@outlook.com>
6
- class Service
7
- include Mongoid::Document
8
- include Mongoid::Timestamps
9
- include Core::Models::Concerns::Activable
10
- include Core::Models::Concerns::Diagnosticable
11
- include Core::Models::Concerns::Premiumable
12
-
13
- # @!attribute [rw] key
14
- # @return [String] the name of the service, used as a namespace on the Kubernetes side.
15
- field :key, type: String
16
- # @!attribute [rw] path
17
- # @return [String] the path the service will be mapped on in the API. This will be used in the Ingress.
18
- field :path, type: String, default: '/'
19
-
20
- # @!attribute [rw] creator
21
- # @return [Core::Models::Account] the creator of this service.
22
- belongs_to :creator, class_name: 'Core::Models::Account', optional: true, inverse_of: :services
23
- # @!attribute [rw] routes
24
- # @return [Array<Core::Models::Monitoring::Route>] the routes associated to this service, accessible from the gateway.
25
- has_many :routes, class_name: 'Core::Models::Monitoring::Route', inverse_of: :service
26
-
27
- validates :key, uniqueness: {message: 'uniq'}
28
-
29
- validates :path, format: {with: /\A(\/:?[a-z]+)+\z/, message: 'pattern'}
30
- end
31
- end
32
- end
33
- end
@@ -1,10 +0,0 @@
1
- module Core
2
- module Models
3
- # The monitoring module holds all the logic about the services so they can be activated or deactivated.
4
- # @author Vincent Courtois <courtois.vincent@outlook.com>
5
- module Monitoring
6
- autoload :Route , 'core/models/monitoring/route'
7
- autoload :Service, 'core/models/monitoring/service'
8
- end
9
- end
10
- end