<commit_before>require 'aws-sdk'

class Stack
  attr_accessor :stack, :name, :deployed

  SUCESS_STATES  = ["CREATE_COMPLETE", "UPDATE_COMPLETE"]
  FAILURE_STATES = ["CREATE_FAILED", "DELETE_FAILED", "UPDATE_ROLLBACK_FAILED", "ROLLBACK_FAILED", "ROLLBACK_COMPLETE","ROLLBACK_FAILED","UPDATE_ROLLBACK_COMPLETE","UPDATE_ROLLBACK_FAILED"]
  END_STATES     = SUCESS_STATES + FAILURE_STATES

  # WAITING_STATES = ["CREATE_IN_PROGRESS","DELETE_IN_PROGRESS","ROLLBACK_IN_PROGRESS","UPDATE_COMPLETE_CLEANUP_IN_PROGRESS","UPDATE_IN_PROGRESS","UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS","UPDATE_ROLLBACK_IN_PROGRESS"]

  # Config options
  # {:aws_access_key => nil, :aws_secert_access_key => nil, :region => nil}

  def initialize(config)
    @name = config[:stack_name]

    AWS.config( {access_key_id: config[:aws_access_key],
                 secret_access_key: config[:aws_secret_access_key]})

    @cf = AWS::CloudFormation.new({region: config[:region]})
    @stack = @cf.stacks[name]
    @ec2 = AWS::EC2.new region: config[:region]
  end


  def deployed
    return stack.exists?
  end

  def apply(template_file, parameters, disable_rollback=false, capabilities=[], notify=[])
    if ( template_file =~ /^https:\/\/s3\S+\.amazonaws\.com\/(.*)/ )
      template = template_file
    else
      template = File.read(template_file)
    end
    validation = validate(template)
    unless validation["valid"]
      puts "Unable to update - #{validation["response"][:code]} - #{validation["response"][:message]}"<commit_msg>Adding session token in AWS.config<commit_after>require 'aws-sdk'

class Stack
  attr_accessor :stack, :name, :deployed

  SUCESS_STATES  = ["CREATE_COMPLETE", "UPDATE_COMPLETE"]
  FAILURE_STATES = ["CREATE_FAILED", "DELETE_FAILED", "UPDATE_ROLLBACK_FAILED", "ROLLBACK_FAILED", "ROLLBACK_COMPLETE","ROLLBACK_FAILED","UPDATE_ROLLBACK_COMPLETE","UPDATE_ROLLBACK_FAILED"]
  END_STATES     = SUCESS_STATES + FAILURE_STATES

  # WAITING_STATES = ["CREATE_IN_PROGRESS","DELETE_IN_PROGRESS","ROLLBACK_IN_PROGRESS","UPDATE_COMPLETE_CLEANUP_IN_PROGRESS","UPDATE_IN_PROGRESS","UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS","UPDATE_ROLLBACK_IN_PROGRESS"]

  # Config options
  # {:aws_access_key => nil, :aws_secert_access_key => nil, :region => nil}

  def initialize(config)
    @name = config[:stack_name]

    AWS.config( {access_key_id: config[:aws_access_key],
                 secret_access_key: config[:aws_secret_access_key],session_token: config[:aws_session_token]})

    @cf = AWS::CloudFormation.new({region: config[:region]})
    @stack = @cf.stacks[name]
    @ec2 = AWS::EC2.new region: config[:region]
  end


  def deployed
    return stack.exists?
  end

  def apply(template_file, parameters, disable_rollback=false, capabilities=[], notify=[])
    if ( template_file =~ /^https:\/\/s3\S+\.amazonaws\.com\/(.*)/ )
      template = template_file
    else
      template = File.read(template_file)
    end
    validation = validate(template)
    unless validation["valid"]
      puts "Unable to update - #{validation["response"][:code]} - #{validation["response"][:message]}"
{'fraction_non_alphanumeric': 0.13746369796708616, 'fraction_numerical': 0.001936108422071636, 'mean_word_length': 5.313645621181263, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '5361755', 'n_tokens_mistral': 1064, 'n_tokens_neox': 1072, 'n_words': 162}