<commit_before>module Paasal
  module Adapters
    module V1
      class Openshift2Adapter < Paasal::Adapters::BaseAdapter
        include Paasal::Logging

        def initialize(endpoint_url, check_certificates = true)
          super(endpoint_url, check_certificates)
        end

        def authenticate(username, password)
          log.debug "Skip openshift authentication but create header for #{@endpoint_url}"
          { 'Authorization' => 'Basic ' + ["#{username}:#{password}"].pack('m*').gsub(/\n/, '') }
        end

        def applications
          response = get('/applications')
          apps = []
          response.body[:data].each do |application|
            apps << application(application[:id])
          end
          apps
        end

        def application(application_id)
          app_response = get("/application/#{application_id}")
          app_gear_groups = get("/application/#{application_id}/gear_groups")
          to_paasal_app app_response.body[:data], app_gear_groups.body[:data]
        end

        def default_deployment(application_id)
          get("/app/#{application_id}/deployment/default")
        end

        def create_application(entity_hash)
          # TODO: implement me
        end
<commit_msg>changed openshift authentication to make dummy request to fail when credentials are invalid<commit_after>module Paasal
  module Adapters
    module V1
      class Openshift2Adapter < Paasal::Adapters::BaseAdapter
        include Paasal::Logging

        def initialize(endpoint_url, check_certificates = true)
          super(endpoint_url, check_certificates)
        end

        def authenticate(username, password)
          # access the user information to prove authentication is granted
          response = Excon.get("#{@endpoint_url}/user",
                               headers: { 'Accept' => 'application/json; version=1.7',
                                          'Authorization' => 'Basic ' +
                                              ["#{username}:#{password}"].pack('m*').gsub(/\n/, '') })

          # Openshift returns 401 for invalid credentials
          fail Errors::AuthenticationError, 'Openshift says the credentials are invalid' if response.status == 401

          # once authenticated, return the header
          { 'Authorization' => 'Basic ' + ["#{username}:#{password}"].pack('m*').gsub(/\n/, '') }
        end

        def applications
          response = get('/applications')
          apps = []
          response.body[:data].each do |application|
            apps << application(application[:id])
          end
          apps
        end

        def application(application_id)
          app_response = get("/application/#{application_id}")
          app_gear_groups = get("/application/#{application_id}/gear_groups")
          to_paasal_app app_response.body[:data], app_gear_groups.body[:data]
        end

        def default_deployment(application_id)
          get("/app/#{application_id}/deployment/default")
        end

        def create_application(entity_hash)
          # TODO: implement me
        end

{'fraction_non_alphanumeric': 0.10678674815053071, 'fraction_numerical': 0.0038597619813444837, 'mean_word_length': 2.2463465553235906, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3010731', 'n_tokens_mistral': 808, 'n_tokens_neox': 785, 'n_words': 177}