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
48 49 50 |
# File 'lib/aptible/api/operation.rb', line 48 def failed? status == 'failed' end |
#succeeded? ⇒ Boolean
44 45 46 |
# File 'lib/aptible/api/operation.rb', line 44 def succeeded? status == 'succeeded' end |
#user ⇒ Object
37 38 39 40 41 42 |
# File 'lib/aptible/api/operation.rb', line 37 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
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 91 92 |
# File 'lib/aptible/api/operation.rb', line 52 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 |