deployagram-vcr 0.1.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.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +14 -0
  3. data/README.md +10 -0
  4. data/lib/deployagram/vcr.rb +74 -0
  5. metadata +61 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 96774f4f16cb21a5ac3eae29943f7d4eab0ca811420d7868d65eb898ad054aca
4
+ data.tar.gz: a69a5ba1ef91e261fad94e01153b7903c412dec0f4a7832898817c00997edf80
5
+ SHA512:
6
+ metadata.gz: db8acbb38e01c86a59374c9e99406251dd57a7a8719ccbaa4e0d10941037a5c1c0f6fed28a05c9cb969495b1a093636f9c4ffea5b13335cb96cdfb42904d71fc
7
+ data.tar.gz: d0cd52aeb6520c8d23fb152dc4b244dea12cea291857581920840753fd60d79ce203511f31a8b1b90119de3ce4e6090969fd63c21364cdd50fd53eb4454f3b1f
data/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ DEPLOYAGRAM PROPRIETARY LICENSE
2
+
3
+ Copyright (c) 2025 Deployagram, Cookiebit and Andy Muir.
4
+
5
+ Permission is hereby granted to use this software solely for its intended purpose.
6
+
7
+ RESTRICTIONS:
8
+ - No modification of the software is permitted
9
+ - No reverse engineering, decompilation, or disassembly
10
+ - No redistribution without explicit written permission
11
+ - Source code remains proprietary and confidential
12
+ - Usage is limited to the compiled npm package (the distributed tarball) artifact only
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
data/README.md ADDED
@@ -0,0 +1,10 @@
1
+ # deployagram-vcr
2
+
3
+ Records the outbound HTTP calls that [VCR](https://github.com/vcr/vcr) sees, to the Deployagram Collector. The calls are
4
+ recorded whether they went to the network or were played back from a cassette.
5
+
6
+ The VCR equivalent of `deployagram-webmock`. Requires the `vcr` gem in the test's Gemfile.
7
+
8
+ Depends on: `deployagram-logger-client`.
9
+
10
+ Part of the Deployagram Ruby packages. See `../../README.md`.
@@ -0,0 +1,74 @@
1
+ require "json"
2
+ require "time"
3
+ require "uri"
4
+ require "vcr"
5
+
6
+ module Deployagram
7
+ # Records the outbound HTTP calls that VCR sees, as the WebMock recorder does for WebMock and the Node MSW and Nock
8
+ # recorders do for theirs. VCR calls after_http_request for each call, whether it went to the network or was played
9
+ # back from a cassette, so the recording is the same either way. Call Deployagram::VCR.record(logger, ...) once,
10
+ # before the cassettes are used.
11
+ module VCR
12
+ REQUEST_HEADERS_KEY = "Headers".freeze
13
+
14
+ module_function
15
+
16
+ # callees: a Hash from the URL host and port (for example "classicbooks:8080") to the callee's name.
17
+ def record(logger, caller:, callees:)
18
+ ::VCR.configure do |config|
19
+ config.after_http_request do |request, response|
20
+ callee = callee_for(request.uri, callees)
21
+ next unless callee
22
+
23
+ record_call(logger, caller: caller, callee: callee, request: request, response: response)
24
+ end
25
+ end
26
+ end
27
+
28
+ def callee_for(uri, callees)
29
+ parsed = URI(uri)
30
+ callees["#{parsed.host}:#{parsed.port}"] || callees[parsed.host]
31
+ end
32
+
33
+ def record_call(logger, caller:, callee:, request:, response:)
34
+ method = request.method.to_s.upcase
35
+ uri = URI(request.uri)
36
+ logger.log(entry(
37
+ "#{method} Request from #{caller} to #{callee}",
38
+ { REQUEST_HEADERS_KEY => header_lists(request.headers), "Body" => request.body,
39
+ "Endpoint" => endpoint_of(uri) }.to_json,
40
+ caller, callee
41
+ ))
42
+ logger.log(entry(
43
+ "#{method} Response from #{callee} to #{caller}",
44
+ { REQUEST_HEADERS_KEY => header_lists(response.headers), "Body" => response.body,
45
+ "ResponseCode" => Integer(response.status.code) }.to_json,
46
+ callee, caller
47
+ ))
48
+ end
49
+
50
+
51
+ # The Collector reads each header as a list of values, so a single value (a string) is wrapped in one.
52
+ def header_lists(headers)
53
+ (headers || {}).transform_values { |value| Array(value) }
54
+ end
55
+
56
+ # The endpoint as the Proxy writes it: the path and query, without the leading slash.
57
+ def endpoint_of(uri)
58
+ path = uri.path.to_s.empty? ? "/" : uri.path
59
+ query = uri.query ? "?#{uri.query}" : ""
60
+ "#{path}#{query}".delete_prefix("/")
61
+ end
62
+
63
+ def entry(message, body, source, target)
64
+ {
65
+ "timestamp" => Time.now.utc.iso8601(6),
66
+ "protocol" => "HTTP",
67
+ "source" => source,
68
+ "target" => target,
69
+ "message" => message,
70
+ "body" => body,
71
+ }
72
+ end
73
+ end
74
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deployagram-vcr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Deployagram
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: deployagram-logger-client
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ -
17
+ - "="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ -
25
+ - "="
26
+ - !ruby/object:Gem::Version
27
+ version: 0.1.0
28
+ description: "Records the outbound HTTP calls of a test that uses VCR, both those sent to the network and those played back from cassettes. Requires the vcr gem in the test's Gemfile."
29
+ email:
30
+ - andy@deployagram.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - LICENSE
36
+ - README.md
37
+ - lib/deployagram/vcr.rb
38
+ licenses:
39
+ - SEE LICENSE IN LICENSE
40
+ metadata:
41
+ rubygems_mfa_required: "true"
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ -
48
+ - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "3.2"
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ -
54
+ - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ requirements: []
58
+ rubygems_version: 4.1.0
59
+ specification_version: 4
60
+ summary: Records the HTTP calls that VCR sees to the Deployagram Collector
61
+ test_files: []