deployagram-core 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 25aaec42fa5fed62b44afe9869784c3f407fb6b1f1f7d8daf66e2406287b3cde
4
+ data.tar.gz: dd6f3cd92ad64c90e5e9f32eb1ba870f55e0c43bdbb3cdbf2d8508a9108237c2
5
+ SHA512:
6
+ metadata.gz: da3375686bd8ed8def86c946ec519b4617e9963b16fc41d84219dafeff37c2ed50dc4871284541f8d587c2ecaec916e563946ed9f70fa2c49219922c4ad720cb
7
+ data.tar.gz: c40e1c6445457d4061cec7ac4422804852b23de377683a722a843d5c96d9920209c12f3e73da4401784c8b615567728c1fb290bd7fafc67c6b7ba87d2bf7b4ac
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,9 @@
1
+ # deployagram-core
2
+
3
+ Framework-independent Deployagram helpers for Ruby service tests.
4
+
5
+ The HTTP Proxy configuration, and the recorder for a test's own HTTP call to the application. Used by the runner adapters.
6
+
7
+ Depends on: `deployagram-logger-client`.
8
+
9
+ Part of the Deployagram Ruby packages. See `../../README.md`.
@@ -0,0 +1,76 @@
1
+ require "json"
2
+ require "net/http"
3
+ require "time"
4
+ require "uri"
5
+
6
+ module Deployagram
7
+ # Records a call the test makes to the application over HTTP. The Proxy records the calls that the application
8
+ # receives through it, but nothing records a call the test makes directly, so the test records its own call: the
9
+ # request before it is sent, and the response after it returns. Recording the request first keeps the Collector's
10
+ # order right, because the application's own calls happen between the two.
11
+ module Inbound
12
+ module_function
13
+
14
+ # Sends a request to uri, records it and the response as a call from caller to callee, and returns the response.
15
+ # The request is recorded under the same names the Proxy uses, so the diagram looks the same either way.
16
+ def call(logger, caller:, callee:, uri:, method: :get, body: nil, headers: {})
17
+ uri = URI(uri) unless uri.is_a?(URI::Generic)
18
+ record_request(logger, caller: caller, callee: callee, uri: uri, method: method, headers: headers, body: body)
19
+
20
+ response = send_request(uri, method, body, headers)
21
+
22
+ record_response(logger, caller: caller, callee: callee, response_code: response.code, headers: response.to_hash,
23
+ body: response.body)
24
+ response
25
+ end
26
+
27
+ # Records the request, for a transport that the test drives itself, such as rack-test. Call it before the request is
28
+ # sent, and record_response after the response comes back. The body is null when there is none, as the Proxy writes it.
29
+ def record_request(logger, caller:, callee:, uri:, method: :get, headers: {}, body: nil)
30
+ uri = URI(uri) unless uri.is_a?(URI::Generic)
31
+ logger.log(entry("#{method.to_s.upcase} Request from #{caller} to #{callee}",
32
+ { "Headers" => header_lists(headers), "Body" => body, "Endpoint" => endpoint_of(uri) }.to_json,
33
+ caller, callee))
34
+ end
35
+
36
+ # Records the response to a request that record_request recorded.
37
+ def record_response(logger, caller:, callee:, response_code:, headers: {}, body: nil, method: :get)
38
+ logger.log(entry("#{method.to_s.upcase} Response from #{callee} to #{caller}",
39
+ { "Headers" => header_lists(headers), "Body" => body,
40
+ "ResponseCode" => Integer(response_code) }.to_json,
41
+ callee, caller))
42
+ end
43
+
44
+
45
+ # The Collector reads each header as a list of values, so a single value (a string) is wrapped in one.
46
+ def header_lists(headers)
47
+ (headers || {}).transform_values { |value| Array(value) }
48
+ end
49
+
50
+ def send_request(uri, method, body, headers)
51
+ klass = Net::HTTP.const_get(method.to_s.capitalize)
52
+ request = klass.new(uri, headers)
53
+ request.body = body if body
54
+ Net::HTTP.start(uri.host, uri.port) { |http| http.request(request) }
55
+ end
56
+
57
+ # The endpoint as the Proxy writes it: the path and query, without the leading slash.
58
+ # Built from the path and query, so that a relative URI, such as "/Emailer/email", works as well as an absolute one.
59
+ def endpoint_of(uri)
60
+ path = uri.path.to_s.empty? ? "/" : uri.path
61
+ query = uri.query ? "?#{uri.query}" : ""
62
+ "#{path}#{query}".delete_prefix("/")
63
+ end
64
+
65
+ def entry(message, body, source, target)
66
+ {
67
+ "timestamp" => Time.now.utc.iso8601(6),
68
+ "protocol" => "HTTP",
69
+ "source" => source,
70
+ "target" => target,
71
+ "message" => message,
72
+ "body" => body,
73
+ }
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,23 @@
1
+ require "json"
2
+ require "net/http"
3
+ require "uri"
4
+ require "deployagram/errors"
5
+
6
+ module Deployagram
7
+ # POSTs proxy configuration to /addNewConfigToProxy, as the Java DeployagramProxyConfigurer does.
8
+ # Keys look like "proxy.proxiedApps.Emailer/email". Three keys per callee: namesOfSourceApps,
9
+ # proxiedAppNames and proxiedApps.
10
+ module ProxyConfig
11
+ module_function
12
+
13
+ def post(proxy_url, config)
14
+ uri = URI(proxy_url.sub(%r{/+\z}, "") + "/addNewConfigToProxy")
15
+ req = Net::HTTP::Post.new(uri)
16
+ req["Content-Type"] = "application/json"
17
+ req.body = JSON.generate(config)
18
+
19
+ res = Net::HTTP.start(uri.host, uri.port) { |http| http.request(req) }
20
+ raise ProxyConfigError.new(res.code.to_i, res.body.to_s) unless res.is_a?(Net::HTTPSuccess)
21
+ end
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deployagram-core
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: "The HTTP Proxy configuration, and the recorder for a test's own HTTP call to the application. Used by the runner adapters."
29
+ email:
30
+ - andy@deployagram.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - LICENSE
36
+ - README.md
37
+ - lib/deployagram/inbound.rb
38
+ - lib/deployagram/proxy_config.rb
39
+ licenses:
40
+ - SEE LICENSE IN LICENSE
41
+ metadata:
42
+ rubygems_mfa_required: "true"
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ -
49
+ - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "3.2"
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ -
55
+ - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ requirements: []
59
+ rubygems_version: 4.1.0
60
+ specification_version: 4
61
+ summary: Framework-independent Deployagram helpers for Ruby service tests
62
+ test_files: []