ctx_cli 0.3.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 993414ac12bd17c37f136bb85d871efc2f217c7ca81fb7c9c57faca557030686
4
- data.tar.gz: d1cfd1282ef0e9ddf5cd23243bf09076d0ffc8fed4c00186f5471e5e96bbcb94
3
+ metadata.gz: b464099a905c64a24b68ae31968fe954f8160ab59ae68edafed68f21164807c8
4
+ data.tar.gz: c08eda04c35fa9360ff72f2a5373a10cc75652e27e9515402da50d3446fdbf56
5
5
  SHA512:
6
- metadata.gz: 6a72826b05f4e540be4999b61acbf9e89517c41949ccefd475e2e67ea039e39a49754f4ddcf179de83f164954032c0d250463db0b0ac6925d51e11665d98b6d2
7
- data.tar.gz: aa88dbda8a415b0f3db1a52a9283a6711951e35c5003814f75724e1ace72ae35472d7f09beda808597c04f746d6dabe7fbd6946f4a55f241cd104c05e831c5a5
6
+ metadata.gz: 56034b19ee9105f545279e0c01dabf52108269c646553a37bc15a21c5e6624c4a090905314ab93dfd54840312483497586bfe0dd668fc5eefa942e907803a288
7
+ data.tar.gz: 681f69619a054508d607106a3791b05515041f6ccddae9edce3129815128c434059d34df43574b059a0ad1a434be6afe228ac1e63c993f3bc64346e4f7ea9792
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.4.0 (2026-10-29)
6
+
7
+ - Add an injected Apply entry point for checksummed plans, explicit item selection, interactive confirmation and safe failure reporting, without domain, runner or connector dependencies.
8
+
5
9
  ## 0.3.0 (2026-10-24)
6
10
 
7
11
  - Use JSON Pointer keys in configuration field provenance, separating literal dots, slashes, tildes, empty keys and nested mappings.
data/README.md CHANGED
@@ -75,7 +75,7 @@ Options 协作者沿用现有入口协议:`informational?`、`validate_interac
75
75
  bundle install
76
76
  bundle exec rake
77
77
  bundle exec rake build
78
- ruby script/verify_package.rb pkg/ctx_cli-0.3.0.gem
78
+ ruby script/verify_package.rb pkg/ctx_cli-0.4.0.gem
79
79
  ```
80
80
 
81
81
  默认任务包括 RSpec、RuboCop 和离线示例。安装验证在独立 GEM_HOME/GEM_PATH 下运行普通与最小 Bundler 应用,检查实际加载来源。CI 参照 ctx_parser 的固定 action 提交和候选制品校验;发布需另行明确授权。
@@ -94,3 +94,5 @@ Input reads default to a 16 MiB byte budget (`CtxCli::Input.read(max_bytes:)`).
94
94
  失败只输出异常类型,返回 2;中断返回 130;诊断流失败不覆盖原始退出码。帮助不加载证据或调用适配器。此类不读取凭据、连接设备或判断业务健康。默认单文件 16 MiB、批次原始正文总计 64 MiB、文件数 10000;宿主可通过 `max_bytes:`、`max_total_bytes:`、`max_files:` 调整。JSON 默认嵌套限制保持开启;上述限制不是进程 RSS 的精确上限。
95
95
 
96
96
  `Collection` 对普通参数/依赖异常只显示类型;宿主需要公开操作提示时使用 `CtxCli::Collection::Error`,其正文必须由宿主构造,不得直接包装外部异常正文、凭据或设备回显。该类型继承 ArgumentError,既有库调用方仍可按参数错误捕获。
