Class: Envirobly::ContainerShell

Inherits:
Object
  • Object
show all
Defined in:
lib/envirobly/container_shell.rb

Constant Summary collapse

AWS_ENV =
[
  "AWS_ACCESS_KEY_ID='%s'",
  "AWS_SECRET_ACCESS_KEY='%s'",
  "AWS_SESSION_TOKEN='%s'"
]
SSH =
[
  "ssh -i %s",
  "-o StrictHostKeyChecking=no",
  "-o UserKnownHostsFile=/dev/null",
  "-o SendEnv=ENVIROBLY_SERVICE_INTERACTIVE_SHELL",
  "-o SendEnv=ENVIROBLY_SERVICE_SHELL_USER",
  "-o ProxyCommand='aws ec2-instance-connect open-tunnel --instance-id %s --region %s'"
]
USER_AND_HOST =
"envirobly-service@%s"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service_name, options, shell:) ⇒ ContainerShell

Returns a new instance of ContainerShell.



22
23
24
25
26
27
28
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
# File 'lib/envirobly/container_shell.rb', line 22

def initialize(service_name, options, shell:)
  @service_name = service_name
  @options = options

  commit = Git::Commit.new "HEAD"
   = Defaults::Account.new(shell:)
  default_project = Defaults::Project.new(shell:)

  target = Target.new(
    default_account_id: .value,
    default_project_id: default_project.value,
    default_project_name: Defaults::Project.dirname,
    default_environ_name: commit.current_branch,
    account_id: options.,
    project_id: options.project_id,
    project_name: options.project_name,
    environ_name: options.environ_name
  )

  if target.missing_params.include?(:account_id)
    target. = .require_value
  end

  target.ignored_params.each do |param|
    shell.say "--#{param.to_s.parameterize} ignored, due to other arguments overriding it"
  end

  @params = {
    account_id: target.,
    project_id: target.project_id,
    project_name: target.project_name,
    environ_name: target.environ_name,
    service_name:,
    instance_slot: options.instance_slot || 0
  }

  if options.project_name.blank? && options..blank? && options.project_id.blank?
    @params[:project_id] = Defaults::Project.new.value
  end
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



20
21
22
# File 'lib/envirobly/container_shell.rb', line 20

def options
  @options
end

#service_nameObject (readonly)

Returns the value of attribute service_name.



20
21
22
# File 'lib/envirobly/container_shell.rb', line 20

def service_name
  @service_name
end

Instance Method Details

#exec(command = nil) ⇒ Object



63
64
65
66
67
# File 'lib/envirobly/container_shell.rb', line 63

def exec(command = nil)
  with_private_key do
    system join(env_vars, ssh, user_and_host, command)
  end
end

#rsync(source, destination) ⇒ Object



69
70
71
72
73
74
75
76
77
78
# File 'lib/envirobly/container_shell.rb', line 69

def rsync(source, destination)
  with_private_key do
    system join(
      env_vars,
      %(rsync #{options.args} -e "#{ssh}"),
      source.sub("#{service_name}:", "#{user_and_host}:"),
      destination.sub("#{service_name}:", "#{user_and_host}:")
    )
  end
end