Class: Aptible::Api::Operation
- Defined in:
- lib/aptible/api/operation.rb
Instance Method Summary collapse
- #failed? ⇒ Boolean
- #logs_url ⇒ Object
- #succeeded? ⇒ Boolean
- #user ⇒ Object
- #with_ssh_cmd(private_key_file, host: nil, port: nil, host_key: nil) ⇒ Object
Methods inherited from Resource
Instance Method Details
#failed? ⇒ Boolean
71 72 73 |
# File 'lib/aptible/api/operation.rb', line 71 def failed? status == 'failed' end |
#logs_url ⇒ Object
63 64 65 |
# File 'lib/aptible/api/operation.rb', line 63 def logs_url links['logs'].href end |
#succeeded? ⇒ Boolean
67 68 69 |
# File 'lib/aptible/api/operation.rb', line 67 def succeeded? status == 'succeeded' end |
#user ⇒ Object
56 57 58 59 60 61 |
# File 'lib/aptible/api/operation.rb', line 56 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
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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/aptible/api/operation.rb', line 75 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 # Backups can be restored across stacks, and the operation executes # on the destiantion stack. Assuming all future cross-stack operations # will behave the same way, fingers crossed they'll "just work" stack = destination_account.try(&:stack) || account.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 |