<commit_before>module Sources
  class Joyent < Sources::Fog
    class << self
      def required_fields
        super.merge({
          username: :string,
          password: :password,
          datacenter: :string,
          image_id: :string,
          package_id: :string
        })
      end
    end

    # Connect to Joyent to make sure our config is valid
    # You cannot verify custom images through Fog, but an incorrect image
    # UUID will cause an error when creating the server.
    def validate_config!
      if !config['image_id'].nil?
        connection.flavors.each do |f|
          if f.name == config['package_id']
            return true
          end
        end
      end
      return false
    end

    private

    # server_is_proxy_type?(server)
    # given a server, determine if it is running a proxy
    def server_is_proxy_type?(server)
      return server.image == config['image_id'] \
        && server.package == config['package_id']
    end

    def connection
      @connection ||= ::Fog::Compute.new(
        :provider => 'Joyent',
        :joyent_username => config['username'],
        :joyent_password => config['password'],
        :joyent_url => config['datacenter']
      )
    end

    def server_by_proxy(proxy)
      return NoServer unless validate_config!
      server = connection.servers.select do |s|
        s.primary_ip == proxy.host
      end.first

      server || NoServer
    end

    def create_server
      timestamp = Time.now.strftime("%Y.%m.%d-%H.%M.%S")
      server_output = connection.servers.create(
        name: "proxy-#{timestamp}-#{SecureRandom.uuid}",
        package: config['package_id'],
        image: config['image_id']
      )
    # Generally get this error when we've hit our limit on # of servers
    # but Joyent will produce errors here as well if form data is incorrect
    rescue => e
      puts(e)
      add_error(e.message)
      NoServer
    end
  end
end<commit_msg>removed print<commit_after>module Sources
  class Joyent < Sources::Fog
    class << self
      def required_fields
        super.merge({
          username: :string,
          password: :password,
          datacenter: :string,
          image_id: :string,
          package_id: :string
        })
      end
    end

    # Connect to Joyent to make sure our config is valid
    # You cannot verify custom images through Fog, but an incorrect image
    # UUID will cause an error when creating the server.
    def validate_config!
      if !config['image_id'].nil?
        connection.flavors.each do |f|
          if f.name == config['package_id']
            return true
          end
        end
      end
      return false
    end

    private

    # server_is_proxy_type?(server)
    # given a server, determine if it is running a proxy
    def server_is_proxy_type?(server)
      return server.image == config['image_id'] \
        && server.package == config['package_id']
    end

    def connection
      @connection ||= ::Fog::Compute.new(
        :provider => 'Joyent',
        :joyent_username => config['username'],
        :joyent_password => config['password'],
        :joyent_url => config['datacenter']
      )
    end

    def server_by_proxy(proxy)
      return NoServer unless validate_config!
      server = connection.servers.select do |s|
        s.primary_ip == proxy.host
      end.first

      server || NoServer
    end

    def create_server
      timestamp = Time.now.strftime("%Y.%m.%d-%H.%M.%S")
      server_output = connection.servers.create(
        name: "proxy-#{timestamp}-#{SecureRandom.uuid}",
        package: config['package_id'],
        image: config['image_id']
      )
    # Generally get this error when we've hit our limit on # of servers
    # but Joyent will produce errors here as well if form data is incorrect
    rescue => e
      add_error(e.message)
      NoServer
    end
  end
end
{'fraction_non_alphanumeric': 0.09717223650385604, 'fraction_numerical': 0.0, 'mean_word_length': 2.2077493816982687, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '5803456', 'n_tokens_mistral': 1122, 'n_tokens_neox': 1105, 'n_words': 329}