selfsdk 0.0.216 → 0.0.217
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 +4 -4
- data/lib/messaging.rb +0 -29
- data/lib/selfsdk.rb +0 -1
- data/lib/services/messaging.rb +0 -35
- data/lib/services/requester.rb +0 -3
- metadata +1 -2
- data/lib/acl.rb +0 -67
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 6b46d28c22f1f2bc5580d68f247bec53aac495765ea0199e59e21ecefd6f29e9
         | 
| 4 | 
            +
              data.tar.gz: b0b84f89bdda28f94c2a81e56c71c420c480fe3b69e9425ab393e85e92a0e199
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 77173c08e398e75416d6711da44edc8a12062fae4dcf51e7b302dd9fab7fb8654af3904bd504aad7a980dd269fe6bd831453d005ec6352f7d60c0d08b754bb71
         | 
| 7 | 
            +
              data.tar.gz: c9c443f7570a352bcfd5c65250e7b6b7ca5b3c9bc0dd1017170186df0bf706aa227e74924a24427dfd350ff0f967e126fd55da1517e7e8a6c1d6541cd982a6b1
         | 
    
        data/lib/messaging.rb
    CHANGED
    
    | @@ -246,17 +246,6 @@ module SelfSDK | |
| 246 246 | 
             
                  end
         | 
| 247 247 | 
             
                end
         | 
| 248 248 |  | 
| 249 | 
            -
                # Sends a command to list ACL rules.
         | 
| 250 | 
            -
                def list_acl_rules
         | 
| 251 | 
            -
                  wait_for 'acl_list' do
         | 
| 252 | 
            -
                    a = SelfMsg::Acl.new
         | 
| 253 | 
            -
                    a.id = SecureRandom.uuid
         | 
| 254 | 
            -
                    a.command = SelfMsg::AclCommandLIST
         | 
| 255 | 
            -
             | 
| 256 | 
            -
                    @ws.send a
         | 
| 257 | 
            -
                  end
         | 
| 258 | 
            -
                end
         | 
| 259 | 
            -
             | 
| 260 249 | 
             
                # Sends a message and waits for the response
         | 
| 261 250 | 
             
                #
         | 
| 262 251 | 
             
                # @params msg [SelfMsg::Message] message object to be sent
         | 
| @@ -387,7 +376,6 @@ module SelfSDK | |
| 387 376 |  | 
| 388 377 | 
             
                private
         | 
| 389 378 |  | 
| 390 | 
            -
             | 
| 391 379 | 
             
                # Cleans expired messages
         | 
| 392 380 | 
             
                def clean_timeouts
         | 
| 393 381 | 
             
                  clean_observers
         | 
| @@ -413,7 +401,6 @@ module SelfSDK | |
| 413 401 | 
             
                  @ws.start
         | 
| 414 402 | 
             
                end
         | 
| 415 403 |  | 
| 416 | 
            -
             | 
| 417 404 | 
             
                # Process an event when it arrives through the websocket connection.
         | 
| 418 405 | 
             
                def on_message(event)
         | 
| 419 406 | 
             
                  data = event.data.pack('c*')
         | 
| @@ -438,27 +425,11 @@ module SelfSDK | |
| 438 425 | 
             
                    @messages[hdr.id][:response] = {error: e.error}
         | 
| 439 426 | 
             
                    mark_as_acknowledged(hdr.id)
         | 
| 440 427 | 
             
                    mark_as_arrived(hdr.id)
         | 
| 441 | 
            -
                  when SelfMsg::MsgTypeACL
         | 
| 442 | 
            -
                    SelfSDK.logger.debug "#{hdr.id} ACL received"
         | 
| 443 | 
            -
                    a = SelfMsg::Acl.new(data: data)
         | 
| 444 | 
            -
                    process_incomming_acl a
         | 
| 445 428 | 
             
                  end
         | 
| 446 429 | 
             
                rescue TypeError
         | 
| 447 430 | 
             
                  SelfSDK.logger.debug "invalid array message"
         | 
| 448 431 | 
             
                end
         | 
| 449 432 |  | 
| 450 | 
            -
                def process_incomming_acl(input)
         | 
| 451 | 
            -
                  list = JSON.parse(input.payload)
         | 
| 452 | 
            -
             | 
| 453 | 
            -
                  @messages['acl_list'][:response] = list
         | 
| 454 | 
            -
                  mark_as_arrived 'acl_list'
         | 
| 455 | 
            -
                rescue StandardError => e
         | 
| 456 | 
            -
                  p "Error processing incoming ACL #{input.id} #{input.payload}"
         | 
| 457 | 
            -
                  SelfSDK.logger.debug e
         | 
| 458 | 
            -
                  SelfSDK.logger.debug e.backtrace
         | 
