Class: RKSeal::CLI
- Inherits:
-
Thor
- Object
- Thor
- RKSeal::CLI
- Defined in:
- lib/rkseal/cli.rb
Overview
Thor-based command-line interface: parses ARGV, validates options, and dispatches to the orchestration commands. It is intentionally thin – it maps flags/positionals onto RKSeal::Commands::Create / RKSeal::Commands::Edit, prints their RKSeal::Commands::Result, and turns the gem’s fail-fast Errors into a single clean line + non-zero exit. No business logic lives here.
rubocop:disable Metrics/ClassLength – length here is Thor’s declarative ‘method_option` surface (every flag for both subcommands plus their long_desc help text), not logic. The two command bodies stay thin and delegate straight to the orchestration classes.
Constant Summary collapse
- SCOPE_SYMBOLS =
kubeseal’s ‘–scope` strings, as exposed on the CLI, mapped to the symbols the command/adapter layers expect. Thor does not underscore enum values.
{ "strict" => :strict, "namespace-wide" => :namespace_wide, "cluster-wide" => :cluster_wide }.freeze
Class Method Summary collapse
-
.dispatch(*args) ⇒ void
Entry point used by ‘exe/rkseal`, and Thor’s internal command router.
-
.exit_on_failure? ⇒ Boolean
Make argument/usage errors (and our rescued errors) exit non-zero rather than return 0, so the CLI is shell-script friendly.
-
.thor_dispatch ⇒ Object
‘dispatch` is also Thor’s own internal 4-arg command router, which Thor.start calls.
Instance Method Summary collapse
-
#create(namespace, name) ⇒ void
Author a new SealedSecret.
-
#edit(namespace, name) ⇒ void
Edit an existing SealedSecret.
-
#list(namespace = nil) ⇒ void
List SealedSecrets (read-only, metadata only).
-
#reencrypt(namespace, name) ⇒ void
Re-encrypt an existing SealedSecret to the newest controller key.
-
#validate(namespace = nil, name = nil) ⇒ void
Validate a SealedSecret (local <NAME>.yaml, or –file <path>).
- #version ⇒ void
-
#view(namespace, name) ⇒ void
Print the live Secret for a SealedSecret (read-only).
Class Method Details
.dispatch(*args) ⇒ void
This method returns an undefined value.
Entry point used by ‘exe/rkseal`, and Thor’s internal command router.
Dual-role on arity:
- called as `dispatch(argv)` (a single Array, from `exe/rkseal`): run
{Thor.start} and translate any deliberately-raised {RKSeal::Error}
into a one-line stderr message with a non-zero exit -- no backtrace.
Thor's own parse errors keep their {exit_on_failure?} handling;
unexpected exceptions propagate.
- called by Thor internally (`dispatch(meth, args, opts, config)`):
delegate to Thor's preserved router unchanged.
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rkseal/cli.rb', line 52 def dispatch(*args) return thor_dispatch(*args) unless args.length == 1 && args.first.is_a?(Array) begin start(args.first) rescue RKSeal::Error => e warn(e.) exit(1) end end |
.exit_on_failure? ⇒ Boolean
Make argument/usage errors (and our rescued errors) exit non-zero rather than return 0, so the CLI is shell-script friendly.
28 29 30 |
# File 'lib/rkseal/cli.rb', line 28 def self.exit_on_failure? true end |
.thor_dispatch ⇒ Object
‘dispatch` is also Thor’s own internal 4-arg command router, which Thor.start calls. Preserve it under an alias so our public 1-arg entry point can reuse the name (as the gem’s contract requires) without clobbering Thor’s routing.
37 |
# File 'lib/rkseal/cli.rb', line 37 alias thor_dispatch dispatch |
Instance Method Details
#create(namespace, name) ⇒ void
This method returns an undefined value.
Author a new SealedSecret.
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/rkseal/cli.rb', line 97 def create(namespace, name) validate_identifiers!(namespace, name) result = Commands::Create.new( namespace: namespace, name: name, scope: scope_symbol, type: ["type"], from_file: parsed_from_file, no_edit: ["no-edit"], string_data: ["string-data"], kubeseal: build_kubeseal ).call report(result) end |
#edit(namespace, name) ⇒ void
This method returns an undefined value.
Edit an existing SealedSecret. Reads current values from the cluster; if the Secret is absent there but a local <NAME>.yaml exists, automatically falls back to the offline local edit. ‘–local` forces the offline path.
171 172 173 174 175 |
# File 'lib/rkseal/cli.rb', line 171 def edit(namespace, name) validate_identifiers!(namespace, name) result = ["local"] ? edit_local(namespace, name) : edit_auto(namespace, name) report(result) end |
#list(namespace = nil) ⇒ void
This method returns an undefined value.
List SealedSecrets (read-only, metadata only).
291 292 293 294 |
# File 'lib/rkseal/cli.rb', line 291 def list(namespace = nil) Secret.validate_identifier!(field: "namespace", value: namespace) if namespace say(Commands::List.new(namespace: namespace, kubectl: Kubectl.new).call) end |
#reencrypt(namespace, name) ⇒ void
This method returns an undefined value.
Re-encrypt an existing SealedSecret to the newest controller key.
205 206 207 208 209 210 211 212 213 |
# File 'lib/rkseal/cli.rb', line 205 def reencrypt(namespace, name) validate_identifiers!(namespace, name) result = Commands::Reencrypt.new( namespace: namespace, name: name, deploy: ["deploy"], assume_yes: ["yes"], kubectl: Kubectl.new, kubeseal: build_kubeseal ).call report(result) end |
#validate(namespace = nil, name = nil) ⇒ void
This method returns an undefined value.
Validate a SealedSecret (local <NAME>.yaml, or –file <path>).
240 241 242 243 244 245 246 247 248 249 |
# File 'lib/rkseal/cli.rb', line 240 def validate(namespace = nil, name = nil) file = ["file"] raise InvalidInputError, "give NAMESPACE NAME or --file <path>" if file.nil? && name.nil? validate_identifiers!(namespace, name) unless file path = Commands::Validate.new( namespace: namespace, name: name, file: file, kubeseal: build_kubeseal ).call say("SealedSecret #{path} is valid.") end |
#version ⇒ void
This method returns an undefined value.
299 300 301 |
# File 'lib/rkseal/cli.rb', line 299 def version say("rkseal #{RKSeal::VERSION}") end |
#view(namespace, name) ⇒ void
This method returns an undefined value.
Print the live Secret for a SealedSecret (read-only).
269 270 271 272 273 274 275 |
# File 'lib/rkseal/cli.rb', line 269 def view(namespace, name) validate_identifiers!(namespace, name) manifest = Commands::View.new( namespace: namespace, name: name, reveal: ["reveal"], kubectl: Kubectl.new ).call say(manifest) end |