97
+
98
+ `CtxCli::Apply` 负责版本计划的校验和、`--item` 选择、终端确认及退出码;通过 `adapter:` 和 `execution:` 注入领域校验、凭据、会话、日志及执行器。ctx_cli 不依赖 ctx_runner 或连接器。
data/docs/migration.md CHANGED
@@ -24,3 +24,7 @@ ctx_cli 初始版本为 0.1.0。首次发布依赖顺序先 ctx_cli,再 net-co
24
24
  `Configuration#sources["fields"]` 的键统一使用 [JSON Pointer](https://www.rfc-editor.org/rfc/rfc6901):`parallel` 改为 `/parallel`,`ssh.port` 的嵌套路径改为 `/ssh/port`。字面键 `ssh.port` 则为 `/ssh.port`,两者拥有独立来源。空键为 `/`;每段中的 `~` 编为 `~0`,`/` 编为 `~1`,不作 Unicode 归一化。
25
25
 
26
26
  来源值仍是 YAML 文件路径;数组整体替换,来源记在数组字段上。空映射合并不覆盖既有非空映射的来源。宿主透传的 `--show-config` 同步采用此结构;外部来源索引调用方须迁移键查找,不提供点分键回退或格式开关。`path_fields` 仍是宿主声明哪些字段要解析为文件路径的独立语法。
27
+
28
+ ## 0.4.0 Apply
29
+
30
+ VXLAN/Wireless 的交互执行入口组合 `CtxCli::Apply`;宿主注入 adapter 和 execution 协作者,领域命令和会话仍由宿主维护。统一要求具名 `--item`、plan.json.sha256 和绑定设备/摘要/所选项的终端确认,取消为 1、预检或执行失败为 2、中断为 130。ctx_cli 自身不加载 Runner 或连接器。
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "digest"
4
+ require "json"
5
+ require_relative "command"
6
+ require_relative "configuration"
7
+ require_relative "terminal"
8
+ require_relative "input"
9
+ require_relative "output"
10
+
11
+ module CtxCli
12
+ # 单项交互变更的终端入口;领域校验与会话、执行账本均通过显式协作者提供。
13
+ class Apply
14
+ def initialize(adapter:, execution:, name:, out: $stdout, error: $stderr, input: $stdin)
15
+ @adapter, @execution_class, @name = adapter, execution, name
16
+ @out, @error, @input = out, error, input
17
+ @output = Output.new(out: out, error: error)
18
+ end
19
+
20
+ def run(argv)
21
+ @execution = nil
22
+ command = options
23
+ values = command.parse(argv)
24
+ return 0 if command.informational?
25
+ terminal = Terminal.new(input: @input, out: @out)
26
+ terminal.require_tty!(@error)
27
+ unless values[:plan] && values[:item] && values[:port].between?(1, 65_535)
28
+ raise ArgumentError, "A plan and explicit --item are required"
29
+ end
30
+ body = Input.read(path: values[:plan])
31
+ sha256 = Digest::SHA256.hexdigest(body)
32
+ unless Input.read(path: "#{values[:plan]}.sha256", max_bytes: 128).strip == sha256
33
+ raise ArgumentError, "Plan checksum verification failed"
34
+ end
35
+ # 外部领域回调不能改变刚验证的计划、选择或连接参数。
36
+ values = Configuration.freeze_tree(Configuration.copy(values))
37
+ document = Configuration.freeze_tree(Configuration.copy(JSON.parse(body)))
38
+ plan = Configuration.freeze_tree(Configuration.copy(@adapter.select_plan(document, item: values[:item])))
39
+ change = @adapter.validate_plan(plan)
40
+ host = plan.fetch("device").fetch("host")
41
+ @out.puts "Target: #{plan['device']['name']}(#{host}); #{plan['scope']}; #{plan['title']}"
42
+ @out.puts "Impact: #{plan['impact']}"
43
+ @out.puts Array(plan["prerequisites"]).map { |value| "Prerequisite: #{value}" }
44
+ @out.puts "Plan SHA256: #{sha256}\nProposed commands:\n#{change.commands.join("\n")}\nConditional rollback (not executed automatically):\n#{change.rollback.join("\n")}"
45
+ token = "APPLY #{host} #{sha256[0, 12]} #{values[:item]}"
46
+ unless terminal.confirm(token: token, prompt: "After reviewing the service policy and maintenance window, enter #{token}; any other input cancels: ")
47
+ @out.puts "Cancelled; no device connection opened."
48
+ return 1
49
+ end
50
+ settings = @adapter.credentials(values)
51
+ journal = @adapter.report(values)
52
+ @execution = @execution_class.new(plan: plan, change: change, journal: journal, plan_sha256: sha256, item: values[:item])
53
+ @execution.run { |operation| @adapter.with_session(plan.fetch("device"), settings, &operation) }
54
+ @out.puts "Configuration readback confirmed; service acceptance is still required. Configuration was not saved to startup configuration. Log: #{journal.directory}/execution.json"
55
+ 0
56
+ rescue Interrupt
57
+ failure("Operation interrupted")
58
+ 130
59
+ rescue StandardError, LoadError => error
60
+ failure("Apply stopped (#{error.class.name})")
61
+ 2
62
+ end
63
+
64
+ def inspect = "#<#{self.class.name}>"
65
+ alias to_s inspect
66
+ def pretty_print(printer) = printer.text(inspect)
67
+
68
+ private
69
+
70
+ def options
71
+ Command.new(banner: "Usage: #{@name} apply --plan FILE --item ID [--env-file FILE] (interactive confirmation required)",
72
+ defaults: { directory: File.join(Dir.pwd, "#{@name}-executions"), port: 22 }, out: @out) do |parser, values|
73
+ parser.on("--plan FILE", "Versioned plan with an adjacent .sha256 checksum") { |value| values[:plan] = value }
74
+ parser.on("--item ID", "Explicitly select one change") { |value| values[:item] = value }
75
+ parser.on("--env-file FILE", "Credentials file; process environment takes precedence") { |value| values[:env_file] = value }
76
+ parser.on("--directory DIR", "Private execution journal directory") { |value| values[:directory] = value }
77
+ parser.on("--port N", Integer, "SSH port, default 22") { |value| values[:port] = value }
78
+ parser.on("-h", "--help", "Show help") { values[:help] = true }
79
+ end
80
+ end
81
+
82
+ def failure(message)
83
+ if @execution&.journal_failed?
84
+ @output.diagnostic "Execution log finalization is unconfirmed; existing checkpoints retained."
85
+ end
86
+ detail = @execution&.started? ? "Effects are uncertain; read back before proceeding. Do not replay commands." : "No service configuration was sent."
87
+ @output.diagnostic "#{message}; #{detail}"
88
+ rescue Interrupt
89
+ nil
90
+ end
91
+ end
92
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CtxCli
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
data/lib/ctx_cli.rb CHANGED
@@ -11,3 +11,4 @@ require_relative "ctx_cli/input"
11
11
  require_relative "ctx_cli/output"
12
12
  require_relative "ctx_cli/collection"
13
13
  require_relative "ctx_cli/review"
14
+ require_relative "ctx_cli/apply"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ctx_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gatework contributors
@@ -23,6 +23,20 @@ dependencies:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
25
  version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: digest
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
26
40
  - !ruby/object:Gem::Dependency
27
41
  name: fileutils
28
42
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +136,7 @@ files:
122
136
  - examples/configuration.rb
123
137
  - examples/offline.rb
124
138
  - lib/ctx_cli.rb
139
+ - lib/ctx_cli/apply.rb
125
140
  - lib/ctx_cli/collection.rb
126
141
  - lib/ctx_cli/command.rb
127
142
  - lib/ctx_cli/configuration.rb