anycable-core 1.4.0.rc.1 → 1.4.0.rc.2
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/CHANGELOG.md +4 -0
- data/lib/anycable/config.rb +6 -0
- data/lib/anycable/httrpc/server.rb +58 -0
- data/lib/anycable/rpc/handler.rb +4 -0
- data/lib/anycable/version.rb +1 -1
- data/lib/anycable.rb +2 -0
- data/sig/anycable/config.rbs +2 -0
- data/sig/anycable/httrpc/server.rbs +11 -0
- data/sig/anycable/rpc/handler.rbs +1 -0
- data/sig/anycable/rpc.rbs +8 -0
- metadata +4 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 25b7f4021fa0e158fbd28f5213545756750ab8222ed43c25e770bb4031083f9e
         | 
| 4 | 
            +
              data.tar.gz: a2f5760a88c80ed483d1de2b953558f2ac4f66b71d55a2e1745b52f1ce359f3d
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: f18b8269a526c7cebedcd0146f12a3dc43e1aa3c0af23e3bbe147f632758bfc1b3102e972f6416b1a1b7228cfcc9a9c8f90ba1b22a0d173a8f46ce392777d93f
         | 
| 7 | 
            +
              data.tar.gz: 36a767ee9034deefbecc0696843e65c1c1773ce8e58cf5898a4a4fd4bd44784fbf7cd8a4a7ba5d6bcb84767b1466df465d8c26b2ac634aaa55aa311f2e84734b
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/lib/anycable/config.rb
    CHANGED
    
    | @@ -53,6 +53,9 @@ module AnyCable | |
| 53 53 | 
             
                  http_health_port: nil,
         | 
| 54 54 | 
             
                  http_health_path: "/health",
         | 
| 55 55 |  | 
| 56 | 
            +
                  ### HTTP RPC options
         | 
| 57 | 
            +
                  http_rpc_secret: nil,
         | 
| 58 | 
            +
             | 
| 56 59 | 
             
                  ### Misc options
         | 
| 57 60 | 
             
                  version_check_enabled: true,
         | 
| 58 61 | 
             
                  sid_header_enabled: true
         | 
| @@ -110,6 +113,9 @@ module AnyCable | |
| 110 113 | 
             
                  HTTP PUB/SUB
         | 
| 111 114 | 
             
                      --http-broadcast-url              HTTP pub/sub endpoint URL, default: "http://localhost:8090/_broadcast"
         | 
| 112 115 | 
             
                      --http-broadcast-secret           HTTP pub/sub authorization secret, default: <none> (disabled)
         | 
| 116 | 
            +
             | 
| 117 | 
            +
                  HTTP RPC
         | 
| 118 | 
            +
                      --http-rpc-secret                 HTTP RPC authorization secret, default: <none> (disabled)
         | 
| 113 119 | 
             
                TXT
         | 
| 114 120 |  | 
| 115 121 | 
             
                # Build Redis parameters
         | 
| @@ -0,0 +1,58 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module AnyCable
         | 
| 4 | 
            +
              module HTTRPC
         | 
| 5 | 
            +
                class Server
         | 
| 6 | 
            +
                  def initialize(token: AnyCable.config.http_rpc_secret)
         | 
| 7 | 
            +
                    @token = token
         | 
| 8 | 
            +
                  end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  def call(env)
         | 
| 11 | 
            +
                    if env["REQUEST_METHOD"] != "POST"
         | 
| 12 | 
            +
                      return [404, {}, ["Not found"]]
         | 
| 13 | 
            +
                    end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                    if token && env["HTTP_AUTHORIZATION"] != "Bearer #{token}"
         | 
| 16 | 
            +
                      return [401, {}, ["Unauthorized"]]
         | 
| 17 | 
            +
                    end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                    rpc_command = env["PATH_INFO"].sub(%r{^/}, "").to_sym
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                    # check if command is supported and return 404 if not
         | 
| 22 | 
            +
                    return [404, {}, ["Not found"]] unless AnyCable.rpc_handler.supported?(rpc_command)
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                    # read request body and it's empty, return 422
         | 
