Sha256: 3e94a8155931a739dba8dd4c4993850d324891f6e9ad2da959f41c6a1071e291

Contents?: true

Size: 1.14 KB

Versions: 102

Compression:

Stored size: 1.14 KB

Contents

require 'net/https'

module OpsManagerUiDrivers
  module Version14
    class Api
      def initialize(host_uri:, username:, password:)
        @host_uri = URI.parse(host_uri) # we expect "proto://host(:port)"
        @username = username
        @password = password
      end

      def export_installation
        tmpfile = Tempfile.new('installation.zip')
        http.request(get('installation_asset_collection')) do |response|
          response.read_body do |chunk|
            tmpfile.write(chunk)
          end
        end
        tmpfile.close
        tmpfile
      end

      private

      def http
        Net::HTTP.new(@host_uri.host, @host_uri.port).tap do |http|
          http.use_ssl      = @host_uri.is_a?(URI::HTTPS)
          http.verify_mode  = OpenSSL::SSL::VERIFY_NONE
          http.read_timeout = 1800
        end
      end

      def get(endpoint)
        Net::HTTP::Get.new(api_uri(endpoint).request_uri).tap do |get|
          get.basic_auth(@username, @password)
        end
      end

      def api_uri(endpoint)
        URI.parse(
          URI.join(@host_uri.to_s, File.join('api', endpoint)).to_s
        )
      end
    end
  end
end

Version data entries

102 entries across 102 versions & 1 rubygems

Version Path
ops_manager_ui_drivers-2.42.0 lib/ops_manager_ui_drivers/version14/api.rb
ops_manager_ui_drivers-2.41.0 lib/ops_manager_ui_drivers/version14/api.rb
ops_manager_ui_drivers-2.40.1 lib/ops_manager_ui_drivers/version14/api.rb
ops_manager_ui_drivers-2.40.0 lib/ops_manager_ui_drivers/version14/api.rb
ops_manager_ui_drivers-2.39.0 lib/ops_manager_ui_drivers/version14/api.rb
ops_manager_ui_drivers-2.38.0 lib/ops_manager_ui_drivers/version14/api.rb
ops_manager_ui_drivers-2.37.0 lib/ops_manager_ui_drivers/version14/api.rb
ops_manager_ui_drivers-2.36.0 lib/ops_manager_ui_drivers/version14/api.rb
ops_manager_ui_drivers-2.35.2 lib/ops_manager_ui_drivers/version14/api.rb
ops_manager_ui_drivers-2.35.1 lib/ops_manager_ui_drivers/version14/api.rb
ops_manager_ui_drivers-2.35.0 lib/ops_manager_ui_drivers/version14/api.rb
ops_manager_ui_drivers-2.34.1 lib/ops_manager_ui_drivers/version14/api.rb
ops_manager_ui_drivers-2.34.0 lib/ops_manager_ui_drivers/version14/api.rb
ops_manager_ui_drivers-2.33.1 lib/ops_manager_ui_drivers/version14/api.rb
ops_manager_ui_drivers-2.33.0 lib/ops_manager_ui_drivers/version14/api.rb
ops_manager_ui_drivers-2.32.1 lib/ops_manager_ui_drivers/version14/api.rb
ops_manager_ui_drivers-2.32.0 lib/ops_manager_ui_drivers/version14/api.rb
ops_manager_ui_drivers-2.31.3 lib/ops_manager_ui_drivers/version14/api.rb
ops_manager_ui_drivers-2.31.2 lib/ops_manager_ui_drivers/version14/api.rb
ops_manager_ui_drivers-2.31.1 lib/ops_manager_ui_drivers/version14/api.rb