Class: RKSeal::Commands::Reencrypt
- Inherits:
-
Object
- Object
- RKSeal::Commands::Reencrypt
- Defined in:
- lib/rkseal/commands/reencrypt.rb
Overview
Orchestrates the ‘rkseal reencrypt <namespace> <secret-name>` flow.
Re-encrypts an existing SealedSecret onto the controller’s newest sealing key without ever exposing plaintext (‘kubeseal –re-encrypt`). The input is the SealedSecret itself, not the unsealed Secret – so unlike `edit`, this flow never touches `$EDITOR`, a RAM workspace, or cluster Secret values.
Input resolution, in order:
1. the local `<name>.yaml` in the output directory (a previous run);
2. otherwise the live SealedSecret via {RKSeal::Kubectl#get_sealedsecret}.
If neither exists, fail fast and point the user at ‘create`.
Deploy is opt-in and identical to ‘edit`: RKSeal::ContextGuard surfaces the active context and confirms before `kubectl apply` (skipped with `assume_yes`).
Instance Attribute Summary collapse
- #deploy ⇒ Boolean readonly
- #name ⇒ String readonly
- #namespace ⇒ String readonly
Instance Method Summary collapse
-
#call ⇒ RKSeal::Commands::Result
Run the re-encrypt flow end to end.
-
#initialize(namespace:, name:, deploy: false, assume_yes: false, kubectl: Kubectl.new, kubeseal: Kubeseal.new, context_guard: nil, prompt: Thor::Shell::Basic.new, output_dir: Dir.pwd) ⇒ Reencrypt
constructor
A new instance of Reencrypt.
Constructor Details
#initialize(namespace:, name:, deploy: false, assume_yes: false, kubectl: Kubectl.new, kubeseal: Kubeseal.new, context_guard: nil, prompt: Thor::Shell::Basic.new, output_dir: Dir.pwd) ⇒ Reencrypt
Returns a new instance of Reencrypt.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rkseal/commands/reencrypt.rb', line 44 def initialize(namespace:, name:, deploy: false, assume_yes: false, kubectl: Kubectl.new, kubeseal: Kubeseal.new, context_guard: nil, prompt: Thor::Shell::Basic.new, output_dir: Dir.pwd) @namespace = namespace @name = name @deploy = deploy @assume_yes = assume_yes @kubectl = kubectl @kubeseal = kubeseal @context_guard = context_guard @prompt = prompt @output_dir = output_dir end |
Instance Attribute Details
#deploy ⇒ Boolean (readonly)
31 32 33 |
# File 'lib/rkseal/commands/reencrypt.rb', line 31 def deploy @deploy end |
#name ⇒ String (readonly)
29 30 31 |
# File 'lib/rkseal/commands/reencrypt.rb', line 29 def name @name end |
#namespace ⇒ String (readonly)
27 28 29 |
# File 'lib/rkseal/commands/reencrypt.rb', line 27 def namespace @namespace end |
Instance Method Details
#call ⇒ RKSeal::Commands::Result
Run the re-encrypt flow end to end.
Side effects: reads the local ‘<name>.yaml` or the cluster SealedSecret; shells out to `kubeseal –re-encrypt`; writes `<name>.yaml`; and, only when #deploy is true and the operator confirms, runs `kubectl apply`.
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rkseal/commands/reencrypt.rb', line 69 def call @kubectl.ensure_available! @kubeseal.ensure_available! reencrypted = @kubeseal.re_encrypt(source_sealed_yaml) path = write_manifest(reencrypted) deployed = @deploy && deploy_confirmed? @kubectl.apply(file: path) if deployed Result.new(secret_name: @name, namespace: @namespace, output_path: path, deployed: deployed) end |