Class: Kontena::Cli::Vault::ImportCommand
- Inherits:
-
Kontena::Command
- Object
- Clamp::Command
- Kontena::Command
- Kontena::Cli::Vault::ImportCommand
- Includes:
- Common, GridOptions
- Defined in:
- lib/kontena/cli/vault/import_command.rb
Constant Summary collapse
- UPDATE_CMD =
'vault update --upsert --silent %{key} %{value}'- DELETE_CMD =
'vault rm --silent --force %{key}'
Instance Attribute Summary
Attributes inherited from Kontena::Command
#arguments, #exit_code, #result
Instance Method Summary collapse
Methods included from GridOptions
Methods included from Common
#access_token=, #add_master, #any_key_to_continue, #any_key_to_continue_with_timeout, #api_url, #api_url=, #api_url_version, #ask, #clear_current_grid, #client, #cloud_auth?, #cloud_client, #config, #confirm, #confirm_command, #current_account, #current_grid, #current_grid=, #current_master, #current_master=, #current_master_index, #display_account_login_info, #display_login_info, #display_logo, #display_master_login_info, #error, #exit_with_error, #kontena_account, #logger, #pastel, #print, #prompt, #puts, #require_api_url, #require_current_account, #require_current_grid, #require_current_master, #require_token, #reset_client, #reset_cloud_client, #running_silent?, #running_verbose?, #settings, #settings_filename, #spinner, #sprint, #sputs, #stdin_input, #use_refresh_token, #vfakespinner, #vputs, #vspinner, #warning, #yes?
Methods inherited from Kontena::Command
banner, callback_matcher, #help_requested?, inherited, load_subcommand, requires_current_account_token, requires_current_account_token?, requires_current_grid, requires_current_grid?, requires_current_master, requires_current_master?, requires_current_master_token, requires_current_master_token?, #run, #run_callbacks, #verify_current_account_token, #verify_current_grid, #verify_current_master, #verify_current_master_token
Instance Method Details
#execute ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/kontena/cli/vault/import_command.rb', line 29 def execute require_current_grid updates = [] deletes = [] parsed_input.map do |k,v| case v when String, Numeric, TrueClass, FalseClass if empty_is_null? && v.to_s.empty? deletes << k.to_s else updates << [k.to_s, v.to_s] end when NilClass deletes << k.to_s else exit_with_error "Invalid value type #{v.class} for #{k}." end end if updates.empty? && deletes.empty? exit_with_error "No secrets loaded" end unless forced? puts "About to.." puts " * #{Kontena.pastel.yellow("IMPORT")} #{updates.size} secret#{"s" if updates.size > 1}" unless updates.empty? puts " * #{Kontena.pastel.red("DELETE")} #{deletes.size} secret#{"s" if deletes.size > 1}" unless deletes.empty? confirm end unless updates.empty? spinner "Updating #{updates.size} secrets" do |spin| updates.each do |pair| result = Kontena.run(UPDATE_CMD % { key: pair.first.shellescape, value: pair.last.shellescape }) spin.fail! unless result.zero? end end end unless deletes.empty? || skip_null? spinner "Deleting #{deletes.size} secrets" do |spin| deletes.map(&:shellescape).each do |del| result = Kontena.run(DELETE_CMD % { key: del }) spin.fail! unless result.zero? end end end end |
#input ⇒ Object
25 26 27 |
# File 'lib/kontena/cli/vault/import_command.rb', line 25 def input path ? File.read(path) : stdin_input("Enter secrets YAML", :multiline) end |
#parsed_input ⇒ Object
21 22 23 |
# File 'lib/kontena/cli/vault/import_command.rb', line 21 def parsed_input json? ? JSON.load(input) : YAML.safe_load(input) end |