| 25 | 
            +
                    request_body = env["rack.input"].read
         | 
| 26 | 
            +
                    return [422, {}, ["Empty request body"]] if request_body.empty?
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                    payload =
         | 
| 29 | 
            +
                      case rpc_command
         | 
| 30 | 
            +
                      when :connect then AnyCable::ConnectionRequest.decode_json(request_body)
         | 
| 31 | 
            +
                      when :disconnect then AnyCable::DisconnectRequest.decode_json(request_body)
         | 
| 32 | 
            +
                      when :command then AnyCable::CommandMessage.decode_json(request_body)
         | 
| 33 | 
            +
                      end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                    return [422, {}, ["Invalid request body"]] if payload.nil?
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                    response = AnyCable.rpc_handler.handle(rpc_command, payload, build_meta(env))
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                    [200, {}, [response.to_json({format_enums_as_integers: true})]]
         | 
| 40 | 
            +
                  rescue JSON::ParserError, ArgumentError => e
         | 
| 41 | 
            +
                    [422, {}, ["Invalid request body: #{e.message}"]]
         | 
| 42 | 
            +
                  end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                  private
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                  attr_reader :token
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                  def build_meta(env)
         | 
| 49 | 
            +
                    # `x-anycable-meta-var` -> `meta["var"]`
         | 
| 50 | 
            +
                    env.each_with_object({}) do |(k, v), meta|
         | 
| 51 | 
            +
                      next unless k.start_with?("HTTP_X_ANYCABLE_META_")
         | 
| 52 | 
            +
                      meta[k.sub(%r{^HTTP_X_ANYCABLE_META_}, "").downcase] = v
         | 
| 53 | 
            +
                      meta
         | 
| 54 | 
            +
                    end
         | 
| 55 | 
            +
                  end
         | 
| 56 | 
            +
                end
         | 
| 57 | 
            +
              end
         | 
| 58 | 
            +
            end
         | 
    
        data/lib/anycable/rpc/handler.rb
    CHANGED
    
    
    
        data/lib/anycable/version.rb
    CHANGED
    
    
    
        data/lib/anycable.rb
    CHANGED
    
    
    
        data/sig/anycable/config.rbs
    CHANGED
    
    | @@ -41,6 +41,8 @@ module AnyCable | |
| 41 41 | 
             
                def http_health_port=: (Integer) -> void
         | 
| 42 42 | 
             
                def http_health_path: () -> String
         | 
| 43 43 | 
             
                def http_health_path=: (String) -> void
         | 
| 44 | 
            +
                def http_rpc_secret: () -> String
         | 
| 45 | 
            +
                def http_rpc_secret=: (String) -> void
         | 
| 44 46 | 
             
                def version_check_enabled: () -> bool
         | 
| 45 47 | 
             
                def version_check_enabled=: (bool) -> void
         | 
| 46 48 | 
             
                def version_check_enabled?: () -> bool
         | 
| @@ -0,0 +1,11 @@ | |
| 1 | 
            +
            module AnyCable
         | 
| 2 | 
            +
              module HTTRPC
         | 
| 3 | 
            +
                class Server
         | 
| 4 | 
            +
                  def initialize: (?token: String?) -> void
         | 
| 5 | 
            +
                  def call: (Hash[String, untyped] env) -> [Integer, Hash[String, String], Array[String]]
         | 
| 6 | 
            +
                  private
         | 
| 7 | 
            +
                  attr_reader token: String?
         | 
| 8 | 
            +
                  def build_meta: (Hash[String, untyped] env) -> Hash[String, String]
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
            end
         | 
    
        data/sig/anycable/rpc.rbs
    CHANGED
    
    | @@ -73,6 +73,7 @@ module AnyCable | |
| 73 73 | 
             
              class ConnectionRequest
         | 
| 74 74 | 
             
                include _WithEnv
         | 
| 75 75 |  | 
| 76 | 
            +
                def self.decode_json: (String) -> instance
         | 
| 76 77 | 
             
                %a{rbs:test:skip} def initialize: (?env: Env) -> void
         | 
