arkaan 2.4.0 → 2.7.0

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
  SHA256:
3
- metadata.gz: 88f3666897172e59135de5920b17f9356a7cdcf2877b5f5244eb21b55f95c7c8
4
- data.tar.gz: 73c232117a9f905d00d1853d03176460b139a8a8b9b59544a5975d6af825d5c1
3
+ metadata.gz: 15f29a2d1dc424ac2db2aed441e007437b4aab5fe6030711f89e8afe3ca7d1ed
4
+ data.tar.gz: c8f989b214ae66572e0b06249a95362642341c4a34ffe63c2eacb4e33e264150
5
5
  SHA512:
6
- metadata.gz: 3035f83abcc6a2970d3fa21b149fe70ab6f9e7908fa124c01917a54c89d087a1239694e82241882df74b672494b3e38d1a9951b83bca512b54ee10134f7e4c6b
7
- data.tar.gz: c5529c6c1c9ba7686492379bff4e2ab509d0a0f9515d1c77b190a175000af86ba8bedd22b2a919fa7c6a375253d8c9036fa41d5ab33d14c55a4eaec2a29d55e7
6
+ metadata.gz: 01dd270f06012cce7c1aef0e4da22deb04698e36312c1a306b9c465431fdf76cb267f86b4f616bbb8895d3b850ec3a6a9afd21e5c829d103e81ef1cbf0305952
7
+ data.tar.gz: 3e5a3d6cd2fdaff73b2cc88d754040267de4db4fb100ed4977a5f8ab106ccae7ba2b2e5fdfb2663b0f2fd07d87150bbb4a6e5783a7087d8019e4941eb00025e0
@@ -1,12 +1,6 @@
1
1
  require 'mongoid'
2
2
  require 'active_model'
3
3
  require 'active_support'
4
- require 'sinatra/base'
5
- require 'sinatra/config_file'
6
- require 'platform-api'
7
- require 'draper'
8
- require 'faraday'
9
- require 'sinatra/custom_logger'
10
4
  require 'dotenv/load'
11
5
 
12
6
  # Main module of the application, holding all the subsequent classes.
@@ -16,7 +10,10 @@ module Arkaan
16
10
  autoload :Authentication, 'arkaan/authentication'
17
11
  autoload :Campaign , 'arkaan/campaign'
18
12
  autoload :Campaigns , 'arkaan/campaigns'
13
+ autoload :Chatroom , 'arkaan/chatroom'
14
+ autoload :Chatrooms , 'arkaan/chatrooms'
19
15
  autoload :Concerns , 'arkaan/concerns'
16
+ autoload :Event , 'arkaan/event'
20
17
  autoload :Factories , 'arkaan/factories'
21
18
  autoload :Files , 'arkaan/files'
22
19
  autoload :Monitoring , 'arkaan/monitoring'
@@ -57,12 +57,14 @@ module Arkaan
57
57
  # @!attribute [rw] invitations
58
58
  # @return [Array<Arkaan::Campaigns::Invitation>] the invitations you've issued yourself to other players.
59
59
  has_many :created_invitations, class_name: 'Arkaan::Campaigns::Invitation', inverse_of: :creator
60
- # @!attribute [rw] websockets
61
- # @return [Array<Arkaan::Monitoring::Websocket>] the websockets created by the owner of this account.
62
- has_many :websockets, class_name: 'Arkaan::Monitoring::Websocket', inverse_of: :creator
63
60
  # @!attribute [rw] permissions
64
61
  # @return [Array<Arkaan::Files::Permission>] the file access permissions granted to this account.
65
62
  has_many :permissions, class_name: 'Arkaan::Files::Permission', inverse_of: :account
63
+ # @!attribute [rw] messages
64
+ # @return [Array<Arkaan::Chatrooms::Messages>] all the messages ever sent by the user.
65
+ has_many :messages, class_name: 'Arkaan::Chatrooms::Message', inverse_of: :account
66
+
67
+ has_many :memberships, class_name: 'Arkaan::Chatrooms::Membership', inverse_of: :account
66
68
 
67
69
  # @!attribute [rw] notifications
68
70
  # @return [Array<Arkaan::Notification>] the notifications linked to this user.
@@ -28,9 +28,9 @@ module Arkaan
28
28
  # @return [Array<Arkaan::Files::Document>] the files uploaded in this campaign.
29
29
  has_many :files, class_name: 'Arkaan::Files::Document'
30
30
 
31
- # @!attribute [rw] messages
32
- # @return [Array<Arkaan::Campaigns::Messages::Base>] the messages sent in the chatroom of the campaign.
33
- embeds_many :messages, class_name: 'Arkaan::Campaigns::Message', inverse_of: :campaign
31
+ # @!attribute [rw] chatroom
32
+ # @return [Arkaan::Chatrooms::Campaign] the chatroom linked to this campaign.
33
+ embeds_one :chatroom, class_name: 'Arkaan::Chatrooms::Campaign', inverse_of: :campaign
34
34
 
35
35
  # @!attribute [rw] ruleset
36
36
  # @return [Arkaan::Ruleset] the set of rules this campaign is based upon.
@@ -51,14 +51,15 @@ module Arkaan
51
51
  # @param account [Arkaan::Account] the account of the creator for this campaign.
52
52
  def creator=(account)
53
53
  if !invitations.where(account: account).exists?
54
- Arkaan::Campaigns::Invitation.create(campaign: self, account: account, enum_status: :creator)
54
+ invitation = Arkaan::Campaigns::Invitation.create(campaign: self, account: account)
55
+ invitation.status = :creator
55
56
  end
