Class: Aptible::Api::Operation

Inherits:
Resource
  • Object
show all
Defined in:
lib/aptible/api/operation.rb

Instance Method Summary collapse

Methods inherited from Resource

#namespace, #root_url

Instance Method Details

#failed?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/aptible/api/operation.rb', line 56

def failed?
  status == 'failed'
end

#logs_urlObject



48
49
50
# File 'lib/aptible/api/operation.rb', line 48

def logs_url
  links['logs'].href
end

#succeeded?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/aptible/api/operation.rb', line 52

def succeeded?
  status == 'succeeded'
end

#userObject



41
42
43
44
45
46
# File 'lib/aptible/api/operation.rb', line 41

def user
  auth = Aptible::Auth::User.new(token: token, headers: headers)
  auth.find_by_url(links['user'].href)
rescue StandardError
  nil
end

#with_ssh_cmd(private_key_file, host: nil, port: nil, host_key: nil) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/aptible/api/operation.rb', line 60

def with_ssh_cmd(private_key_file, host: nil, port: nil, host_key: nil)
  # We expect that the public key will be found next to the private key,
  # which is also what SSH itself expects. If that's not the case, then
  # we'll just fail. The Aptible CLI will always ensure credentials are
  # set up properly (other consumers are of course responsible for doing
  # the same!).
  public_key_file = "#{private_key_file}.pub"

  private_key = File.read(private_key_file)
  public_key = File.read(public_key_file)

  connection = create_ssh_portal_connection!(ssh_public_key: public_key)
  certificate = connection.ssh_certificate_body

  stack = .stack
  host ||= stack.ssh_portal_host
  port ||= stack.ssh_portal_port
  host_key ||= stack.ssh_host_rsa_public_key

  with_temporary_known_hosts(
    host, port, host_key
  ) do |known_hosts_file|
    with_temporary_id(private_key, public_key, certificate) do |id_file|
      cmd = [
        'ssh',
        "#{connection.ssh_user}@#{host}",
        '-p', port.to_s,
        '-i', id_file,
        '-o', 'IdentitiesOnly=yes',
        '-o', "UserKnownHostsFile=#{known_hosts_file}",
        '-o', 'StrictHostKeyChecking=yes'
      ]

      # If we aren't allowed to create a pty, then we shouldn't try to
      # allocate once, or we'll get an awkward error.
      cmd << '-T' unless connection.ssh_pty

      yield cmd, connection
    end
  end
end