neo4j_bolt 0.4.3 → 0.4.4

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: 38ed2e6727f1bc4baccc838b195d72a2392bbb82788598d704a1e81bd0f20de0
4
- data.tar.gz: d781a67c3eee09dd9e32a9af60fe1fb65a61bb8afddb96307dd897cbcd99ddf1
3
+ metadata.gz: e6322e3f763f052647f81029aaa96e45d6cb6f41a8e8d625c198d025b1408a81
4
+ data.tar.gz: ddf55ab34e93f5b65b36273a2c148037f4455e18252aba692296e52598668902
5
5
  SHA512:
6
- metadata.gz: e1d4c318c5adb68878da6368dc8d694a63c79cc953ab0e87ffe5aceaf77ce9d47d06b35a80cef8ea835ac90e6753974a59c2bb2bd9088f144fdf8761976b9b8a
7
- data.tar.gz: d28fd8341cbbfe89391c7685331ed8fc666864edb7222f8ccb3530ddd3e93b2bad68d9fa6ebdf75049cad99c8d68926b356e3b55fadcb795e017dfc0be9d0f22
6
+ metadata.gz: bff514f49ee709624ac1b178e2216edd001ad168845c397aff2f9d28a3d3752a4c3fcbf0d7f9ea4bc6c0a1f68ffd6feef8fae560127774c0aa0277a4d6cf6ffd
7
+ data.tar.gz: d5ef2dbebc19f6f1538ee461993ec20a9184b734ba4b490ca6a941f4de7b2cb526f22ad59daa9f8578afee00f0be25728c16eed29f6ddfab1a581901b8eabb42
data/README.md CHANGED
@@ -4,14 +4,14 @@ Neo4jBolt 0.4 is a small compatibility and convenience layer for Ruby applicatio
4
4
 
5
5
  Neo4jBolt no longer implements the Bolt wire protocol itself.
6
6
 
7
- `0.4.0` requires Ruby 3.4 or newer and pins `neo4j-ruby-driver` to `6.2.1.beta.4`. Applications on older Rubies can remain on the Neo4jBolt 0.3.x line; this prerelease is intentionally not an automatic upgrade for them.
7
+ `0.4.4` requires Ruby 3.4 or newer and pins `neo4j-ruby-driver` to `6.2.1.beta.4`. Applications on older Rubies can remain on the Neo4jBolt 0.3.x line; this prerelease is intentionally not an automatic upgrade for them.
8
8
 
9
9
  ## Installation
10
10
 
11
11
  For this prerelease, specify the version explicitly:
12
12
 
13
13
  ```ruby
14
- gem "neo4j_bolt", "0.4.0"
14
+ gem "neo4j_bolt", "0.4.4"
15
15
  ```
16
16
 
17
17
  Then run `bundle install`. A running Neo4j database is required.
@@ -26,6 +26,24 @@ Neo4jBolt.bolt_port = 7687
26
26
  Neo4jBolt.bolt_verbosity = 0
27
27
  ```
28
28
 
29
+ Authentication and database selection can use the standard Neo4j client environment variables:
30
+
31
+ ```bash
32
+ export NEO4J_USERNAME=neo4j
33
+ export NEO4J_PASSWORD=secret
34
+ export NEO4J_DATABASE=neo4j
35
+ ```
36
+
37
+ They are read when `neo4j_bolt` is loaded. Explicit Ruby configuration overrides those defaults:
38
+
39
+ ```ruby
40
+ Neo4jBolt.bolt_username = "neo4j"
41
+ Neo4jBolt.bolt_password = "secret"
42
+ Neo4jBolt.bolt_database = "movies"
43
+ ```
44
+
45
+ If both username and password are unset, Neo4jBolt keeps the existing unauthenticated connection behavior. If only one is set, the first query raises `Neo4jBolt::Error`. Leaving the database unset lets Neo4j choose the user's/server's default database.
46
+
29
47
  Applications can include the module as before:
30
48
 
31
49
  ```ruby
@@ -36,7 +54,7 @@ They can also extend another object or call the convenience methods directly on
36
54
 
37
55
  One lazily initialized upstream driver owns a thread-safe connection pool. Each standalone query uses a short-lived session and returns its connection to that pool after its result has been consumed. Queries from several Puma threads are not globally serialized.
38
56
 
39
- `cleanup_neo4j` safely retires the driver and its pool after active operations finish. A later query creates a new driver. Do not call cleanup from inside an active query or transaction on the same thread.
57
+ `cleanup_neo4j` safely retires the driver and its pool after active operations finish. A later query creates a new driver. Changing host, port, username, or password also retires the pool so later connections use the new settings. Database selection is a session setting and therefore applies to newly opened sessions without rebuilding the driver. Do not call cleanup from inside an active query or transaction on the same thread.
40
58
 
41
59
  ## Running queries
42
60
 
@@ -188,7 +206,7 @@ The `neo4j_bolt` executable retains these commands:
188
206
  | `neo4j_bolt index rm --force` | Remove all constraints and indexes |