56
57
  end
57
58
 
58
59
  # Getter for the creator account of this campaign.
59
60
  # @return [Arkaan::Account] the account of the player creating this campaign.
60
61
  def creator
61
- return invitations.where(enum_status: :creator).first.account
62
+ invitations.to_a.find(&:status_creator?).account
62
63
  end
63
64
 
64
65
  # Adds an error message if the account creating this campaign already has a campaign with the very same name.
@@ -83,12 +84,22 @@ module Arkaan
83
84
 
84
85
  # @return [Array<Arkaan::Campaigns::Invitation>] the players in this campaign.
85
86
  def players
86
- invitations.where(enum_status: :accepted)
87
+ invitations.to_a.select do |invitation|
88
+ [:creator, :accepted].include? invitation.enum_status
89
+ end
87
90
  end
88
91
 
89
92
  # @return [Integer] the number of players in this campaign.
90
93
  def players_count
91
94
  players.count
92
95
  end
96
+
97
+ def messages
98
+ chatroom.messages
99
+ end
100
+
101
+ after_initialize do
102
+ self.chatroom = Arkaan::Chatrooms::Campaign.new(campaign: self)
103
+ end
93
104
  end
94
105
  end
@@ -3,7 +3,6 @@ module Arkaan
3
3
  # @author Vincent Courtois <courtois.vincent@outlook.com>
4
4
  module Campaigns
5
5
  autoload :Invitation, 'arkaan/campaigns/invitation'
6
- autoload :Message , 'arkaan/campaigns/message'
7
6
  autoload :Tag , 'arkaan/campaigns/tag'
8
7
  end
9
8
  end
@@ -1,15 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Arkaan
2
4
  module Campaigns
3
- # An invitation is the linked between a player and a campaign, accepted or not.
5
+ # An invitation is the linked between a player and a campaign.
6
+ # It keeps the history of the interaction between the player and the campaign.
7
+ #
4
8
  # @author Vincent Courtois <courtois.vincent@outlook.com>
5
9
  class Invitation
6
10
  include Mongoid::Document
7
11
  include Mongoid::Timestamps
8
12
  include Arkaan::Concerns::Enumerable
9
-
10
- # @!attribute [rw] status
11
- # @return [Symbol] the current status of the invitation.
12
- enum_field :status, [:accepted, :blocked, :expelled, :ignored, :left, :pending, :refused, :request, :creator], default: :pending
13
+ include Arkaan::Concerns::Historizable
13
14
 
14
15
  # @!attribute [rw] account
15
16
  # @return [Arkaan::Account] the account the invitation has been issued to.
@@ -17,6 +18,12 @@ module Arkaan
17
18
  # @!attribute [rw] campaign
18
19
  # @return [Arkaan::Campaign] the campaign the invitation has been made in.
19
20
  belongs_to :campaign, class_name: 'Arkaan::Campaign', inverse_of: :invitations
21
+
22
+ # @!attribute [rw] status
23
+ # @return [Symbol] the current status of the invitation.
24
+ historize enum_field :status,
25
+ [:pending, :request, :accepted, :refused, :expelled, :left, :master, :creator],
26
+ default: :pending
20
27
  end
21
28
  end
22
- end
29
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Arkaan
2
4
  module Campaigns
3
5
  # A campaign tag is a string describing a characteristic of the campaign it's in.
@@ -13,9 +15,7 @@ module Arkaan
13
15
  # @return [Integer] the number of campaigns this tag is in, avoiding a join.
14
16
  field :count, type: Integer, default: 1
15
17
 
16
- validates :content,
17
- presence: {message: 'required'},
18
- uniqueness: {message: 'uniq'}
18
+ validates :content, presence: { message: 'required' }, uniqueness: { message: 'uniq' }
19
19
  end
20
20
  end
21
- end
21
+ end
@@ -0,0 +1,11 @@
1
+ module Arkaan
2
+ # The chatrooms modules regroup all classes concerning messages between players.
3
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
4
+ module Chatrooms
5
+ autoload :Base , 'arkaan/chatrooms/base'
6
+ autoload :Campaign , 'arkaan/chatrooms/campaign'
7
+ autoload :Conversation, 'arkaan/chatrooms/conversation'
8
+ autoload :Message , 'arkaan/chatrooms/message'
9
+ autoload :Membership , 'arkaan/chatrooms/membership'
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ module Arkaan
2
+ module Chatrooms
3
+ # The base chatroom class, made to be subclassed in campaign and personal chatrooms.
4
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
5
+ class Base
6
+ include Mongoid::Document
7
+ include Mongoid::Timestamps
8
+
9
+ # @!attribute [rw] messages
10
+ # @return [Array<Arkaan::Chatrooms::Message>] the messages sent in this chatroom.
11
+ has_many :messages, class_name: 'Arkaan::Chatrooms::Message', inverse_of: :chatroom
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ module Arkaan
2
+ module Chatrooms
3
+ # Represents the chatroom embedded in a campaign.
4
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
5
+ class Campaign < Arkaan::Chatrooms::Base
6
+ # @!attribute [rw] campaign
7
+ # @return [Arkaan::Campaign] the campaign the chatroom is linked to.
8
+ embedded_in :campaign, class_name: 'Arkaan::Campaign', inverse_of: :chatroom
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module Arkaan
2
+ module Chatrooms
3
+ class Conversation < Arkaan::Chatrooms::Base
4
+ has_many :memberships, class_name: 'Arkaan::Chatrooms::Membership', inverse_of: :chatroom
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ module Arkaan
2
+ module Chatrooms
3
+ class Membership
4
+ include Mongoid::Document
5
+ include Mongoid::Timestamps
6
+ include Arkaan::Concerns::Enumerable
7
+
8
+ enum_field :status, [:shown, :hidden], default: :shown
9
+
10
+ belongs_to :chatroom, class_name: 'Arkaan::Chatrooms::Private', inverse_of: :memberships
11
+
12
+ belongs_to :account, class_name: 'Arkaan::Account', inverse_of: :memberships
13
+ end
14
+ end
15
+ end
@@ -1,5 +1,5 @@
1
1
  module Arkaan
