<commit_before>require 'aws-sdk'
require 'net/dns'

Capistrano::Configuration.instance(:must_exist).load do

  def staging_domain_name(name, *args)

    packet = Net::DNS::Resolver.start(name)
    all_cnames= packet.answer.reject { |p| !p.instance_of? Net::DNS::RR::CNAME }
    cname_record = all_cnames.find { |c| c.name == "#{name}."}
    current_elb = cname_record.value
    fqdn = cname_record.name

    aws_region= fetch(:aws_region, 'us-east-1')
    AWS.config(:access_key_id => fetch(:aws_access_key_id),
               :secret_access_key => fetch(:aws_secret_access_key),
               :ec2_endpoint => "ec2.#{aws_region}.amazonaws.com",
    :elb_endpoint => "elasticloadbalancing.#{aws_region}.amazonaws.com")

    hosted_zone = fetch(:hosted_zone)

    @r53 = AWS::Route53.new

    zone = zone("#{hosted_zone}.")
    record_sets = record_sets(zone)

    staging_prod_ref = find_record(fqdn, record_sets) do |record|
      record[:resource_records].all? { |r| r[:value]!=current_elb } &&
        record[:type]=='CNAME'
    end

    raise "Weighting is not 0 for production staging, please adjust dns weighting to zero before deploying" if staging_prod_ref[:weight].to_i > 0

    staging_prod_record = find_record(staging_prod_ref[:set_identifier], record_sets) do |record|
      record[:type]=='CNAME'
    end

    set(:domain) { staging_prod_record[:name][0..-2] }
  end

  def zone(hosted_zone)
    zone = @r53.client.list_hosted_zones[:hosted_zones].find { |hosted_zones| hosted_zones[:name].downcase==hosted_zone.downcase}
    raise "Could not find hosted zone ${hosted_zone.downcase}" if zone.nil?
    zone
  end

  def find_record(hosted_zone, record_sets, &filter)
    raise "filter required" unless block_given?
    staging_prod = record_sets.find do |record|
      record[:name] == hosted_zone && filter.call(record)
    end<commit_msg>change to return staging env<commit_after>require 'aws-sdk'
require 'net/dns'

Capistrano::Configuration.instance(:must_exist).load do

  def staging_domain_name(name, *args)

    packet = Net::DNS::Resolver.start(name)
    all_cnames= packet.answer.reject { |p| !p.instance_of? Net::DNS::RR::CNAME }
    cname_record = all_cnames.find { |c| c.name == "#{name}."}
    current_elb = cname_record.value
    fqdn = cname_record.name

    aws_region= fetch(:aws_region, 'us-east-1')
    AWS.config(:access_key_id => fetch(:aws_access_key_id),
               :secret_access_key => fetch(:aws_secret_access_key),
               :ec2_endpoint => "ec2.#{aws_region}.amazonaws.com",
    :elb_endpoint => "elasticloadbalancing.#{aws_region}.amazonaws.com")

    hosted_zone = fetch(:hosted_zone)

    @r53 = AWS::Route53.new

    zone = zone("#{hosted_zone}.")
    record_sets = record_sets(zone)

    staging_prod_ref = find_record(fqdn, record_sets) do |record|
      record[:resource_records].all? { |r| r[:value]!=current_elb } &&
        record[:type]=='CNAME'
    end

    raise "Weighting is not 0 for production staging, please adjust dns weighting to zero before deploying" if staging_prod_ref[:weight].to_i > 0

    staging_prod_record = find_record(staging_prod_ref[:set_identifier], record_sets) do |record|
      record[:type]=='CNAME'
    end

    staging_prod_record[:name][0..-2]
  end

  def zone(hosted_zone)
    zone = @r53.client.list_hosted_zones[:hosted_zones].find { |hosted_zones| hosted_zones[:name].downcase==hosted_zone.downcase}
    raise "Could not find hosted zone ${hosted_zone.downcase}" if zone.nil?
    zone
  end

  def find_record(hosted_zone, record_sets, &filter)
    raise "filter required" unless block_given?
    staging_prod = record_sets.find do |record|
      record[:name] == hosted_zone && filter.call(record)
    end
{'fraction_non_alphanumeric': 0.13349514563106796, 'fraction_numerical': 0.007011866235167206, 'mean_word_length': 4.165738161559888, 'pattern_counts': {'":': 0, '<': 3, '<?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': '207913', 'n_tokens_mistral': 1318, 'n_tokens_neox': 1275, 'n_words': 236}