<commit_before>class BrokerManager

  def initialize(client, logger)
    @client = client
    @logger = logger
  end

  SERVICE_BROKER_NAME_IS_TAKEN = 270_002
  SERVICE_BROKER_URL_IS_TAKEN = 270_003

  def find_or_create_service_broker!(broker_name, broker_url, broker_username, broker_password)
    broker               = client.service_broker
    broker.name          = broker_name
    broker.broker_url    = broker_url
    broker.auth_username = broker_username
    broker.auth_password = <PASSWORD>

    begin
      broker.create!
      logger.info "Registered service broker [#{broker.name}]"
    rescue CFoundry::APIError => e
      case e.error_code
      when SERVICE_BROKER_NAME_IS_TAKEN, SERVICE_BROKER_URL_IS_TAKEN
        broker = client.service_broker_by_name(broker_name)
        update_service_broker(broker, broker_url, broker_username, broker_password)
        logger.info "Updated existing service broker [#{broker_name}]"
      else
        raise e
      end
    end

    broker
  end

  def get_services_for_broker(broker_url, broker_username, broker_password)
    credentials = { username: broker_username, password: <PASSWORD> }
    response = HTTParty.get("#{broker_url}/v2/catalog", basic_auth: credentials)
    broker_provided_ids = extract_broker_provided_ids(response)
    client.services.find_all { |s| broker_provided_ids.include?(s.unique_id) }
  end

  def make_services_plans_public(services)
    services.each do |service|
      service.service_plans.each { |sp| make_service_plan_public(sp) }
    end
  end

  def make_service_plan_public(service_plan)
    service_plan.public = true
    service_plan.update!
    logger.info "Made service plan [#{service_plan.name}] public"
  end

  private

  attr_reader :client, :logger

  def update_service_broker(broker, new_url, new_username, new_password)
    broker.broker_url = new_url
    broker.auth_username = new_username
    broker.auth_password = <PASSWORD>
    broker.update!
  end

  def extract_broker_provided_ids(response)
    response['services'].map { |s| s['id'] }
  end
end<commit_msg>Different informational message if plans are already public<commit_after>class BrokerManager

  def initialize(client, logger)
    @client = client
    @logger = logger
  end

  SERVICE_BROKER_NAME_IS_TAKEN = 270_002
  SERVICE_BROKER_URL_IS_TAKEN = 270_003

  def find_or_create_service_broker!(broker_name, broker_url, broker_username, broker_password)
    broker               = client.service_broker
    broker.name          = broker_name
    broker.broker_url    = broker_url
    broker.auth_username = broker_username
    broker.auth_password = <PASSWORD>

    begin
      broker.create!
      logger.info "Registered service broker [#{broker.name}]"
    rescue CFoundry::APIError => e
      case e.error_code
      when SERVICE_BROKER_NAME_IS_TAKEN, SERVICE_BROKER_URL_IS_TAKEN
        broker = client.service_broker_by_name(broker_name)
        update_service_broker(broker, broker_url, broker_username, broker_password)
        logger.info "Updated existing service broker [#{broker_name}]"
      else
        raise e
      end
    end

    broker
  end

  def get_services_for_broker(broker_url, broker_username, broker_password)
    credentials = { username: broker_username, password: <PASSWORD> }
    response = HTTParty.get("#{broker_url}/v2/catalog", basic_auth: credentials)
    broker_provided_ids = extract_broker_provided_ids(response)
    client.services.find_all { |s| broker_provided_ids.include?(s.unique_id) }
  end

  def make_services_plans_public(services)
    services.each do |service|
      service.service_plans.each { |sp| make_service_plan_public(sp) }
    end
  end

  def make_service_plan_public(service_plan)
    if service_plan.public
      logger.info "Service plan [#{service_plan.name}] is already public"
    else
      service_plan.public = true
      service_plan.update!
      logger.info "Made service plan [#{service_plan.name}] public"
    end
  end

  private

  attr_reader :client, :logger

  def update_service_broker(broker, new_url, new_username, new_password)
    broker.broker_url = new_url
    broker.auth_username = new_username
    broker.auth_password = <PASSWORD>
    broker.update!
  end

  def extract_broker_provided_ids(response)
    response['services'].map { |s| s['id'] }
  end
end
{'fraction_non_alphanumeric': 0.07813222376329172, 'fraction_numerical': 0.006010171058714748, 'mean_word_length': 3.765418502202643, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2810024', 'n_tokens_mistral': 1434, 'n_tokens_neox': 1401, 'n_words': 273}