textus 0.51.0 → 0.53.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 +4 -4
- data/CHANGELOG.md +37 -0
- data/README.md +74 -66
- data/SPEC.md +100 -223
- data/docs/architecture/README.md +91 -80
- data/docs/reference/conventions.md +8 -8
- data/exe/textus +1 -1
- data/lib/textus/action/accept.rb +53 -0
- data/lib/textus/action/audit.rb +133 -0
- data/lib/textus/action/base.rb +42 -0
- data/lib/textus/{read → action}/blame.rb +30 -22
- data/lib/textus/action/boot.rb +26 -0
- data/lib/textus/action/data_mv.rb +71 -0
- data/lib/textus/action/deps.rb +48 -0
- data/lib/textus/action/doctor.rb +26 -0
- data/lib/textus/action/drain.rb +41 -0
- data/lib/textus/action/enqueue.rb +55 -0
- data/lib/textus/action/get.rb +80 -0
- data/lib/textus/action/jobs.rb +38 -0
- data/lib/textus/action/key_delete.rb +46 -0
- data/lib/textus/action/key_delete_prefix.rb +46 -0
- data/lib/textus/action/key_mv.rb +143 -0
- data/lib/textus/action/key_mv_prefix.rb +59 -0
- data/lib/textus/action/list.rb +44 -0
- data/lib/textus/action/propose.rb +54 -0
- data/lib/textus/action/published.rb +26 -0
- data/lib/textus/action/pulse/scanner.rb +118 -0
- data/lib/textus/action/pulse.rb +87 -0
- data/lib/textus/action/put.rb +63 -0
- data/lib/textus/action/rdeps.rb +49 -0
- data/lib/textus/action/reject.rb +49 -0
- data/lib/textus/action/rule_explain.rb +95 -0
- data/lib/textus/action/rule_lint.rb +70 -0
- data/lib/textus/action/rule_list.rb +46 -0
- data/lib/textus/action/schema_envelope.rb +31 -0
- data/lib/textus/action/uid.rb +35 -0
- data/lib/textus/action/where.rb +38 -0
- data/lib/textus/action/write_verb.rb +58 -0
- data/lib/textus/background/job/base.rb +27 -0
- data/lib/textus/background/job/materialize.rb +31 -0
- data/lib/textus/background/job/refresh.rb +22 -0
- data/lib/textus/background/job/sweep.rb +31 -0
- data/lib/textus/background/job.rb +19 -0
- data/lib/textus/background/plan.rb +9 -0
- data/lib/textus/background/planner/plan.rb +113 -0
- data/lib/textus/background/retention/apply.rb +50 -0
- data/lib/textus/background/worker.rb +67 -0
- data/lib/textus/boot.rb +59 -49
- data/lib/textus/command.rb +36 -0
- data/lib/textus/container.rb +1 -1
- data/lib/textus/{domain → core}/duration.rb +1 -1
- data/lib/textus/{domain → core}/freshness/evaluator.rb +13 -13
- data/lib/textus/{domain → core}/freshness/verdict.rb +2 -2
- data/lib/textus/{domain → core}/freshness.rb +2 -2
- data/lib/textus/{domain → core}/retention/sweep.rb +7 -7
- data/lib/textus/{domain → core}/retention.rb +2 -2
- data/lib/textus/{domain → core}/sentinel.rb +1 -1
- data/lib/textus/doctor/check/generator_drift.rb +2 -2
- data/lib/textus/doctor/check/handler_permit.rb +34 -0
- data/lib/textus/doctor/check/hooks.rb +11 -18
- data/lib/textus/doctor/check/illegal_keys.rb +1 -1
- data/lib/textus/doctor/check/intake_registration.rb +5 -5
- data/lib/textus/doctor/check/proposal_targets.rb +3 -3
- data/lib/textus/doctor/check/rule_ambiguity.rb +2 -2
- data/lib/textus/doctor/check/schema_violations.rb +8 -2
- data/lib/textus/doctor/check/sentinels.rb +2 -2
- data/lib/textus/doctor/check.rb +12 -9
- data/lib/textus/{read → doctor}/validator.rb +22 -13
- data/lib/textus/doctor.rb +6 -6
- data/lib/textus/envelope/io/writer.rb +65 -36
- data/lib/textus/envelope.rb +5 -3
- data/lib/textus/errors.rb +19 -11
- data/lib/textus/events.rb +21 -0
- data/lib/textus/gate/auth.rb +181 -0
- data/lib/textus/gate.rb +114 -0
- data/lib/textus/init/templates/machine_intake.rb +40 -36
- data/lib/textus/init/templates/orientation_reducer.rb +15 -11
- data/lib/textus/init.rb +93 -76
- data/lib/textus/key/path.rb +9 -2
- data/lib/textus/layout.rb +21 -0
- data/lib/textus/manifest/capabilities.rb +1 -1
- data/lib/textus/manifest/data.rb +30 -15
- data/lib/textus/manifest/entry/base.rb +15 -11
- data/lib/textus/manifest/entry/parser.rb +6 -6
- data/lib/textus/manifest/entry/produced.rb +3 -2
- data/lib/textus/manifest/entry/publish/mode.rb +1 -1
- data/lib/textus/manifest/entry/publish/to_paths.rb +2 -1
- data/lib/textus/manifest/entry/validators/events.rb +1 -1
- data/lib/textus/{domain/policy/handler_allowlist.rb → manifest/policy/handler_permit.rb} +4 -4
- data/lib/textus/{domain → manifest}/policy/matcher.rb +2 -2
- data/lib/textus/{domain → manifest}/policy/publish_target.rb +2 -2
- data/lib/textus/manifest/policy/react.rb +30 -0
- data/lib/textus/{domain → manifest}/policy/retention.rb +4 -4
- data/lib/textus/{domain → manifest}/policy/source.rb +27 -28
- data/lib/textus/manifest/policy.rb +36 -48
- data/lib/textus/manifest/resolver.rb +3 -2
- data/lib/textus/manifest/rules.rb +4 -4
- data/lib/textus/manifest/schema/keys.rb +18 -12
- data/lib/textus/manifest/schema/validator.rb +27 -25
- data/lib/textus/manifest/schema/vocabulary.rb +3 -3
- data/lib/textus/manifest/schema.rb +2 -2
- data/lib/textus/manifest.rb +2 -2
- data/lib/textus/{produce → pipeline}/acquire/handler.rb +3 -3
- data/lib/textus/{produce → pipeline}/acquire/intake.rb +23 -21
- data/lib/textus/{produce → pipeline}/acquire/projection.rb +13 -11
- data/lib/textus/{produce → pipeline}/acquire/serializer/json.rb +2 -2
- data/lib/textus/{produce → pipeline}/acquire/serializer/text.rb +1 -1
- data/lib/textus/{produce → pipeline}/acquire/serializer/yaml.rb +2 -2
- data/lib/textus/{produce → pipeline}/acquire/serializer.rb +1 -1
- data/lib/textus/{produce → pipeline}/engine.rb +17 -63
- data/lib/textus/{produce → pipeline}/render.rb +3 -1
- data/lib/textus/ports/audit_log.rb +31 -5
- data/lib/textus/ports/audit_subscriber.rb +4 -4
- data/lib/textus/ports/build_lock.rb +1 -1
- data/lib/textus/ports/queue/job.rb +65 -0
- data/lib/textus/ports/queue.rb +130 -0
- data/lib/textus/ports/sentinel_store.rb +2 -2
- data/lib/textus/ports/watcher_lock.rb +48 -0
- data/lib/textus/projection.rb +8 -8
- data/lib/textus/role.rb +1 -1
- data/lib/textus/schema/tools.rb +4 -3
- data/lib/textus/session.rb +6 -3
- data/lib/textus/step/base.rb +35 -0
- data/lib/textus/step/builtin/csv_fetch.rb +19 -0
- data/lib/textus/step/builtin/ical_events_fetch.rb +30 -0
- data/lib/textus/step/builtin/json_fetch.rb +18 -0
- data/lib/textus/step/builtin/markdown_links_fetch.rb +20 -0
- data/lib/textus/step/builtin/rss_fetch.rb +26 -0
- data/lib/textus/step/builtin.rb +22 -0
- data/lib/textus/{hooks → step}/catalog.rb +3 -4
- data/lib/textus/{hooks → step}/context.rb +15 -13
- data/lib/textus/step/discovery.rb +24 -0
- data/lib/textus/{hooks → step}/error_log.rb +1 -1
- data/lib/textus/{hooks → step}/event_bus.rb +15 -16
- data/lib/textus/step/fetch.rb +13 -0
- data/lib/textus/{hooks → step}/fire_report.rb +1 -1
- data/lib/textus/step/loader.rb +108 -0
- data/lib/textus/step/observe.rb +31 -0
- data/lib/textus/step/registry_store.rb +66 -0
- data/lib/textus/{hooks → step}/signature.rb +1 -1
- data/lib/textus/step/transform.rb +12 -0
- data/lib/textus/step/validate.rb +11 -0
- data/lib/textus/step.rb +10 -0
- data/lib/textus/store.rb +17 -15
- data/lib/textus/surfaces/cli/group/data.rb +11 -0
- data/lib/textus/surfaces/cli/group/key.rb +11 -0
- data/lib/textus/surfaces/cli/group/mcp.rb +11 -0
- data/lib/textus/surfaces/cli/group/rule.rb +11 -0
- data/lib/textus/surfaces/cli/group/schema.rb +11 -0
- data/lib/textus/surfaces/cli/group.rb +50 -0
- data/lib/textus/surfaces/cli/runner.rb +236 -0
- data/lib/textus/surfaces/cli/verb/doctor.rb +21 -0
- data/lib/textus/surfaces/cli/verb/get.rb +21 -0
- data/lib/textus/surfaces/cli/verb/init.rb +20 -0
- data/lib/textus/surfaces/cli/verb/mcp_serve.rb +24 -0
- data/lib/textus/surfaces/cli/verb/put.rb +30 -0
- data/lib/textus/surfaces/cli/verb/schema_diff.rb +17 -0
- data/lib/textus/surfaces/cli/verb/schema_init.rb +21 -0
- data/lib/textus/surfaces/cli/verb/schema_migrate.rb +21 -0
- data/lib/textus/surfaces/cli/verb/watch.rb +19 -0
- data/lib/textus/surfaces/cli/verb.rb +111 -0
- data/lib/textus/surfaces/cli.rb +148 -0
- data/lib/textus/surfaces/mcp/catalog.rb +99 -0
- data/lib/textus/surfaces/mcp/errors.rb +34 -0
- data/lib/textus/surfaces/mcp/server.rb +145 -0
- data/lib/textus/surfaces/mcp/session.rb +9 -0
- data/lib/textus/surfaces/mcp/tool_schemas.rb +17 -0
- data/lib/textus/surfaces/mcp.rb +8 -0
- data/lib/textus/surfaces/role_scope.rb +38 -0
- data/lib/textus/surfaces/watcher.rb +38 -0
- data/lib/textus/version.rb +1 -1
- data/lib/textus.rb +64 -22
- metadata +133 -107
- data/lib/textus/cli/group/hook.rb +0 -9
- data/lib/textus/cli/group/key.rb +0 -9
- data/lib/textus/cli/group/mcp.rb +0 -9
- data/lib/textus/cli/group/rule.rb +0 -9
- data/lib/textus/cli/group/schema.rb +0 -9
- data/lib/textus/cli/group/zone.rb +0 -9
- data/lib/textus/cli/group.rb +0 -48
- data/lib/textus/cli/runner.rb +0 -193
- data/lib/textus/cli/verb/doctor.rb +0 -17
- data/lib/textus/cli/verb/get.rb +0 -18
- data/lib/textus/cli/verb/hook_run.rb +0 -48
- data/lib/textus/cli/verb/hooks.rb +0 -50
- data/lib/textus/cli/verb/init.rb +0 -18
- data/lib/textus/cli/verb/mcp_serve.rb +0 -22
- data/lib/textus/cli/verb/put.rb +0 -30
- data/lib/textus/cli/verb/schema_diff.rb +0 -15
- data/lib/textus/cli/verb/schema_init.rb +0 -19
- data/lib/textus/cli/verb/schema_migrate.rb +0 -19
- data/lib/textus/cli/verb.rb +0 -116
- data/lib/textus/cli.rb +0 -138
- data/lib/textus/dispatcher.rb +0 -52
- data/lib/textus/doctor/check/handler_allowlist.rb +0 -34
- data/lib/textus/domain/action.rb +0 -9
- data/lib/textus/domain/permission.rb +0 -7
- data/lib/textus/domain/policy/base_guards.rb +0 -25
- data/lib/textus/domain/policy/evaluation.rb +0 -15
- data/lib/textus/domain/policy/guard.rb +0 -35
- data/lib/textus/domain/policy/guard_factory.rb +0 -40
- data/lib/textus/domain/policy/predicates/author_held.rb +0 -33
- data/lib/textus/domain/policy/predicates/etag_match.rb +0 -32
- data/lib/textus/domain/policy/predicates/fresh_within.rb +0 -59
- data/lib/textus/domain/policy/predicates/registry.rb +0 -39
- data/lib/textus/domain/policy/predicates/schema_valid.rb +0 -61
- data/lib/textus/domain/policy/predicates/target_is_canon.rb +0 -33
- data/lib/textus/domain/policy/predicates/zone_writable_by.rb +0 -39
- data/lib/textus/hooks/builtin.rb +0 -70
- data/lib/textus/hooks/loader.rb +0 -54
- data/lib/textus/hooks/rpc_registry.rb +0 -43
- data/lib/textus/maintenance/key_delete_prefix.rb +0 -48
- data/lib/textus/maintenance/key_mv_prefix.rb +0 -68
- data/lib/textus/maintenance/reconcile.rb +0 -160
- data/lib/textus/maintenance/rule_lint.rb +0 -66
- data/lib/textus/maintenance/zone_mv.rb +0 -64
- data/lib/textus/maintenance.rb +0 -15
- data/lib/textus/mcp/catalog.rb +0 -70
- data/lib/textus/mcp/errors.rb +0 -32
- data/lib/textus/mcp/server.rb +0 -138
- data/lib/textus/mcp/session.rb +0 -7
- data/lib/textus/mcp/tool_schemas.rb +0 -15
- data/lib/textus/mcp.rb +0 -6
- data/lib/textus/mustache.rb +0 -117
- data/lib/textus/ports/produce_on_write_subscriber.rb +0 -69
- data/lib/textus/produce/events.rb +0 -36
- data/lib/textus/read/audit.rb +0 -130
- data/lib/textus/read/boot.rb +0 -26
- data/lib/textus/read/capabilities.rb +0 -70
- data/lib/textus/read/deps.rb +0 -38
- data/lib/textus/read/doctor.rb +0 -27
- data/lib/textus/read/freshness.rb +0 -152
- data/lib/textus/read/get.rb +0 -73
- data/lib/textus/read/list.rb +0 -24
- data/lib/textus/read/published.rb +0 -22
- data/lib/textus/read/pulse.rb +0 -98
- data/lib/textus/read/rdeps.rb +0 -39
- data/lib/textus/read/rule_explain.rb +0 -96
- data/lib/textus/read/rule_list.rb +0 -54
- data/lib/textus/read/schema_envelope.rb +0 -25
- data/lib/textus/read/uid.rb +0 -29
- data/lib/textus/read/validate_all.rb +0 -36
- data/lib/textus/read/where.rb +0 -24
- data/lib/textus/role_scope.rb +0 -78
- data/lib/textus/write/accept.rb +0 -58
- data/lib/textus/write/key_delete.rb +0 -65
- data/lib/textus/write/key_mv.rb +0 -141
- data/lib/textus/write/propose.rb +0 -54
- data/lib/textus/write/put.rb +0 -74
- data/lib/textus/write/reject.rb +0 -68
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Textus
|
|
4
|
+
class Gate
|
|
5
|
+
class Auth
|
|
6
|
+
FLOOR = {
|
|
7
|
+
put: %w[lane_writable_by],
|
|
8
|
+
key_delete: %w[lane_writable_by],
|
|
9
|
+
key_mv: %w[lane_writable_by],
|
|
10
|
+
accept: %w[author_held],
|
|
11
|
+
reject: %w[author_held],
|
|
12
|
+
propose: %w[lane_writable_by],
|
|
13
|
+
key_mv_prefix: %w[lane_writable_by],
|
|
14
|
+
key_delete_prefix: %w[lane_writable_by],
|
|
15
|
+
}.freeze
|
|
16
|
+
|
|
17
|
+
AuthContext = Struct.new(
|
|
18
|
+
:actor, :actor_caps, :lane_verb,
|
|
19
|
+
:action, :target, :envelope,
|
|
20
|
+
:mentry, :manifest,
|
|
21
|
+
keyword_init: true
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
def initialize(container)
|
|
25
|
+
@manifest = container.manifest
|
|
26
|
+
@schemas = container.schemas
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Command-based check (new Gate path).
|
|
30
|
+
def check!(cmd)
|
|
31
|
+
key = extract_key(cmd)
|
|
32
|
+
return unless key
|
|
33
|
+
|
|
34
|
+
evaluate_predicates(
|
|
35
|
+
action: command_to_action(cmd),
|
|
36
|
+
actor: cmd.role.to_s,
|
|
37
|
+
key: key,
|
|
38
|
+
envelope: nil,
|
|
39
|
+
extra: {},
|
|
40
|
+
)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Backward-compatible check for inline action auth (accept, put, etc.).
|
|
44
|
+
def check_action!(action:, actor:, key:, envelope: nil, extra: {})
|
|
45
|
+
evaluate_predicates(
|
|
46
|
+
action: action.to_sym,
|
|
47
|
+
actor: actor,
|
|
48
|
+
key: key,
|
|
49
|
+
envelope: envelope,
|
|
50
|
+
extra: extra,
|
|
51
|
+
)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def self.command_to_verb
|
|
55
|
+
@command_to_verb ||= Textus::Gate::VERB_COMMAND.invert.freeze
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
private
|
|
59
|
+
|
|
60
|
+
def command_to_action(cmd)
|
|
61
|
+
self.class.command_to_verb.fetch(cmd.class) do
|
|
62
|
+
raise Textus::UsageError.new("unmapped command: #{cmd.class}")
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def evaluate_predicates(action:, actor:, key:, envelope:, extra:)
|
|
67
|
+
mentry = @manifest.resolver.resolve(key).entry
|
|
68
|
+
lane_verb = @manifest.policy.verb_for_lane(mentry.lane.to_s)
|
|
69
|
+
actor_caps = Set.new(@manifest.data.role_caps.fetch(actor, []))
|
|
70
|
+
|
|
71
|
+
ctx = AuthContext.new(
|
|
72
|
+
actor:, actor_caps:, lane_verb:,
|
|
73
|
+
action:, target: key, envelope:,
|
|
74
|
+
mentry:, manifest: @manifest
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
failures = []
|
|
78
|
+
floor_preds = FLOOR.fetch(action, [])
|
|
79
|
+
rule_preds = rule_declared_predicates(action, key)
|
|
80
|
+
(floor_preds + rule_preds).uniq.each do |pred|
|
|
81
|
+
result = evaluate(pred, ctx, extra)
|
|
82
|
+
next if result[:pass]
|
|
83
|
+
raise result[:error] if result[:error]
|
|
84
|
+
|
|
85
|
+
failures << [pred, result[:reason]]
|
|
86
|
+
end
|
|
87
|
+
raise Textus::GuardFailed.new(failures) unless failures.empty?
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def extract_key(cmd)
|
|
91
|
+
if cmd.respond_to?(:pending_key)
|
|
92
|
+
cmd.pending_key
|
|
93
|
+
elsif cmd.respond_to?(:key)
|
|
94
|
+
cmd.key
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def rule_declared_predicates(action, key)
|
|
99
|
+
guard_map = @manifest.rules.for(key).guard
|
|
100
|
+
return [] if guard_map.nil?
|
|
101
|
+
|
|
102
|
+
Array(guard_map[action.to_s])
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def evaluate(pred_name, ctx, extra)
|
|
106
|
+
case pred_name
|
|
107
|
+
when "lane_writable_by" then evaluate_lane_writable_by(ctx)
|
|
108
|
+
when "author_held" then evaluate_author_held(ctx)
|
|
109
|
+
when "target_is_canon" then evaluate_target_is_canon(ctx)
|
|
110
|
+
when "etag_match" then evaluate_etag_match(ctx, extra)
|
|
111
|
+
when "schema_valid" then evaluate_schema_valid(ctx)
|
|
112
|
+
when "fresh_within" then { pass: true }
|
|
113
|
+
else raise Textus::UsageError.new("unknown predicate '#{pred_name}'")
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def evaluate_lane_writable_by(ctx)
|
|
118
|
+
pass = ctx.actor_caps.include?(ctx.lane_verb.to_s)
|
|
119
|
+
return { pass: true } if pass
|
|
120
|
+
|
|
121
|
+
holders = @manifest.policy.roles_with_capability(ctx.lane_verb.to_s)
|
|
122
|
+
{ pass: false, error: Textus::WriteForbidden.new(ctx.mentry.key, ctx.mentry.lane, verb: ctx.lane_verb, holders:) }
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def evaluate_author_held(ctx)
|
|
126
|
+
holders = @manifest.policy.roles_with_capability("author")
|
|
127
|
+
pass = holders.include?(ctx.actor.to_s)
|
|
128
|
+
reason = if pass
|
|
129
|
+
nil
|
|
130
|
+
elsif holders.empty?
|
|
131
|
+
"no role holds the 'author' capability; #{ctx.action} is disabled"
|
|
132
|
+
else
|
|
133
|
+
"role '#{ctx.actor}' lacks the 'author' capability (held by: #{holders.join(", ")})"
|
|
134
|
+
end
|
|
135
|
+
{ pass:, reason: }
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def evaluate_target_is_canon(ctx)
|
|
139
|
+
kind = @manifest.policy.declared_kind(ctx.mentry.lane.to_s)
|
|
140
|
+
pass = kind == :canon
|
|
141
|
+
{ pass:, reason: pass ? nil : "target lane '#{ctx.mentry.lane}' is not canon (kind: #{kind})" }
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def evaluate_etag_match(ctx, extra)
|
|
145
|
+
if_etag = extra[:if_etag]
|
|
146
|
+
return { pass: true } if if_etag.nil?
|
|
147
|
+
|
|
148
|
+
current = ctx.envelope&.etag
|
|
149
|
+
pass = current.nil? || current == if_etag
|
|
150
|
+
{ pass:, error: pass ? nil : Textus::EtagMismatch.new(ctx.target, if_etag, current) }
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def evaluate_schema_valid(ctx)
|
|
154
|
+
return { pass: true } unless ctx.envelope
|
|
155
|
+
|
|
156
|
+
schema_ref = ctx.mentry.schema
|
|
157
|
+
return { pass: true } unless schema_ref
|
|
158
|
+
|
|
159
|
+
schema = @schemas.fetch_or_nil(schema_ref)
|
|
160
|
+
return { pass: true } unless schema
|
|
161
|
+
|
|
162
|
+
frontmatter = ctx.envelope.meta&.dig("_meta") || ctx.envelope.meta || {}
|
|
163
|
+
begin
|
|
164
|
+
schema.validate!(frontmatter)
|
|
165
|
+
{ pass: true }
|
|
166
|
+
rescue Textus::SchemaViolation => e
|
|
167
|
+
{ pass: false, reason: schema_reason(e) }
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def schema_reason(err)
|
|
172
|
+
d = err.details
|
|
173
|
+
return err.message.dup unless d.is_a?(Hash)
|
|
174
|
+
return "missing required fields: #{Array(d["missing"]).join(", ")}" if d["missing"]
|
|
175
|
+
return "field '#{d["field"]}': #{d["reason"]}" if d["field"]
|
|
176
|
+
|
|
177
|
+
err.message.dup
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
end
|
data/lib/textus/gate.rb
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Textus
|
|
4
|
+
class Gate
|
|
5
|
+
VERB_COMMAND = {
|
|
6
|
+
get: Textus::Command::Get,
|
|
7
|
+
put: Textus::Command::Put,
|
|
8
|
+
propose: Textus::Command::Propose,
|
|
9
|
+
key_delete: Textus::Command::KeyDelete,
|
|
10
|
+
key_mv: Textus::Command::KeyMv,
|
|
11
|
+
accept: Textus::Command::Accept,
|
|
12
|
+
reject: Textus::Command::Reject,
|
|
13
|
+
enqueue: Textus::Command::Enqueue,
|
|
14
|
+
list: Textus::Command::List,
|
|
15
|
+
where: Textus::Command::Where,
|
|
16
|
+
uid: Textus::Command::Uid,
|
|
17
|
+
blame: Textus::Command::Blame,
|
|
18
|
+
audit: Textus::Command::Audit,
|
|
19
|
+
deps: Textus::Command::Deps,
|
|
20
|
+
rdeps: Textus::Command::Rdeps,
|
|
21
|
+
pulse: Textus::Command::Pulse,
|
|
22
|
+
rule_explain: Textus::Command::RuleExplain,
|
|
23
|
+
rule_list: Textus::Command::RuleList,
|
|
24
|
+
rule_lint: Textus::Command::RuleLint,
|
|
25
|
+
published: Textus::Command::Published,
|
|
26
|
+
schema_show: Textus::Command::SchemaShow,
|
|
27
|
+
doctor: Textus::Command::Doctor,
|
|
28
|
+
boot: Textus::Command::Boot,
|
|
29
|
+
jobs: Textus::Command::Jobs,
|
|
30
|
+
data_mv: Textus::Command::DataMv,
|
|
31
|
+
key_mv_prefix: Textus::Command::KeyMvPrefix,
|
|
32
|
+
key_delete_prefix: Textus::Command::KeyDeletePrefix,
|
|
33
|
+
drain: Textus::Command::Drain,
|
|
34
|
+
}.freeze
|
|
35
|
+
|
|
36
|
+
ROUTES = {
|
|
37
|
+
Command::Get => [Textus::Action::Get],
|
|
38
|
+
Command::Put => [Textus::Action::Put],
|
|
39
|
+
Command::Propose => [Textus::Action::Propose],
|
|
40
|
+
Command::KeyDelete => [Textus::Action::KeyDelete],
|
|
41
|
+
Command::KeyMv => [Textus::Action::KeyMv],
|
|
42
|
+
Command::Accept => [Textus::Action::Accept],
|
|
43
|
+
Command::Reject => [Textus::Action::Reject],
|
|
44
|
+
Command::Enqueue => [Textus::Action::Enqueue],
|
|
45
|
+
Command::List => [Textus::Action::List],
|
|
46
|
+
Command::Where => [Textus::Action::Where],
|
|
47
|
+
Command::Uid => [Textus::Action::Uid],
|
|
48
|
+
Command::Blame => [Textus::Action::Blame],
|
|
49
|
+
Command::Audit => [Textus::Action::Audit],
|
|
50
|
+
Command::Deps => [Textus::Action::Deps],
|
|
51
|
+
Command::Rdeps => [Textus::Action::Rdeps],
|
|
52
|
+
Command::Pulse => [Textus::Action::Pulse],
|
|
53
|
+
Command::RuleExplain => [Textus::Action::RuleExplain],
|
|
54
|
+
Command::RuleList => [Textus::Action::RuleList],
|
|
55
|
+
Command::RuleLint => [Textus::Action::RuleLint],
|
|
56
|
+
Command::Published => [Textus::Action::Published],
|
|
57
|
+
Command::SchemaShow => [Textus::Action::SchemaEnvelope],
|
|
58
|
+
Command::Doctor => [Textus::Action::Doctor],
|
|
59
|
+
Command::Boot => [Textus::Action::Boot],
|
|
60
|
+
Command::Jobs => [Textus::Action::Jobs],
|
|
61
|
+
Command::DataMv => [Textus::Action::DataMv],
|
|
62
|
+
Command::KeyMvPrefix => [Textus::Action::KeyMvPrefix],
|
|
63
|
+
Command::KeyDeletePrefix => [Textus::Action::KeyDeletePrefix],
|
|
64
|
+
Command::Drain => [Textus::Action::Drain],
|
|
65
|
+
}.freeze
|
|
66
|
+
|
|
67
|
+
def initialize(container)
|
|
68
|
+
@container = container
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def dispatch(cmd, correlation_id: nil)
|
|
72
|
+
cmd = normalize_propose_key(cmd, @container) if cmd.is_a?(Command::Propose)
|
|
73
|
+
action_classes = ROUTES.fetch(cmd.class) do
|
|
74
|
+
raise Textus::UsageError.new("unknown command: #{cmd.class}")
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
Gate::Auth.new(@container).check!(cmd)
|
|
78
|
+
call_obj = build_call(cmd, correlation_id: correlation_id)
|
|
79
|
+
results = action_classes.map { |klass| run_action(klass, cmd, @container, call_obj) }
|
|
80
|
+
results.length == 1 ? results.first : results
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
private
|
|
84
|
+
|
|
85
|
+
def normalize_propose_key(cmd, container)
|
|
86
|
+
return cmd if cmd.pending_key
|
|
87
|
+
|
|
88
|
+
zone = container.manifest.policy.propose_lane_for(cmd.role.to_s)
|
|
89
|
+
cmd.with(pending_key: zone ? "#{zone}.#{cmd.key}" : nil)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def run_action(klass, cmd, container, call_obj)
|
|
93
|
+
action = klass.new(**extract_kwargs(klass, cmd))
|
|
94
|
+
action.call(container:, call: call_obj)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def extract_kwargs(klass, cmd)
|
|
98
|
+
params = klass.instance_method(:initialize).parameters
|
|
99
|
+
accepts_keyrest = params.any? { |t, _| t == :keyrest }
|
|
100
|
+
param_set = params.to_set { |_t, n| n }
|
|
101
|
+
cmd.members.each_with_object({}) do |m, h|
|
|
102
|
+
next unless accepts_keyrest || param_set.include?(m)
|
|
103
|
+
|
|
104
|
+
val = cmd.public_send(m)
|
|
105
|
+
h[m] = val unless val.nil?
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def build_call(cmd, correlation_id: nil)
|
|
110
|
+
dry_run = cmd.respond_to?(:dry_run) ? !cmd.dry_run.nil? : false
|
|
111
|
+
Textus::Call.build(role: cmd.role, dry_run:, correlation_id: correlation_id)
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
@@ -1,45 +1,49 @@
|
|
|
1
|
-
# .textus/
|
|
1
|
+
# .textus/steps/fetch/machine_intake.rb
|
|
2
2
|
# Scaffolded by `textus init` — CUSTOMIZE FREELY, or delete the feeds.machines
|
|
3
3
|
# entry from manifest.yaml if you don't want it.
|
|
4
|
-
# Feeds a per-host SNAPSHOT into feeds.machines.<host> on `textus
|
|
4
|
+
# Feeds a per-host SNAPSHOT into feeds.machines.<host> on `textus drain`
|
|
5
5
|
# (never on the per-turn boot/pulse path). It is NESTED so it grows to a fleet: the
|
|
6
6
|
# `local` leaf scans THIS host; add ssh hosts with the cookbook recipe
|
|
7
7
|
# (docs/cookbook/environment-scan.md). tracked:false → gitignored. Keep this an
|
|
8
8
|
# ALLOWLIST of versions and counts — NEVER secrets, raw `env`, or package lists.
|
|
9
|
-
Textus
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
module Textus
|
|
10
|
+
module Step
|
|
11
|
+
class MachineIntakeFetch < Fetch
|
|
12
|
+
def call(config:, args:, caps:, **)
|
|
13
|
+
machine = args[:leaf_segments].first or
|
|
14
|
+
raise "machines intake needs a host leaf, e.g. the 'local' in feeds.machines.local"
|
|
15
|
+
spec = (config["machines"] || {}).fetch(machine) { raise "unknown machine: #{machine}" }
|
|
16
|
+
unless (spec["via"] || "local").to_s == "local"
|
|
17
|
+
raise "machine #{machine}: only `via: local` is scaffolded — see " \
|
|
18
|
+
"docs/cookbook/environment-scan.md for the SSH (remote) fan-out"
|
|
19
|
+
end
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
21
|
+
sh = ->(cmd) { `#{cmd}`.strip } # local shell-out, no network
|
|
22
|
+
ver = ->(cmd) { o = `#{cmd} 2>/dev/null`.strip; o.empty? ? nil : o } # nil if tool absent
|
|
23
|
+
count = ->(cmd) { n = `#{cmd} 2>/dev/null`.strip.lines.size; n.zero? ? nil : n }
|
|
24
|
+
{ content: {
|
|
25
|
+
# git_* describe THIS repo on the control host — only meaningful for `local`.
|
|
26
|
+
"git_head" => sh.call("git rev-parse --short HEAD 2>/dev/null"),
|
|
27
|
+
"git_branch" => sh.call("git rev-parse --abbrev-ref HEAD 2>/dev/null"),
|
|
28
|
+
"git_dirty" => !sh.call("git status --porcelain 2>/dev/null").empty?,
|
|
29
|
+
"repo_root" => sh.call("git rev-parse --show-toplevel 2>/dev/null"),
|
|
30
|
+
"captured_at" => Time.now.utc.iso8601,
|
|
31
|
+
"os" => RbConfig::CONFIG["host_os"],
|
|
32
|
+
"arch" => RbConfig::CONFIG["host_cpu"],
|
|
33
|
+
"ruby_version" => RUBY_VERSION,
|
|
34
|
+
"runtimes" => { # versions only; nil when not installed
|
|
35
|
+
"node" => ver.call("node --version"),
|
|
36
|
+
"python" => ver.call("python3 --version"),
|
|
37
|
+
"go" => ver.call("go version"),
|
|
38
|
+
},
|
|
39
|
+
"packages" => { # COUNTS only — never the list (size/secrets)
|
|
40
|
+
"brew" => count.call("brew list --formula"), # ~1-3s on macOS; runs only on fetch, amortized by the ttl rule
|
|
41
|
+
"apt" => count.call("dpkg-query -f '.\n' -W"),
|
|
42
|
+
},
|
|
43
|
+
"textus_version" => Textus::VERSION,
|
|
44
|
+
"protocol" => Textus::PROTOCOL,
|
|
45
|
+
} }
|
|
46
|
+
end
|
|
47
|
+
end
|
|
44
48
|
end
|
|
45
49
|
end
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
# Reducer that reshapes the raw projection rows into the keys the
|
|
2
2
|
# orientation.mustache template references. Without this, the template
|
|
3
3
|
# would only have access to the flat rows list.
|
|
4
|
-
Textus
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
module Textus
|
|
5
|
+
module Step
|
|
6
|
+
class OrientationTransform < Transform
|
|
7
|
+
def call(rows:, config:, **)
|
|
8
|
+
project_row = rows.find { |r| r["_key"] == "knowledge.project" } || {}
|
|
9
|
+
runbook_rows = rows.select { |r| r["_key"]&.start_with?("knowledge.runbooks.") }
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
{
|
|
12
|
+
"project" => {
|
|
13
|
+
"name" => project_row["name"],
|
|
14
|
+
"description" => project_row["description"]
|
|
15
|
+
},
|
|
16
|
+
"runbooks" => runbook_rows.map { |r| { "name" => r["name"], "description" => r["description"] } }
|
|
17
|
+
}
|
|
18
|
+
end
|
|
19
|
+
end
|
|
16
20
|
end
|
|
17
21
|
end
|