Class: Aptible::Api::Operation
- Defined in:
- lib/aptible/api/operation.rb
Instance Method Summary collapse
- #failed? ⇒ Boolean
- #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
46 47 48 |
# File 'lib/aptible/api/operation.rb', line 46 def failed? status == 'failed' end |
#succeeded? ⇒ Boolean
42 43 44 |
# File 'lib/aptible/api/operation.rb', line 42 def succeeded? status == 'succeeded' end |
#user ⇒ Object
35 36 37 38 39 40 |
# File 'lib/aptible/api/operation.rb', line 35 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
50 51 52 53 54 55 56 57 58 59 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 |
# File 'lib/aptible/api/operation.rb', line 50 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 = 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 |