Class: UnimatrixCLI::Citadel::Instance::ScpCommand

Inherits:
CitadelCommand show all
Defined in:
lib/unimatrix_cli/citadel/instance/scp_command.rb

Constant Summary collapse

DIRECTIONS =
%w( from to )

Constants inherited from CitadelCommand

CitadelCommand::APIS, CitadelCommand::PRIVATE_SUBNETS, CitadelCommand::ROOT

Instance Method Summary collapse

Methods inherited from CitadelCommand

#account, #aws_client, #instance_details, #instance_list, #instances_by_zone, #key, #load_environment, #user, #write_instance_details

Methods inherited from UnimatrixCLI::Command

available_commands, descendants, #initialize, #read_file, #validate, #validate_collection, #write

Methods included from UnimatrixParser

included

Constructor Details

This class inherits a constructor from UnimatrixCLI::Command

Instance Method Details

#executeObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/unimatrix_cli/citadel/instance/scp_command.rb', line 16

def execute
  if @options[ :direction ] && 
     DIRECTIONS.include?( @options[ :direction ] )
    super
    execute_scp
  else
    write( 
      message: "#{ @options[ :direction ] } is not a valid direction", 
      error: true
    )
  end
end

#execute_scpObject




31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/unimatrix_cli/citadel/instance/scp_command.rb', line 31

def execute_scp
  user_to_use = @options[ :user ] || user
  base = "scp -o StrictHostKeyChecking=no -i #{ key } "

  if @options[ :direction ] == 'to'
    command = base + "#{ @options[ :local_file ] } #{ user_to_use }@" +
      "#{ instance_details[ :dns ] }:#{ @options[ :remote_file ] }"
  else
    command = base + "#{ user_to_use }@#{ instance_details[ :dns ] }" +
      ":#{ @options[ :remote_file ] } #{ @options[ :local_file ] }"
  end

  exec command
end