189
207
  | `neo4j_bolt visualize` | Generate a GraphViz document |
190
208
 
191
- Use `--host HOST:PORT` to select a server. `gli` remains a runtime dependency for the CLI, and `pry` remains for the separate `bin/console` executable.
209
+ Use `--host HOST:PORT`, `--username USER`, `--password PASSWORD`, and `--database DATABASE` to override connection settings. Username, password, and database otherwise inherit `NEO4J_USERNAME`, `NEO4J_PASSWORD`, and `NEO4J_DATABASE`. Prefer the password environment variable for routine use because command-line arguments may be visible in shell history or process listings. `gli` remains a runtime dependency for the CLI, and `pry` remains for the separate `bin/console` executable.
192
210
 
193
211
  ## Tested Neo4j versions
194
212
 
@@ -198,7 +216,7 @@ The same complete integration suite is run against these exact Community images:
198
216
  - `neo4j:5.26.28-community`
199
217
  - `neo4j:2026.06.0-community`
200
218
 
201
- No compatibility beyond this matrix is claimed for `0.4.0`.
219
+ No compatibility beyond this matrix is claimed for `0.4.4`.
202
220
 
203
221
  Run one modern LTS target:
204
222
 
@@ -212,15 +230,16 @@ Run the complete sequential matrix:
212
230
  bundle exec rake spec:matrix
213
231
  ```
214
232
 
215
- The harness creates uniquely named disposable containers with `NEO4J_AUTH=none`, dynamically publishes Bolt ports, waits by establishing a real driver/query connection, and cleans every container through shell traps. A developer does not need to start Neo4j manually.
233
+ The harness creates uniquely named disposable containers with Basic authentication enabled, dynamically publishes Bolt ports, waits by establishing a real driver/query connection, and cleans every container through shell traps. A developer does not need to start Neo4j manually.
216
234
 
217
- To point RSpec itself at an already disposable database, set `NEO4J_BOLT_TEST_HOST` and `NEO4J_BOLT_TEST_PORT`. The explicit port requirement protects real databases from the destructive integration suite.
235
+ To point RSpec itself at an already disposable database, set `NEO4J_BOLT_TEST_HOST` and `NEO4J_BOLT_TEST_PORT`. If it requires authentication or an explicit database, also set `NEO4J_USERNAME`, `NEO4J_PASSWORD`, and `NEO4J_DATABASE`. The explicit port requirement protects real databases from the destructive integration suite.
218
236
 
219
237
  ## Compatibility inventory for 0.4
220
238
 
221
239
  | API | Status |
222
240
  | --- | --- |
223
241
  | `bolt_host`, `bolt_port`, `bolt_verbosity` | Preserved |
242
+ | `bolt_username`, `bolt_password`, `bolt_database` | Additive authentication/database configuration |
224
243
  | Included/extended/module-style use | Preserved |
225
244
  | `neo4j_query`, including incremental block form | Preserved via adapter |
226
245
  | `neo4j_query_expect_one` | Preserved via adapter |
@@ -235,12 +254,13 @@ To point RSpec itself at an already disposable database, set `NEO4J_BOLT_TEST_HO
235
254
  | CLI commands | Preserved |
236
255
  | `BoltSocket`, `BoltBuffer`, protocol markers/state/parser/packer | Intentionally removed private implementation details |
237
256
 
238
- ## 0.4.0 migration notes
257
+ ## 0.4.4 migration notes
239
258
 
240
259
  - Ruby 3.4 or newer is required; Ruby 2.x/3.0–3.3 applications should stay on 0.3.x until upgraded.
241
260
  - The exact prerelease upstream dependency is pinned while no stable `neo4j-ruby-driver` 6.2.x exists.
242
261
  - Connections are pooled and safe for concurrent use instead of one mutable socket per including object.
243
- - TLS, routing, authentication, database selection, and other upstream-driver configuration are not newly exposed through the legacy three-setting API in this compatibility prerelease.
262
+ - Basic authentication and database selection are now exposed through `bolt_username`, `bolt_password`, and `bolt_database`, with `NEO4J_USERNAME`, `NEO4J_PASSWORD`, and `NEO4J_DATABASE` as environment defaults.
263
+ - TLS, routing, URI schemes, and other upstream-driver configuration are still not exposed through the compatibility API.
244
264
  - `BoltSocket`, `BoltBuffer`, `ServerState`, `BoltMarker`, `UnexpectedServerResponse`, `State`, and `CypherError` were undocumented wire internals and are removed.
245
265
 
246
266
  ## Development
data/bin/neo4j_bolt CHANGED
@@ -22,12 +22,18 @@ class App
22
22
 
23
23
  flag [:v, :verbosity], :default_value => 0
24
24
  flag [:h, :host], :default_value => 'localhost:7687'
