Sha256: cf52a6427c4b320e6f7c98df824fd89dbae4bbdd60e387ac59d247dc81e67084

Contents?: true

Size: 1.63 KB

Versions: 13

Compression:

Stored size: 1.63 KB

Contents

require 'ops_manager_ui_drivers/version16/api'
require 'uaa'

module OpsManagerUiDrivers
  module Version17
    class Api < Version16::Api
      def set_feature_flag(flag_name, value)
        feature_flag_path = File.join('feature_flags', flag_name)

        http.request(put(feature_flag_path, enabled: value))
      end

      def get_products
        http.request(get('v0/available_products'), uaa_token.auth_header)
      end

      def export_installation
        Tempfile.new('installation.zip').tap do |tmpfile|
          http.request(get('v0/installation_asset_collection', uaa_token.auth_header)) do |response|
            response.read_body do |chunk|
              tmpfile.write(chunk)
            end
          end
          tmpfile.close
        end
      end

      private

      def uaa_token
        target_url = @host_uri.to_s + '/uaa'
        token_issuer = CF::UAA::TokenIssuer.new(target_url, 'opsman', nil, {skip_ssl_validation: true})
        token_issuer.owner_password_grant(@username, @password)
      end

      def get(endpoint, token=nil)
        Net::HTTP::Get.new(api_uri(endpoint).request_uri).tap do |get|
          add_auth_to_request(get, token)
        end
      end

      def put(endpoint, form_data, token=nil)
        Net::HTTP::Put.new(api_uri(endpoint).request_uri).tap do |put_request|
          add_auth_to_request(put_request, token)
          put_request.set_form_data(form_data)
        end
      end

      def add_auth_to_request(request, token)
        if token.present?
          request['Authorization'] = token
        else
          request.basic_auth(@username, @password)
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ops_manager_ui_drivers-2.10.7 lib/ops_manager_ui_drivers/version17/api.rb
ops_manager_ui_drivers-2.10.6 lib/ops_manager_ui_drivers/version17/api.rb
ops_manager_ui_drivers-2.10.5 lib/ops_manager_ui_drivers/version17/api.rb
ops_manager_ui_drivers-2.10.4 lib/ops_manager_ui_drivers/version17/api.rb
ops_manager_ui_drivers-2.10.3 lib/ops_manager_ui_drivers/version17/api.rb
ops_manager_ui_drivers-2.10.2 lib/ops_manager_ui_drivers/version17/api.rb
ops_manager_ui_drivers-2.10.1 lib/ops_manager_ui_drivers/version17/api.rb
ops_manager_ui_drivers-2.10.0 lib/ops_manager_ui_drivers/version17/api.rb
ops_manager_ui_drivers-2.9.6 lib/ops_manager_ui_drivers/version17/api.rb
ops_manager_ui_drivers-2.9.5 lib/ops_manager_ui_drivers/version17/api.rb
ops_manager_ui_drivers-2.9.4 lib/ops_manager_ui_drivers/version17/api.rb
ops_manager_ui_drivers-2.9.3 lib/ops_manager_ui_drivers/version17/api.rb
ops_manager_ui_drivers-2.9.2 lib/ops_manager_ui_drivers/version17/api.rb