2
- module Campaigns
2
+ module Chatrooms
3
3
  # This model represents an in-game tchat message sent in the tchat of a campaign.
4
4
  # @author Vincent Courtois <courtois.vincent@outlook.com>
5
5
  class Message
@@ -13,16 +13,19 @@ module Arkaan
13
13
  # @!attribute [rw] data
14
14
  # @return [Hash] the additional data passed to the message (arguments of the command, or content of the text)
15
15
  field :data, type: Hash, default: {}
16
+ # @!attribute {rw} raw
17
+ # @return [String] the content as typed by the user, without any parsing or transformation.
18
+ field :raw, type: String, default: ''
16
19
  # @!attribute [rw] deleted
17
20
  # @return [Boolean] TRUE if the message has been marked as deleted by its user, FALSE otherwise.
18
21
  field :deleted, type: Boolean, default: false
19
22
 
20
23
  # @!attribute [rw] campaign
21
- # @return [Arkaan::Campaign] the campaign in which the message has been emitted.
22
- embedded_in :campaign, class_name: 'Arkaan::Campaign', inverse_of: :messages
24
+ # @return [Arkaan::Chatrooms::Campaign] the chatroom in which the message has been emitted.
25
+ belongs_to :chatroom, class_name: 'Arkaan::Chatrooms::Campaign', inverse_of: :messages
23
26
  # @!attribute [rw] player
24
27
  # @return [Arkaan::Account] the account that has emitted the message in the campaign.
25
- belongs_to :player, class_name: 'Arkaan::Campaigns::Invitation'
28
+ belongs_to :account, class_name: 'Arkaan::Account', inverse_of: :messages
26
29
  end
27
30
  end
28
31
  end
@@ -5,6 +5,7 @@ module Arkaan
5
5
  autoload :Activable , 'arkaan/concerns/activable'
6
6
  autoload :Diagnosticable, 'arkaan/concerns/diagnosticable'
7
7
  autoload :Enumerable , 'arkaan/concerns/enumerable'
8
+ autoload :Historizable , 'arkaan/concerns/historizable'
8
9
  autoload :MimeTypable , 'arkaan/concerns/mime_typable'
9
10
  autoload :Premiumable , 'arkaan/concerns/premiumable'
10
11
  autoload :Sluggable , 'arkaan/concerns/sluggable'
@@ -14,7 +14,7 @@ module Arkaan
14
14
  # @param values [Array<Symbol>] the possible values of the enumerated field.
15
15
  # @param options [Hash<Symbol, Any>] the possible options for the field.
16
16
  def enum_field(field_name, values, options = {})
17
- field :"enum_#{field_name}", type: Symbol, default: options[:default]
17
+ returned = field :"enum_#{field_name}", type: Symbol, default: options[:default]
18
18
 
19
19
  validates :"enum_#{field_name}", inclusion: {in: values.map(&:to_sym), message: 'inclusion'}
20
20
 
@@ -37,6 +37,10 @@ module Arkaan
37
37
  self["enum_#{field_name}"] == value
38
38
  end
39
39
  end
40
+
41
+ # This is to make enumerations historizable by
42
+ # returning the field object created by Mongoid.
43
+ returned
40
44
  end
41
45
  end
42
46
  end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Arkaan
4
+ module Concerns
5
+ # This module is what I call "a beautiful piece of Ruby engineering"
6
+ # It takes any mongoid field that you may have declared, and historizes
7
+ # it in a dedicated relation if this relation does not already exists.
8
+ #
9
+ # What it does exactly :
10
+ # - Creates the :history relation if it does not already exists.
11
+ # - Creates a method to check for changes of a specific attribute.
12
+ # - Check for changes at initialization to insert the first value.
13
+ # - Check for changes at update/save to store the history.
14
+ #
15
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
16
+ module Historizable
17
+ extend ActiveSupport::Concern
18
+
19
+ # Adds an entry in the history table for the given field.
20
+ # It checks several things to make the history entry valid :
21
+ # - the new value is different from the old value
22
+ # - the old value is identical to the last recorded new value.
23
+ #
24
+ # @param field [String] the name of the field to historize
25
+ # @param from [Any] the old value before update
26
+ # @param to [Any] the new value after update.
27
+ def add_history(field:, from:, to:)
28
+ return if from == to
29
+ return if !history.empty? && history.order_by(:created_at.desc).first.to != from
30
+
31
+ event = Arkaan::Event.create(field: field, from: from, to: to, document: self)
32
+ event.save
33
+ end
34
+
35
+ # Submodule holding all the static methods add to the current subclass.
36
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
37
+ module ClassMethods
38
+
39
+ # Takes the Mongoid declared field and creates the callbacks
40
+ # to intercept any value change and add it to the history.
41
+ # @field field [Mongoid::Fields::Standard] the Mongoid field to historize.
42
+ def historize(field)
43
+
44
+ unless relations.key?('history')
45
+ embeds_many :history, class_name: 'Arkaan::Event'
46
+ end
47
+
48
+ after_initialize do |doc|
49
+ add_history(field: field.name, from: nil, to: doc[field.name])
50
+ end
51
+
52
+ after_save do |doc|
53
+ if doc.changed_attributes.key?(field.name)
54
+ from = doc.changed_attributes[field.name]
55
+ add_history(field: field.name, from: from, to: doc[field.name])
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Arkaan
4
+ # An event is symbolizing a timestamped change in a model.
5
+ # It is recommended NOT to use this class directly but to use
6
+ # the Arkaan::Concerns::Historizable concern in a model.
7
+ #
8
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
9
+ class Event
10
+ include Mongoid::Document
11
+ include Mongoid::Timestamps
12
+
13
+ # @!attribute [rw] field
14
+ # @return [String] the name of the field being historized
15
+ field :field, type: String
16
+ # @!attribute [rw] from
17
+ # @return [Any] the value of the field before update
18
+ field :from
19
+ # @!attribute [rw] to
20
+ # @return [Any] the value of the field after update
21
+ field :to
22
+
23
+ # @!attribute [rw] document
24
+ # @return [Any] the model in which the history is embedded
25
+ embedded_in :document, polymorphic: true, inverse_of: :history
26
+
27
+ validates :field, presence: { message: 'required' }
28
+ end
29
+ end
@@ -30,11 +30,21 @@ module Arkaan
30
30
  # @return [Array<Arkaan::Files::Permission>] the permissions granted to access this file.
