Class: Kitsune::Kit::Commands::SetupUser

Inherits:
Thor
  • Object
show all
Defined in:
lib/kitsune/kit/commands/setup_user.rb

Instance Method Summary collapse

Instance Method Details

#createObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/kitsune/kit/commands/setup_user.rb', line 17

def create
  filled_options = Kitsune::Kit::OptionsBuilder.build(
    options,
    required: [:server_ip],
    defaults: Kitsune::Kit::Defaults.ssh
  )

  with_ssh_connection(false, filled_options) do |ssh|
    perform_setup(ssh)
  end
end

#rollbackObject



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
# File 'lib/kitsune/kit/commands/setup_user.rb', line 30

def rollback
  filled_options = Kitsune::Kit::OptionsBuilder.build(
    options,
    required: [:server_ip],
    defaults: Kitsune::Kit::Defaults.ssh
  )

  server = filled_options[:server_ip]
  port   = filled_options[:ssh_port]
  key    = File.expand_path(filled_options[:ssh_key_path])

  # First, attempt SSH config restore as 'deploy'
  begin
    with_ssh_connection(true, filled_options) do |ssh|
      perform_rollback_config(ssh)
    end
  rescue StandardError => e
    say "⚠️ Skipping SSH config restore: #{e.message}", :yellow
  end

  # Then reconnect as 'root' to remove sudoers and delete user
  say "🔑 Reconnecting as root@#{server}:#{port}", :green
  Net::SSH.start(server, 'root', port: port, keys: [key], non_interactive: true) do |ssh|
    perform_rollback_cleanup(ssh)
  end
  say "✅ Rollback completed", :green
end