connectrpc-health 0.1.2 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f9d3081aa61a18bd5eee848e4b4ece3c169e84311f46f6c58aa0be14e22ad3d7
4
- data.tar.gz: 95e1b23caeeebeb31e8535fd33e9a5832b280ab6f0fda6af8d7936213a09fb52
3
+ metadata.gz: 8142b2b651a0b3a032b54f8d80fac8e38bbfbfee019771fc1bf98ef0ad1aba5a
4
+ data.tar.gz: 10fc6a3480781fd87bfcbf2a1fd89024948e03fa17b6a516b1068b4a9383acf4
5
5
  SHA512:
6
- metadata.gz: d159fe31f974b6c7b9f1394412ea386eb1821fc187aab47882669f3453b5def99174f6a505b7357bae5bcb603774d5abbae89a023d8bc964de5a7ddcb62e2b36
7
- data.tar.gz: d0a794e6819764f98701608afafb3e0e16e5d964837b69ce733dab932216fc1834ca1a6c8d6a57e168e96a9e3dd85f0eed9bad3ff7a9989fbc1cef7f2b876bc5
6
+ metadata.gz: 783b22bc18dd0df6cbdef401887fcfabe8b719a221f5df7245939244ae6de6a870b746461d893b1f7cdf12f9853a40f2b8aa3605187fed20cf72ea6a66f2300f
7
+ data.tar.gz: fcc050a134e3d5afa5d20b10e2f6b2a6a38915397e15694ca65d40deb46dada8eb6b5ae60b8ab937bc4a5fbba4322b3e260fb89c19bd3100c351bbe54d9109d7
data/README.md CHANGED
@@ -27,10 +27,10 @@ and adoption gates.
27
27
  ## Installation
28
28
 
29
29
  ```ruby
30
- gem "connectrpc-health", "~> 0.1.0"
30
+ gem "connectrpc-health", "~> 0.2.0"
31
31
  ```
32
32
 
33
- The runtime dependencies are `connectrpc ~> 0.1.0` and
33
+ The runtime dependencies are `connectrpc ~> 0.2.0` and
34
34
  `google-protobuf >= 4.36.2, < 5`. Core and the hosting packages do not depend
35
35
  on this package.
36
36
 
@@ -110,20 +110,38 @@ worker-local. Set statuses inside each worker, for example while building
110
110
 
111
111
  ### Authentication
112
112
 
113
- `invoker:` covers unary calls only; Watch bypasses it. To expose health behind
114
- authentication, wrap the handlers so a denied call fails before it reaches the
115
- registry. A denied Watch then reveals no status and allocates no watcher:
113
+ Server [interceptors](../../docs/unary.md#interceptors) on the application's
114
+ `Server` cover Check and List through `server_unary` and Watch through
115
+ `server_stream`. To expose health behind authentication, reject before `yield`
116
+ so a denied call never reaches the registry. A denied Watch then reveals no
117
+ status and allocates no watcher. `invoker:` is not enough: it covers unary
118
+ calls only, and Watch bypasses it.
116
119
 
117
120
  ```ruby
118
- guarded = health.handlers.to_h do |path, handler|
119
- [path, lambda do |*arguments, context|
120
- raise ConnectRPC::Error.new(:unauthenticated, "credentials required") unless authorized?(context)
121
+ class HealthAuth
122
+ def server_unary(call, &) = authorize!(call, &)
123
+ def server_stream(call, &) = authorize!(call, &)
121
124
 
122
- handler.call(*arguments, context)
123
- end]
125
+ private
126
+
127
+ # authorized?(context) is the application's own check, for example of a
128
+ # credential in context.request_metadata.
129
+ def authorize!(call)
130
+ if call.method.service == ConnectRPC::Health::SERVICE.name && !authorized?(call.context)
131
+ raise ConnectRPC::Error.new(:unauthenticated, "credentials required")
132
+ end
133
+
134
+ yield
135
+ end
124
136
  end
137
+
138
+ server = ConnectRPC::Server.new(services: services, handlers: handlers, binding: binding,
139
+ protocol: :auto, interceptors: [HealthAuth.new])
125
140
  ```
126
141
 
142
+ An interceptor's `server_stream` frame, and anything it holds, lasts as long as
143
+ the Watch stream. Avoid holding scarce resources across `yield`.
144
+
127
145
  ## Shutdown and drain
128
146
 
129
147
  Call `health.shutdown` before `host.close(grace:)`. Every entry becomes
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ConnectRPC
4
4
  module Health
5
- VERSION = "0.1.2" # x-release-please-version
5
+ VERSION = "0.2.0" # x-release-please-version
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: connectrpc-health
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jimeh
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: 0.1.0
18
+ version: 0.2.0
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: 0.1.0
25
+ version: 0.2.0
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: google-protobuf
28
28
  requirement: !ruby/object:Gem::Requirement