31
31
  has_many :permissions, class_name: 'Arkaan::Files::Permission', inverse_of: :file
32
32
 
33
- validates :name, uniqueness: {message: 'uniq'}
34
-
35
33
  validates :name, :extension, :folder, :mime_type, presence: {message: 'required'}
36
34
 
37
35
  validates :folder, format: {without: /\/\//, message: 'format'}
36
+
37
+ validate :filename_unicity
38
+
39
+ def filename_unicity
40
+ existing = Arkaan::Files::Document.where(
41
+ name: name,
42
+ folder: folder,
43
+ extension: extension,
44
+ :id.ne => id
45
+ )
46
+ errors.add(:name, 'uniq') unless existing.first.nil?
47
+ end
38
48
  end
39
49
  end
40
50
  end
@@ -2,13 +2,7 @@ module Arkaan
2
2
  # The monitoring module holds all the logic about the services so they can be activated or deactivated.
3
3
  # @author Vincent Courtois <courtois.vincent@outlook.com>
4
4
  module Monitoring
5
- autoload :Action , 'arkaan/monitoring/action'
6
- autoload :Gateway , 'arkaan/monitoring/gateway'
7
- autoload :Instance , 'arkaan/monitoring/instance'
8
- autoload :Results , 'arkaan/monitoring/results'
9
- autoload :Route , 'arkaan/monitoring/route'
10
- autoload :Service , 'arkaan/monitoring/service'
11
- autoload :Vigilante, 'arkaan/monitoring/vigilante'
12
- autoload :Websocket, 'arkaan/monitoring/websocket'
5
+ autoload :Route , 'arkaan/monitoring/route'
6
+ autoload :Service, 'arkaan/monitoring/service'
13
7
  end
14
8
  end
@@ -10,21 +10,15 @@ module Arkaan
10
10
  include Arkaan::Concerns::Premiumable
11
11
 
12
12
  # @!attribute [rw] key
13
- # @return [String] the name, or title of the service, optionally given to identify it more easily.
13
+ # @return [String] the name of the service, used as a namespace on the Kubernetes side.
14
14
  field :key, type: String
15
15
  # @!attribute [rw] path
16
- # @return [String] the path the service will be mapped on in the API.
16
+ # @return [String] the path the service will be mapped on in the API. This will be used in the Ingress.
17
17
  field :path, type: String, default: '/'
18
- # @!attribute [rw] test_mode
19
- # @return [Boolean] TRUE if the service is currently in test mode and thus the gateway shall only qurty local instances.
20
- field :test_mode, type: Boolean, default: false
21
18
 
22
19
  # @!attribute [rw] creator
23
20
  # @return [Arkaan::Account] the creator of this service.
24
21
  belongs_to :creator, class_name: 'Arkaan::Account', optional: true, inverse_of: :services
25
- # @!attribute [rw] instances
26
- # @return [Array<Arkaan::Monitoring::Instance>] the instances of this service currently deployed.
27
- embeds_many :instances, class_name: 'Arkaan::Monitoring::Instance', inverse_of: :service
28
22
  # @!attribute [rw] routes
29
23
  # @return [Array<Arkaan::Monitoring::Route>] the routes associated to this service, accessible from the gateway.
30
24
  has_many :routes, class_name: 'Arkaan::Monitoring::Route', inverse_of: :service
@@ -1,6 +1,7 @@
1
1
  module Arkaan
2
2
  module OAuth
3
- # An access token is the value assigned to the application to access the private data of an account.
3
+ # An access token is the value assigned to the application
4
+ # to access the data the user is allowed to access.
4
5
  # @author Vincent Courtois <courtois.vincent@outlook.com>
5
6
  class AccessToken
6
7
  include Mongoid::Document
@@ -15,11 +16,17 @@ module Arkaan
15
16
 
16
17
  # @!attribute [rw] authorization
17
18
  # @return [Arkaan::OAuth::Authorization] the authorization code that issued this token to the application for this user.
18
- belongs_to :authorization, class_name: 'Arkaan::OAuth::Authorization', inverse_of: :access_token
19
+ belongs_to :authorization, class_name: 'Arkaan::OAuth::Authorization', inverse_of: :tokens
19
20
 
20
21
  validates :value,
21
22
  presence: {message: 'required'},
22
23
  uniqueness: {message: 'uniq'}
24
+
25
+ # Checks if the current date is inferior to the creation date + expiration period
26
+ # @return [Boolean] TRUE if the token is expired, FALSE otherwise.
27
+ def expired?
28
+ created_at.to_time.to_i + expiration < Time.now.to_i
29
+ end
23
30
  end
24
31
  end
25
32
  end
@@ -1,6 +1,9 @@
1
1
  module Arkaan
2
2
  module OAuth
3
3
  # An OAuth authorization is granted by a user to an application to access its personal data.
4
+ # The application then transforms it into an access token to be able to send it with
5
+ # further requests, so that we know the user has authorized the application to access its data.
6
+ #
4
7
  # @author Vincent Courtois <courtois.vincent@outlook.com>
5
8
  class Authorization
6
9
  include Mongoid::Document
@@ -18,7 +21,7 @@ module Arkaan
18
21
  belongs_to :application, class_name: 'Arkaan::OAuth::Application', inverse_of: :authorizations
19
22
  # @!attribute [rw] token
20
23
  # @return [Arkaan::OAuth::AccessToken] the access token used further in the application process to access private data of the account.
21
- has_one :token, class_name: 'Arkaan::OAuth::AccessToken', inverse_of: :authorization
24
+ has_many :tokens, class_name: 'Arkaan::OAuth::AccessToken', inverse_of: :authorization
22
25
 
23
26
  validates :code,
24
27
  presence: {message: 'required'},
@@ -1,3 +1,3 @@
1
1
  module Arkaan
2
- VERSION = '2.4.0'
2
+ VERSION = '2.7.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arkaan
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Courtois
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-06 00:00:00.000000000 Z
11
+ date: 2020-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -165,35 +165,35 @@ dependencies:
165
165
  - !ruby/object:Gem::Version
166
166
  version: 2.10.0
167
167
  - !ruby/object:Gem::Dependency
168
- name: mongoid
168
+ name: rubocop
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - '='
172
172
  - !ruby/object:Gem::Version
173
- version: 7.0.1
174
- type: :runtime
173
+ version: 0.85.1
174
+ type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - '='
179
179
  - !ruby/object:Gem::Version
180
- version: 7.0.1
180
+ version: 0.85.1
181
181
  - !ruby/object:Gem::Dependency
182
- name: activemodel
182
+ name: mongoid
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
185
  - - '='
186
186
  - !ruby/object:Gem::Version
187
- version: 5.2.3
187
+ version: 7.0.1
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: 5.2.3
194
+ version: 7.0.1
195
195
  - !ruby/object:Gem::Dependency
196
- name: activesupport
196
+ name: activemodel
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
199
  - - '='
@@ -207,103 +207,33 @@ dependencies:
207
207
  - !ruby/object:Gem::Version
208
208
  version: 5.2.3
209
209
  - !ruby/object:Gem::Dependency
210
- name: bcrypt
211
- requirement: !ruby/object:Gem::Requirement
212
- requirements:
213
- - - '='
214
- - !ruby/object:Gem::Version
215
- version: 3.1.11
216
- type: :runtime
217
- prerelease: false
218
- version_requirements: !ruby/object:Gem::Requirement
219
- requirements:
220
- - - '='
221
- - !ruby/object:Gem::Version
222
- version: 3.1.11
223
- - !ruby/object:Gem::Dependency
224
- name: sinatra
225
- requirement: !ruby/object:Gem::Requirement
226
- requirements:
227
- - - '='
228
- - !ruby/object:Gem::Version
229
- version: 2.0.5
230
- type: :runtime
231
- prerelease: false
232
- version_requirements: !ruby/object:Gem::Requirement
233
- requirements:
234
- - - '='
235
- - !ruby/object:Gem::Version
236
- version: 2.0.5
237
- - !ruby/object:Gem::Dependency
238
- name: sinatra-contrib
239
- requirement: !ruby/object:Gem::Requirement
240
- requirements:
241
- - - '='
242
- - !ruby/object:Gem::Version
243
- version: 2.0.5
244
- type: :runtime
245
- prerelease: false
246
- version_requirements: !ruby/object:Gem::Requirement
247
- requirements:
248
- - - '='
249
- - !ruby/object:Gem::Version
250
- version: 2.0.5
251
- - !ruby/object:Gem::Dependency
252
- name: platform-api
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: faraday
267
- requirement: !ruby/object:Gem::Requirement
268
- requirements:
269
- - - '='
270
- - !ruby/object:Gem::Version
271
- version: 0.15.2
272
- type: :runtime
273
- prerelease: false
274
- version_requirements: !ruby/object:Gem::Requirement
275
- requirements:
276
- - - '='
277
- - !ruby/object:Gem::Version
278
- version: 0.15.2
279
- - !ruby/object:Gem::Dependency
280
- name: draper
210
+ name: activesupport
281
211
  requirement: !ruby/object:Gem::Requirement
282
212
  requirements:
283
213
  - - '='
284
214
  - !ruby/object:Gem::Version
285
- version: 3.1.0
215
+ version: 5.2.3
286
216
  type: :runtime
287
217
  prerelease: false
288
218
  version_requirements: !ruby/object:Gem::Requirement
289
219
  requirements:
290
220
  - - '='
291
221
  - !ruby/object:Gem::Version
292
- version: 3.1.0
222
+ version: 5.2.3
293
223
  - !ruby/object:Gem::Dependency
294
- name: actionview
224
+ name: bcrypt
295
225
  requirement: !ruby/object:Gem::Requirement
296
226
  requirements:
297
227
  - - '='
298
228
  - !ruby/object:Gem::Version
299
- version: 5.2.3
229
+ version: 3.1.11
300
230
  type: :runtime
301
231
  prerelease: false
302
232
  version_requirements: !ruby/object:Gem::Requirement
303
233
  requirements:
304
234
  - - '='
305
235
  - !ruby/object:Gem::Version
306
- version: 5.2.3
236
+ version: 3.1.11
307
237
  - !ruby/object:Gem::Dependency
308
238
  name: dotenv
309
239
  requirement: !ruby/object:Gem::Requirement
@@ -331,12 +261,18 @@ files:
331
261
  - lib/arkaan/campaign.rb
332
262
  - lib/arkaan/campaigns.rb
333
263
  - lib/arkaan/campaigns/invitation.rb
334
- - lib/arkaan/campaigns/message.rb
335
264
  - lib/arkaan/campaigns/tag.rb
265
+ - lib/arkaan/chatrooms.rb
266
+ - lib/arkaan/chatrooms/base.rb
267
+ - lib/arkaan/chatrooms/campaign.rb
268
+ - lib/arkaan/chatrooms/conversation.rb
269
+ - lib/arkaan/chatrooms/membership.rb
270
+ - lib/arkaan/chatrooms/message.rb
336
271
  - lib/arkaan/concerns.rb
337
272
  - lib/arkaan/concerns/activable.rb
338
273
  - lib/arkaan/concerns/diagnosticable.rb
339
274
  - lib/arkaan/concerns/enumerable.rb
275
+ - lib/arkaan/concerns/historizable.rb
340
276
  - lib/arkaan/concerns/mime_typable.rb
341
277
  - lib/arkaan/concerns/premiumable.rb
342
278
  - lib/arkaan/concerns/sluggable.rb
@@ -344,24 +280,16 @@ files:
344
280
  - lib/arkaan/decorators/errors.rb
345
281
  - lib/arkaan/decorators/errors/env_variable_missing.rb
346
282
  - lib/arkaan/decorators/gateway.rb
283
+ - lib/arkaan/event.rb
347
284
  - lib/arkaan/factories.rb
348
285
  - lib/arkaan/factories/errors.rb
349
286
  - lib/arkaan/factories/errors/gateway_not_found.rb
350
- - lib/arkaan/factories/gateways.rb
351
287
  - lib/arkaan/files.rb
352
288
  - lib/arkaan/files/document.rb
353
289
  - lib/arkaan/files/permission.rb
354
290
  - lib/arkaan/monitoring.rb
355
- - lib/arkaan/monitoring/action.rb
356
- - lib/arkaan/monitoring/gateway.rb
357
- - lib/arkaan/monitoring/instance.rb
358
- - lib/arkaan/monitoring/results.rb
359
- - lib/arkaan/monitoring/results/heartbeat.rb
360
- - lib/arkaan/monitoring/results/report.rb
361
291
  - lib/arkaan/monitoring/route.rb
362
292
  - lib/arkaan/monitoring/service.rb
363
- - lib/arkaan/monitoring/vigilante.rb
364
- - lib/arkaan/monitoring/websocket.rb
365
293
  - lib/arkaan/notification.rb
366
294
  - lib/arkaan/oauth.rb
367
295
  - lib/arkaan/oauth/access_token.rb
@@ -393,7 +321,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
393
321
  - !ruby/object:Gem::Version
394
322
  version: '0'
395
323
  requirements: []
396
- rubygems_version: 3.0.3
324
+ rubygems_version: 3.1.2
397
325
  signing_key:
398
326
  specification_version: 4
399
327
  summary: The model layer for my table-RPG application
@@ -1,19 +0,0 @@
1
- module Arkaan
2
- module Factories
3
- # This class provides methods to create decorated services.
4
- # @author Vincent Courtois <courtois.vincent@outlook.com>
5
- class Gateways
6
-
7
- # Searches for a gateway via its key and returns it decorated.
8
- # @param key [String] the key of the server you want to find.
9
- # @return [Arkaan::Decorators::Gateway, NilClass] nil if the gateway is not found, or the decorated gateway.
10
- def self.random(action)
11
- gateway = Arkaan::Monitoring::Gateway.where(active: true, running: true).first
12
- if gateway.nil?
13
- raise Arkaan::Factories::Errors::GatewayNotFound.new(action: action)
14
- end
15
- return Arkaan::Decorators::Gateway.new(action, gateway)
16
- end
17
- end
18
- end
19
- end
@@ -1,25 +0,0 @@
1
- module Arkaan
2
- module Monitoring
3
- # An action is made by an authorized user on the instance of a server to perform a task.
4
- # @author Vincent Courtois <courtois.vincent@outlook.com>
5
- class Action
6
- include Mongoid::Document
7
- include Mongoid::Timestamps
8
- include Arkaan::Concerns::Enumerable
9
-
10
- # @!attribute [rw] type
11
- # @return [Symbol] the type of action you're making on this instance
12
- enum_field :type, [:restart]
13
- # @!attribute [rw] success
14
- # @return [Boolean] TRUE if the action succeeded (or at least was successfully launched), FALSE otherwise.
15
- field :success, type: Boolean, default: false
16
-
17
- # @!attribute [rw] user
18
- # @return [Arkaan::Account] the user performing the action on the instance.
19
- belongs_to :user, class_name: 'Arkaan::Account'
20
- # @!attribute [rw] instance
21
- # @return [Arkaan::Monitoring::Instance] the instance of a service on which the action is performed.
22
- embedded_in :instance, class_name: 'Arkaan::Monitoring::Instance', inverse_of: :actions
23
- end
24
- end
25
- end
@@ -1,37 +0,0 @@
1
- module Arkaan
2
- module Monitoring
3
- # A gateway is a portal by which you access the different web services of the application suite.
4
- # @author Vincent Courtois <courtois.vincent@outlook.com>
5
- class Gateway
6
- include Mongoid::Document
7
- include Mongoid::Timestamps
8
- include Arkaan::Concerns::Activable
9
- include Arkaan::Concerns::Diagnosticable
10
- include Arkaan::Concerns::Typable
11
-
12
- # @!attribute [rw] url
13
- # @return [String] the URL of the gateway, where the requests will be issued.
14
- field :url, type: String
15
- # @!attribute [rw] running
16
- # @return [Boolean] the running status of the gateway, indicating if it can be used or not.
17
- field :running, type: Boolean, default: false
18
- # @!attribute [rw] gateways
19
- # @return [String] the uniq token for this gateway, identifying it in the micro services.
20
- field :token, type: String
21
-
22
- scope :running , ->{ where(running: true) }
23
-
24
- validates :url,
25
- presence: {message: 'required'},
26
- format: {
27
- with: /\A(https?:\/\/)((localhost:[0-9]+)|(([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*)|(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b):([0-9]{2,6}))\/?\z/,
28
- message: 'pattern',
29
- if: :url?
30
- }
31
-
32
- validates :token,
33
- presence: {message: 'required'},
34
- uniqueness: {message: 'uniq'}
35
- end
36
- end
37
- end
@@ -1,38 +0,0 @@
1
- module Arkaan
2
- module Monitoring
3
- # An instance is one of the services, deployed on one server. A service may have many instances to balance the load between them all.
4
- # @author Vincent Courtois <courtois.vincent@outlook.com>
5
- class Instance
6
- include Mongoid::Document
7
- include Mongoid::Timestamps
8
- include Arkaan::Concerns::Activable
9
- include Arkaan::Concerns::Typable
10
-
11
- # @!attribute [rw] url
12
- # @return [String] the URL of the instance, where the requests will be issued.
13
- field :url, type: String
14
- # @!attribute [rw] running
15
- # @return [Boolean] the running status of the instance, indicating if it can be used or not.
16
- field :running, type: Boolean, default: false
17
- # @!attribute [rw] data
18
- # @return [Hash] the additional datas for this instance (for example for an Heroku instance it's all the data provided by the API)
19
- field :data, type: Hash, default: {}
20
-
21
- scope :running , ->{ where(running: true) }
22
-
23
- # @!attribute [r] service
24
- # @return [Arkaan::Monitoring::Service] the service this instance is linked to.
25
- embedded_in :service, class_name: 'Arkaan::Monitoring::Service', inverse_of: :instances
26
- # @!attribute [rw] actions
27
- # @return [Arkaan::Monitoring::Action] the actions that has been performed on the service.
28
- embeds_many :actions, class_name: 'Arkaan::Monitoring::Action', inverse_of: :instance
29
-
30
- has_many :heartbeats, class_name: 'Arkaan::Monitoring::Results::Heartbeat', inverse_of: :instance
31
-
32
- validates :url,
33
- presence: {message: 'required'},
34
- format: {with: /\A(https?:\/\/)((([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*)|(localhost:[0-9]{2,4})\/?)\z/, message: 'pattern', if: :url?}
35
- end
36
- end
37
- end
38
-
@@ -1,10 +0,0 @@
1
- module Arkaan
2
- module Monitoring
3
- # The results module handle classes to make results for the vigilante runs.
4
- # @author Vincent Courtois <courtois.vincent@outlook.com>
5
- module Results
6
- autoload :Report, 'arkaan/monitoring/results/report'
7
- autoload :Heartbeat, 'arkaan/monitoring/results/heartbeat'
8
- end
9
- end
10
- end
@@ -1,50 +0,0 @@
1
- module Arkaan
2
- module Monitoring
3
- module Results
4
- # A record is the result of the vigilante asking the health of one instance.
5
- # @author Vincent Courtois <courtois.vincent@outlook.com>
6
- class Heartbeat
7
- include Mongoid::Document
8
-
9
- # @!attribute [rw] status
10
- # @return [Integer] the HTTP status of the request made for this record.
11
- field :status, type: Integer, default: 500
12
- # @!attribute [rw] body
13
- # @return [Hash] the JSON parsed body from the heartbeat request.
14
- field :body, type: Hash, default: {}
15
- # @!attribute [rw] healthy
16
- # @return [Boolean] TRUE if the instance is deemed healthy, FALSE otherwise.
17
- field :healthy, type: Boolean, default: false
18
- # @!attribute [rw] started_at
19
- # @return [DateTime] the date at which the heartbeat request has started.
20
- field :started_at, type: DateTime
21
- # @!attribute [rw] ended_at
22
- # @return [DateTime] the date at which the request was terminated.
23
- field :ended_at, type: DateTime
24
-
25
- # @!attribute [rw] instance
26
- # @return [Arkaan::Monitoring::Instance] the instance on which the record has been done.
27
- belongs_to :instance, class_name: 'Arkaan::Monitoring::Instance', inverse_of: :heartbeats
28
-
29
- # @!attribute [rw] report
30
- # @return [Arkaan::Monitoring::Results::Report] the report made by the vigilante including this record.
31
- belongs_to :report, class_name: 'Arkaan::Monitoring::Results::Report', inverse_of: :heartbeats
32
-
33
- attr_readonly :healthy
34
-
35
- def status=(status)
36
- self[:status] = status
37
- self[:healthy] = status == 200
38
- end
39
-
40
- def start!
41
- self.started_at = DateTime.now
42
- end
43
-
44
- def end!
45
- self.ended_at = DateTime.now
46
- end
47
- end
48
- end
49
- end
50
- end
@@ -1,46 +0,0 @@
1
- module Arkaan
2
- module Monitoring
3
- module Results
4
- # A report is the result of one call to the API on one instance status route.
5
- # @author Vincent Courtois <courtoi.vincent@outlook.com>
6
- class Report
7
- include Mongoid::Document
8
- include Mongoid::Timestamps
9
-
10
- field :started_at, type: DateTime
11
- # @!attribute [rw] ended_at
12
- # @return [DateTime] the timestamp at which the report ends.
13
- field :ended_at, type: DateTime
14
- # @!attribute [rw] total
15
- # @return [Integer] the total number of services monitored.
16
- field :total, type: Integer, default: 0
17
- # @!attribute [rw] healthy
18
- # @return [Integer] the number of healthy services amongst all the monitored services.
19
- field :healthy, type: Integer, default: 0
20
-
21
- # @!attribute [rw] records
22
- # @return [Array<Arkaan::Monitoring::Results::Record>] the records linked to this report.
23
- has_many :heartbeats, class_name: 'Arkaan::Monitoring::Results::Heartbeat', inverse_of: :report
24
- # @!attribute [rw] vigilante
25
- # @return [Arkaan::Monitoring::Vigilante] the vigilante application that has created this report.
26
- belongs_to :vigilante, class_name: 'Arkaan::Monitoring::Vigilante', inverse_of: :reports
27
-
28
- def add_heartbeat(heartbeat)
29
- self.heartbeats << heartbeat
30
- self.total += 1
31
- self.healthy += (heartbeat.healthy ? 1 : 0)
32
- heartbeat.end!
33
- end
34
-
35
- def start!
36
- self.started_at = DateTime.now
37
- end
38
-
39
- def end!
40
- self.ended_at = DateTime.now
41
- self.save!
42
- end
43
- end
44
- end
45
- end
46
- end
@@ -1,48 +0,0 @@
1
- module Arkaan
2
- module Monitoring
3
- # A vigilante is a specific type of service that watches over the
4
- # infrastructure and give a clear look at its global state.
5
- # @author Vincent Courtois <courtois.vincent@outlook.com>
6
- class Vigilante
7
- include Mongoid::Document
8
- include Mongoid::Timestamps
9
-
10
- # @!attribute [rw] token
11
- # @return [String] the token the vigilante uses to identify himself in the services
12
- field :token, type: String
13
- # @!attribute [rw] max_results
14
- # @return [Integer] the number of results the vigilante should be keeping at any time.
15
- # The oldest result should be erased to not go over the limit
16
- field :max_results, type: Integer, default: 20
17
-
18
- # @!attribute [rw] reports
19
- # @return [Array<Arkaan::monitoring::Results::Report>] the report generated by running this vigilante.
20
- has_many :reports, class_name: 'Arkaan::Monitoring::Results::Report', inverse_of: :vigilante
21
-
22
- validates :token, presence: {message: 'required'}
23
-
24
- validates :max_results,
25
- numericality: {greater_than: 0, message: 'minimum'}
26
-
27
- # Adds a report to the collection of reports by eventually deleting the oldest one.
28
- # @param report [Arkaan::Monitoring::Results::Report] the report to add to the vigilante,
29
- # added only if it does not exceed the max number of reports the vigilante can store.
30
- def add_report(report)
31
- erase_oldest_result if result_full?
32
- reports << report
33
- end
34
-
35
- # Checks if the list of reports is already full, or if more can be added.
36
- # @return [Boolean] TRUE if the number of reports already exceeds the max number.
37
- def results_full?
38
- reports.to_a.count >= max_results
39
- end
40
-
41
- # Erases the oldest results to keep only MAX - 1 results in the list.
42
- def erase_oldest_result
43
- limit = reports.count + 1 - vigilante.max_results
44
- reports.sort_by(created_at: :asc).limit(limit).each(&:delete)
45
- end
46
- end
47
- end
48
- end
@@ -1,25 +0,0 @@
1
- module Arkaan
2
- module Monitoring
3
- # The websocket is a particular kind of service, just like the gateway. It always has the same signature.
4
- # A websocket document is a particular instance of websocket, located on a server and answering to a URL.
5
- # @author Vincent Courtois <courtois.vincent@outlook.com>
6
- class Websocket
7
- include Mongoid::Document
8
- include Mongoid::Timestamps
9
- include Arkaan::Concerns::Activable
10
- include Arkaan::Concerns::Diagnosticable
11
-
12
- # @!attribute [rw] url
13
- # @return [String] the URL of the websocket to be contacted on.
14
- field :url, type: String
15
-
16
- # @!attribute [rw] creator
17
- # @return [Arkaan::Account] the account that created this web socket instance in the database.
18
- belongs_to :creator, class_name: 'Arkaan::Account', inverse_of: :web_sockets, optional: true
19
-
20
- validates :url,
21
- presence: {message: 'required'},
22
- format: {with: /\A(ws:\/\/)([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?\z/, message: 'pattern', if: :url?}
23
- end
24
- end
25
- end