Class: SelfSDK::ACL

Inherits:
Object
  • Object
show all
Defined in:
lib/acl.rb

Overview

Access control list

Instance Method Summary collapse

Constructor Details

#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

#allow(id) ⇒ Object

Allows incomming messages from the given identity.



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/acl.rb', line 25

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

#deny(id) ⇒ Object

Deny incomming messages from the given identity.



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/acl.rb', line 39

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

#listObject

Lists allowed connections.



15
16
17
18
19
20
21
22
# File 'lib/acl.rb', line 15

def list
  SelfSDK.logger.info "Listing allowed connections"
  rules = {}
  @messaging.list_acl_rules.each do |c|
    rules[c['acl_source']] = DateTime.parse(c['acl_exp'])
  end
  rules
end