| 459 | 
            -
                  nil
         | 
| 460 | 
            -
                end
         | 
| 461 | 
            -
             | 
| 462 433 | 
             
                def process_incomming_message(input)
         | 
| 463 434 | 
             
                  message = parse_and_write_offset(input)
         | 
| 464 435 |  | 
    
        data/lib/selfsdk.rb
    CHANGED
    
    
    
        data/lib/services/messaging.rb
    CHANGED
    
    | @@ -32,37 +32,6 @@ module SelfSDK | |
| 32 32 | 
             
                    @client.subscribe(type, &block)
         | 
| 33 33 | 
             
                  end
         | 
| 34 34 |  | 
| 35 | 
            -
                  # Permits incoming messages from the a identity.
         | 
| 36 | 
            -
                  #
         | 
| 37 | 
            -
                  # @param [String] selfid to be allowed.
         | 
| 38 | 
            -
                  # @return [Boolean] success / failure
         | 
| 39 | 
            -
                  def permit_connection(selfid)
         | 
| 40 | 
            -
                    acl.allow selfid
         | 
| 41 | 
            -
                  end
         | 
| 42 | 
            -
             | 
| 43 | 
            -
                  # Lists app allowed connections.
         | 
| 44 | 
            -
                  # @return [Array] array of self ids allowed to connect to your app.
         | 
| 45 | 
            -
                  def allowed_connections
         | 
| 46 | 
            -
                    acl.list
         | 
| 47 | 
            -
                  end
         | 
| 48 | 
            -
             | 
| 49 | 
            -
                  # Checks if you're permitting messages from a specific self identifier
         | 
| 50 | 
            -
                  # @return [Boolean] yes|no
         | 
| 51 | 
            -
                  def is_permitted?(id)
         | 
| 52 | 
            -
                    conns = allowed_connections
         | 
| 53 | 
            -
                    return true if conns.include? "*"
         | 
| 54 | 
            -
                    return true if conns.include? id
         | 
| 55 | 
            -
                    return false
         | 
| 56 | 
            -
                  end
         | 
| 57 | 
            -
             | 
| 58 | 
            -
                  # Revokes incoming messages from the given identity.
         | 
| 59 | 
            -
                  #
         | 
| 60 | 
            -
                  # @param [String] selfid to be denied
         | 
| 61 | 
            -
                  # @return [Boolean] success / failure
         | 
| 62 | 
            -
                  def revoke_connection(selfid)
         | 
| 63 | 
            -
                    acl.deny selfid
         | 
| 64 | 
            -
                  end
         | 
| 65 | 
            -
             | 
| 66 35 | 
             
                  # Gets the device id for the authenticated app.
         | 
| 67 36 | 
             
                  #
         | 
| 68 37 | 
             
                  # @return [String] device_id of the running app.
         | 
| @@ -101,10 +70,6 @@ module SelfSDK | |
| 101 70 | 
             
                  end
         | 
| 102 71 |  | 
| 103 72 | 
             
                  private
         | 
| 104 | 
            -
             | 
| 105 | 
            -
                  def acl
         | 
| 106 | 
            -
                    @acl ||= ACL.new(@client)
         | 
| 107 | 
            -
                  end
         | 
| 108 73 | 
             
                end
         | 
| 109 74 | 
             
              end
         | 
| 110 75 | 
             
            end
         | 
    
        data/lib/services/requester.rb
    CHANGED
    
    | @@ -48,9 +48,6 @@ module SelfSDK | |
| 48 48 | 
             
                  def request(selfid, facts, opts = {}, &block)
         | 
| 49 49 | 
             
                    SelfSDK.logger.info "authenticating #{selfid}"
         | 
| 50 50 | 
             
                    rq = opts.fetch(:request, true)
         | 
| 51 | 
            -
                    if rq
         | 
| 52 | 
            -
                      raise "You're not permitting connections from #{selfid}" unless @messaging_service.is_permitted?(selfid)
         | 
| 53 | 
            -
                    end
         | 
| 54 51 |  | 
| 55 52 | 
             
                    req = SelfSDK::Messages::FactRequest.new(@messaging)
         | 
| 56 53 | 
             
                    req.populate(selfid, prepare_facts(facts), opts)
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: selfsdk
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.217
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Self Group Ltd.
         | 
| @@ -350,7 +350,6 @@ executables: [] | |
| 350 350 | 
             
            extensions: []
         | 
| 351 351 | 
             
            extra_rdoc_files: []
         | 
| 352 352 | 
             
            files:
         | 
| 353 | 
            -
            - lib/acl.rb
         | 
| 354 353 | 
             
            - lib/authenticated.rb
         | 
| 355 354 | 
             
            - lib/chat/file_object.rb
         | 