| 77 78 | 
             
                def to_h: () -> Hash[Symbol, untyped]
         | 
| 78 79 | 
             
              end
         | 
| @@ -95,11 +96,14 @@ module AnyCable | |
| 95 96 | 
             
                ) -> void
         | 
| 96 97 |  | 
| 97 98 | 
             
                def to_h: () -> Hash[Symbol, untyped]
         | 
| 99 | 
            +
                def to_json: (?Hash[Symbol, untyped] options) -> String
         | 
| 98 100 | 
             
              end
         | 
| 99 101 |  | 
| 100 102 | 
             
              class CommandMessage
         | 
| 101 103 | 
             
                include _WithEnv
         | 
| 102 104 |  | 
| 105 | 
            +
                def self.decode_json: (String) -> instance
         | 
| 106 | 
            +
             | 
| 103 107 | 
             
                attr_accessor command: String
         | 
| 104 108 | 
             
                attr_accessor identifier: String
         | 
| 105 109 | 
             
                attr_accessor connection_identifiers: String
         | 
| @@ -139,11 +143,14 @@ module AnyCable | |
| 139 143 | 
             
                ) -> void
         | 
| 140 144 |  | 
| 141 145 | 
             
                def to_h: () -> Hash[Symbol, untyped]
         | 
| 146 | 
            +
                def to_json: (?Hash[Symbol, untyped] options) -> String
         | 
| 142 147 | 
             
              end
         | 
| 143 148 |  | 
| 144 149 | 
             
              class DisconnectRequest
         | 
| 145 150 | 
             
                include _WithEnv
         | 
| 146 151 |  | 
| 152 | 
            +
                def self.decode_json: (String) -> instance
         | 
| 153 | 
            +
             | 
| 147 154 | 
             
                attr_accessor identifiers: String
         | 
| 148 155 | 
             
                attr_accessor subscriptions: Array[String]
         | 
| 149 156 |  | 
| @@ -159,6 +166,7 @@ module AnyCable | |
| 159 166 |  | 
| 160 167 | 
             
                %a{rbs:test:skip} def initialize: (status: rpcStatus, ?error_msg: String) -> void
         | 
| 161 168 | 
             
                def to_h: () -> Hash[Symbol, untyped]
         | 
| 169 | 
            +
                def to_json: (?Hash[Symbol, untyped] options) -> String
         | 
| 162 170 | 
             
              end
         | 
| 163 171 |  | 
| 164 172 | 
             
              type rpcRequest = ConnectionRequest | DisconnectRequest | CommandMessage
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: anycable-core
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.4.0.rc. | 
| 4 | 
            +
              version: 1.4.0.rc.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - palkan
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2023- | 
| 11 | 
            +
            date: 2023-07-04 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: anyway_config
         | 
| @@ -216,6 +216,7 @@ files: | |
| 216 216 | 
             
            - lib/anycable/grpc_kit/health_services_pb.rb
         | 
| 217 217 | 
             
            - lib/anycable/grpc_kit/server.rb
         | 
| 218 218 | 
             
            - lib/anycable/health_server.rb
         | 
| 219 | 
            +
            - lib/anycable/httrpc/server.rb
         | 
| 219 220 | 
             
            - lib/anycable/middleware.rb
         | 
| 220 221 | 
             
            - lib/anycable/middleware_chain.rb
         | 
| 221 222 | 
             
            - lib/anycable/middlewares/check_version.rb
         | 
| @@ -246,6 +247,7 @@ files: | |
| 246 247 | 
             
            - sig/anycable/grpc/rpc_services_pb.rbs
         | 
| 247 248 | 
             
            - sig/anycable/grpc/server.rbs
         | 
| 248 249 | 
             
            - sig/anycable/health_server.rbs
         | 
| 250 | 
            +
            - sig/anycable/httrpc/server.rbs
         | 
| 249 251 | 
             
            - sig/anycable/middleware.rbs
         | 
| 250 252 | 
             
            - sig/anycable/middleware_chain.rbs
         | 
| 251 253 | 
             
            - sig/anycable/middlewares/check_version.rbs
         |