25
+ flag [:u, :username], :default_value => nil, :desc => 'Neo4j username (default: NEO4J_USERNAME)'
26
+ flag [:p, :password], :default_value => nil, :desc => 'Neo4j password (default: NEO4J_PASSWORD)'
27
+ flag [:d, :database], :default_value => nil, :desc => 'Neo4j database (default: NEO4J_DATABASE)'
25
28
 
26
29
  pre do |global_options, command, options, args|
27
30
  host = global_options[:host]
28
31
  Neo4jBolt.bolt_host = host.split(':').first
29
32
  Neo4jBolt.bolt_port = host.split(':').last.to_i
30
33
  Neo4jBolt.bolt_verbosity = global_options[:verbosity].to_i
34
+ Neo4jBolt.bolt_username = global_options[:username] unless global_options[:username].nil?
35
+ Neo4jBolt.bolt_password = global_options[:password] unless global_options[:password].nil?
36
+ Neo4jBolt.bolt_database = global_options[:database] unless global_options[:database].nil?
31
37
  true
32
38
  end
33
39
 
@@ -1,3 +1,3 @@
1
1
  module Neo4jBolt
2
- VERSION = "0.4.3"
2
+ VERSION = "0.4.4"
3
3
  end
data/lib/neo4j_bolt.rb CHANGED
@@ -335,10 +335,22 @@ module Neo4jBolt
335
335
  host = "[#{host}]" if host.include?(":") && !host.start_with?("[")
336
336
  Neo4j::Driver::GraphDatabase.driver(
337
337
  "bolt://#{host}:#{Neo4jBolt.bolt_port}",
338
- Neo4j::Driver::AuthTokens.none
338
+ authentication_token
339
339
  )
340
340
  end
341
341
 
342
+ def authentication_token
343
+ username = Neo4jBolt.bolt_username
344
+ password = Neo4jBolt.bolt_password
345
+ return Neo4j::Driver::AuthTokens.none if username.nil? && password.nil?
346
+
347
+ if username.nil? || password.nil?
348
+ raise Error, "Neo4j username and password must either both be set or both be unset"
349
+ end
350
+
351
+ Neo4j::Driver::AuthTokens.basic(username, password)
352
+ end
353
+
342
354
  def leases
343
355
  @leases ||= 0
344
356
  end
@@ -354,8 +366,8 @@ module Neo4jBolt
354
366
  end
355
367
 
356
368
  class << self
357
- attr_reader :bolt_host, :bolt_port
358
- attr_accessor :bolt_verbosity
369
+ attr_reader :bolt_host, :bolt_port, :bolt_username, :bolt_password
370
+ attr_accessor :bolt_verbosity, :bolt_database
359
371
 
360
372
  def bolt_host=(host)
361
373
  reconfigure_driver if defined?(@bolt_host) && @bolt_host != host
@@ -367,6 +379,16 @@ module Neo4jBolt
367
379
  @bolt_port = port
368
380
  end
369
381
 
382
+ def bolt_username=(username)
383
+ reconfigure_driver if defined?(@bolt_username) && @bolt_username != username
384
+ @bolt_username = username
385
+ end
386
+
387
+ def bolt_password=(password)
388
+ reconfigure_driver if defined?(@bolt_password) && @bolt_password != password
389
+ @bolt_password = password
390
+ end
391
+
370
392
  private
371
393
 
372
394
  def reconfigure_driver
@@ -377,10 +399,23 @@ module Neo4jBolt
377
399
  self.bolt_host = "localhost"
378
400
  self.bolt_port = 7687
379
401
  self.bolt_verbosity = 0
402
+ self.bolt_username = ENV["NEO4J_USERNAME"]
403
+ self.bolt_password = ENV["NEO4J_PASSWORD"]
404
+ self.bolt_database = ENV["NEO4J_DATABASE"]
380
405
 
381
406
  # Keep both `include Neo4jBolt` and direct module-style calls working.
382
407
  extend self
383
408
 
409
+ def with_session(driver)
410
+ database = Neo4jBolt.bolt_database
411
+ if database.nil?
412
+ driver.session { |session| yield session }
413
+ else
414
+ driver.session(database: database) { |session| yield session }
415
+ end
416
+ end
417
+ private :with_session
418
+
384
419
  def neo4j_query(query, data = {}, &block)
385
420
  validate_parameters!(data)
386
421
  log_query(query, data)
@@ -390,7 +425,7 @@ module Neo4jBolt
390
425
  run_and_convert(context.transaction, query, data, &block)
391
426
  else
392
427
  DriverRegistry.with_driver do |driver|
393
- driver.session do |session|
428
+ with_session(driver) do |session|
394
429
  run_and_convert(session, query, data, &block)
395
430
  end
396
431
  end
@@ -430,7 +465,7 @@ module Neo4jBolt
430
465
  end
431
466
 
432
467
  DriverRegistry.with_driver do |driver|
433
- driver.session do |session|
468
+ with_session(driver) do |session|
434
469
  upstream_transaction = session.begin_transaction
435
470
  context = TransactionContext.new(
436
471
  session: session, transaction: upstream_transaction, depth: 1, rollback_only: false
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neo4j_bolt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Specht