| 356 355 | 
             
            - lib/chat/group.rb
         | 
    
        data/lib/acl.rb
    DELETED
    
    | @@ -1,67 +0,0 @@ | |
| 1 | 
            -
            # Copyright 2020 Self Group Ltd. All Rights Reserved.
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            # frozen_string_literal: true
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            require 'date'
         | 
| 6 | 
            -
             | 
| 7 | 
            -
            # Namespace for classes and modules that handle Self interactions.
         | 
| 8 | 
            -
            module SelfSDK
         | 
| 9 | 
            -
              # Access control list
         | 
| 10 | 
            -
              class ACL
         | 
| 11 | 
            -
                def initialize(messaging)
         | 
| 12 | 
            -
                  @messaging = messaging
         | 
| 13 | 
            -
                  @jwt = @messaging.jwt
         | 
| 14 | 
            -
                  @acl_rules = []
         | 
| 15 | 
            -
                end
         | 
| 16 | 
            -
             | 
| 17 | 
            -
                # Lists allowed connections.
         | 
| 18 | 
            -
                def list
         | 
| 19 | 
            -
                  SelfSDK.logger.info "Listing allowed connections"
         | 
| 20 | 
            -
                  @acl_rules = @messaging.list_acl_rules if @acl_rules.empty?
         | 
| 21 | 
            -
                  @acl_rules
         | 
| 22 | 
            -
                end
         | 
| 23 | 
            -
             | 
| 24 | 
            -
                # Allows incomming messages from the given identity.
         | 
| 25 | 
            -
                def allow(id)
         | 
| 26 | 
            -
                  @acl_rules << id
         | 
| 27 | 
            -
                  SelfSDK.logger.info "Allowing connections from #{id}"
         | 
| 28 | 
            -
                  payload = @jwt.prepare(jti: SecureRandom.uuid,
         | 
| 29 | 
            -
                                         cid: SecureRandom.uuid,
         | 
| 30 | 
            -
                                         typ: 'acl.permit',
         | 
| 31 | 
            -
                                         iss: @jwt.id,
         | 
| 32 | 
            -
                                         sub: @jwt.id,
         | 
| 33 | 
            -
                                         iat: (SelfSDK::Time.now - 5).strftime('%FT%TZ'),
         | 
| 34 | 
            -
                                         exp: (SelfSDK::Time.now + 60).strftime('%FT%TZ'),
         | 
| 35 | 
            -
                                         acl_source: id,
         | 
| 36 | 
            -
                                         acl_exp: (SelfSDK::Time.now + 360_000).to_datetime.rfc3339)
         | 
| 37 | 
            -
             | 
| 38 | 
            -
                  a = SelfMsg::Acl.new
         | 
| 39 | 
            -
                  a.id = SecureRandom.uuid
         | 
| 40 | 
            -
                  a.command = SelfMsg::AclCommandPERMIT
         | 
| 41 | 
            -
                  a.payload = payload
         | 
| 42 | 
            -
             | 
| 43 | 
            -
                  @messaging.send_message a
         | 
| 44 | 
            -
                end
         | 
| 45 | 
            -
             | 
| 46 | 
            -
                # Deny incomming messages from the given identity.
         | 
| 47 | 
            -
                def deny(id)
         | 
| 48 | 
            -
                  @acl_rules.delete(id)
         | 
| 49 | 
            -
                  SelfSDK.logger.info "Denying connections from #{id}"
         | 
| 50 | 
            -
                  payload = @jwt.prepare(jti: SecureRandom.uuid,
         | 
| 51 | 
            -
                                         cid: SecureRandom.uuid,
         | 
| 52 | 
            -
                                         typ: 'acl.revoke',
         | 
| 53 | 
            -
                                         iss: @jwt.id,
         | 
| 54 | 
            -
                                         sub: @jwt.id,
         | 
| 55 | 
            -
                                         iat: (SelfSDK::Time.now - 5).strftime('%FT%TZ'),
         | 
| 56 | 
            -
                                         exp: (SelfSDK::Time.now + 60).strftime('%FT%TZ'),
         | 
| 57 | 
            -
                                         acl_source: id,
         | 
| 58 | 
            -
                                         acl_exp: (SelfSDK::Time.now + 360_000).to_datetime.rfc3339)
         | 
| 59 | 
            -
             | 
| 60 | 
            -
                  a = SelfMsg::Acl.new
         | 
| 61 | 
            -
                  a.id = SecureRandom.uuid
         | 
| 62 | 
            -
                  a.command = SelfMsg::AclCommandREVOKE
         | 
| 63 | 
            -
                  a.payload = payload
         | 
| 64 | 
            -
                  @messaging.send_message a
         | 
| 65 | 
            -
                end
         | 
| 66 | 
            -
              end
         | 
| 67 | 
            -
            end
         |