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.
9 10 11 12 |
# File 'lib/acl.rb', line 9 def initialize(messaging) @messaging = messaging @jwt = @messaging.jwt end |
Instance Method Details
permalink #allow(id) ⇒ Object
Allows incomming messages from the given identity.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/acl.rb', line 21 def allow(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.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/acl.rb', line 35 def deny(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.
15 16 17 18 |
# File 'lib/acl.rb', line 15 def list SelfSDK.logger.info "Listing allowed connections" @messaging.list_acl_rules end |