Class: Capsium::Reactor::Introspection
- Inherits:
-
Object
- Object
- Capsium::Reactor::Introspection
- Defined in:
- lib/capsium/reactor/introspection.rb,
sig/capsium/reactor/introspection.rbs
Overview
Monitoring HTTP API reports for the package this reactor serves (ARCHITECTURE.md section 7).
Constant Summary collapse
- METADATA_PATH =
"/api/v1/introspect/metadata"- ROUTES_PATH =
"/api/v1/introspect/routes"- CONTENT_HASHES_PATH =
"/api/v1/introspect/content-hashes"- CONTENT_VALIDITY_PATH =
"/api/v1/introspect/content-validity"- PATHS =
[METADATA_PATH, ROUTES_PATH, CONTENT_HASHES_PATH, CONTENT_VALIDITY_PATH].freeze
Instance Attribute Summary collapse
-
#package ⇒ Package
readonly
Returns the value of attribute package.
Instance Method Summary collapse
- #content_hashes_report ⇒ Hash[Symbol, untyped]
- #content_validity_report ⇒ Hash[Symbol, untyped]
- #endpoint?(path) ⇒ Boolean
-
#initialize(package) ⇒ Introspection
constructor
A new instance of Introspection.
- #metadata_report ⇒ Hash[Symbol, untyped]
-
#report_for(path) ⇒ Hash[Symbol, untyped]?
The report body for an introspection endpoint, or nil when the path is not an introspection endpoint.
- #routes_report ⇒ Hash[Symbol, untyped]
Constructor Details
#initialize(package) ⇒ Introspection
Returns a new instance of Introspection.
22 23 24 |
# File 'lib/capsium/reactor/introspection.rb', line 22 def initialize(package) @package = package end |
Instance Attribute Details
#package ⇒ Package (readonly)
Returns the value of attribute package.
20 21 22 |
# File 'lib/capsium/reactor/introspection.rb', line 20 def package @package end |
Instance Method Details
#content_hashes_report ⇒ Hash[Symbol, untyped]
58 59 60 |
# File 'lib/capsium/reactor/introspection.rb', line 58 def content_hashes_report { contentHashes: [{ package: package.name, hash: content_hash }] } end |
#content_validity_report ⇒ Hash[Symbol, untyped]
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/capsium/reactor/introspection.rb', line 62 def content_validity_report errors = package.verify_integrity entry = { package: package.name, valid: errors.empty?, lastChecked: Time.now.utc.iso8601, signed: package.signed?, encrypted: package.encrypted? } entry[:signatureValid] = package.verify_signature if package.signed? entry[:reason] = errors.map(&:message).join("; ") unless errors.empty? { contentValidity: [entry] } end |
#endpoint?(path) ⇒ Boolean
26 27 28 |
# File 'lib/capsium/reactor/introspection.rb', line 26 def endpoint?(path) PATHS.include?(path) end |
#metadata_report ⇒ Hash[Symbol, untyped]
41 42 43 44 45 46 47 48 49 |
# File 'lib/capsium/reactor/introspection.rb', line 41 def = package. { packages: [{ name: .name, version: .version, author: ., description: .description }] } end |
#report_for(path) ⇒ Hash[Symbol, untyped]?
The report body for an introspection endpoint, or nil when the path is not an introspection endpoint.
32 33 34 35 36 37 38 39 |
# File 'lib/capsium/reactor/introspection.rb', line 32 def report_for(path) case path when METADATA_PATH then when ROUTES_PATH then routes_report when CONTENT_HASHES_PATH then content_hashes_report when CONTENT_VALIDITY_PATH then content_validity_report end end |
#routes_report ⇒ Hash[Symbol, untyped]
51 52 53 54 55 56 |
# File 'lib/capsium/reactor/introspection.rb', line 51 def routes_report entries = package.routes.config.routes.map do |route| { method: route.http_method || "GET", path: route.path } end { routes: [{ package: package.name, routes: entries }] } end |