Class: SelfSDK::ACL
- Inherits:
-
Object
- Object
- SelfSDK::ACL
- Defined in:
- lib/acl.rb
Overview
Access control list
Instance Method Summary collapse
-
#allow(id) ⇒ Object
Allows incomming messages from the given identity.
-
#deny(id) ⇒ Object
Deny incomming messages from the given identity.
-
#initialize(messaging) ⇒ ACL
constructor
A new instance of ACL.
-
#list ⇒ Object
Lists allowed connections.
Constructor Details
permalink #initialize(messaging) ⇒ ACL
Returns a new instance of ACL.
11 12 13 14 15 |
# File 'lib/acl.rb', line 11 def initialize(messaging) @messaging = messaging @jwt = @messaging.jwt @acl_rules = [] end |
Instance Method Details
permalink #allow(id) ⇒ Object
Allows incomming messages from the given identity.
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/acl.rb', line 25 def allow(id) @acl_rules << id SelfSDK.logger.info "Allowing connections from #{id}" @messaging.add_acl_rule(@jwt.prepare(jti: SecureRandom.uuid, cid: SecureRandom.uuid, typ: 'acl.permit', iss: @jwt.id, sub: @jwt.id, iat: (SelfSDK::Time.now - 5).strftime('%FT%TZ'), exp: (SelfSDK::Time.now + 60).strftime('%FT%TZ'), acl_source: id, acl_exp: (SelfSDK::Time.now + 360_000).to_datetime.rfc3339)) end |
permalink #deny(id) ⇒ Object
Deny incomming messages from the given identity.
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/acl.rb', line 40 def deny(id) @acl_rules.delete(id) SelfSDK.logger.info "Denying connections from #{id}" @messaging.remove_acl_rule(@jwt.prepare(jti: SecureRandom.uuid, cid: SecureRandom.uuid, typ: 'acl.revoke', iss: @jwt.id, sub: @jwt.id, iat: (SelfSDK::Time.now - 5).strftime('%FT%TZ'), exp: (SelfSDK::Time.now + 60).strftime('%FT%TZ'), acl_source: id, acl_exp: (SelfSDK::Time.now + 360_000).to_datetime.rfc3339)) end |
permalink #list ⇒ Object
Lists allowed connections.
18 19 20 21 22 |
# File 'lib/acl.rb', line 18 def list SelfSDK.logger.info "Listing allowed connections" @acl_rules = @messaging.list_acl_rules if @acl_rules.empty? @acl_rules end |