<commit_before># # Description: This MIQ Method configures an
# existing Simple Email Service
# It will set the region, as well as set a verified sender
# If a verified sender is chosen

# For use in MIQ under the
# /Provisioning/StateMachines/Methods/CreateSES

require 'aws-sdk'
require 'net/http'
require 'uri/http'

def send_order_status(status, order_id, information, message = '')
  host = 'jellyfish-core-dev.dpi.bah.com'
  path = "/order_items/#{order_id}/provision_update"
  url = "http://#{host}#{path}"
  uri = URI.parse(url)

  information = information.merge('provision_status' => status.downcase)
  $evm.log('info', "send_order_status: Information: #{information}")
  json = {
    status: "#{status}",
    message: "#{message}",
    info: information
  }
  $evm.log('info', "send_order_status: Information #{json}")
  begin
    http = Net::HTTP.new(uri.host, uri.port)
    request = Net::HTTP::Put.new(uri.path)
    request.content_type = 'application/json'
    request.body = json.to_json
    response = http.request(request)
    $evm.log('info', "send_order_status: HTTP Response code: #{response.code}")
    $evm.log('info', "send_order_status: HTTP Response message: #{response.message}")
  rescue HTTPExceptions => e
    $evm.log('error', "send_order_status: HTTP Exception caught while sending response back to core: #{e.message}")
  rescue StandardError => e
    $evm.log('error', "send_order_status: Exception caught while sending response back to core: #{e.message}")
  end
end # End of function

$evm.log('info', 'CreateSES: Entering method')

# Retrieve properties from request
# MIQ makes product_details into a string.
# Must make into a hash
product_details = $evm.root['dialog_product_details']
$evm.log('info', "CreateSES: Product Details: #{product_details}")
product_hash = JSON.parse(product_details.gsub("'", '"').gsub('=>', ':'))
access_key = product_hash['access_key_id']
secret_access_key = product_hash['secret_access_key']
region = product_hash['region']
email = product_hash['email']
order_id = product_hash['id']
uuid = product_hash['uuid']

# Setup the SES Region if region was chosen
if region != ''
  AWS.config(
      access_key_id: access_key,
      secret_access_key: secret_access_key,
      ses: { region: region }
  )
else
  AWS.config(
      access_key_id: access_key,
      secret_access_key: secret_access_key
  )
end

$evm.log('info', 'CreateSES: create service')
ses = AWS::SimpleEmailService.new

# Setup a verified sender if a sender was chosen
if email != ''
  begin
    info = {
      'id' => order_id,
      'uuid' => uuid
    }
    email_identities = email.split(',')
    email_identities.each do |e|
      $evm.log('info', "CreateSES: E-mail Identity: #{e}")
      ses.identities.verify(e)
    end
  rescue AWS::SimpleEmailService::Errors::InvalidClientTokenId => e
    $evm.log('error', "CreateSES: Exception caught when creating instance: #{e.message}")
    send_order_status('CRITICAL', order_id, info, "#{e.message}")
    exit
  rescue AWS::RDS::Errors::InvalidParameterValue => e
    $evm.log('error', "CreateSES: Invalid parameter exception caught: #{e.message}")
    send_order_status('CRITICAL', order_id, info, "#{e.message}")
    exit
  rescue AWS::RDS::Errors => e
    $evm.log('error', "CreateSES: Exception caught: #{e.message}")
    send_order_status('CRITICAL', order_id, info, "#{e.message}")
    exit
  rescue StandardError => e
    $evm.log('error', "CreateSES: Exception caught #{e.message}")
    send_order_status('CRITICAL', order_id, info, "#{e.message}")
    exit
  end
end

# Return the response that it was created successfully
info = {
  'id' => order_id,
  'region' => region
}

$evm.log('info', 'CreateSES: Provision executed successfully.')
send_order_status('OK', order_id, info)<commit_msg>Updated send status method<commit_after># # Description: This MIQ Method configures an
# existing Simple Email Service
# It will set the region, as well as set a verified sender
# If a verified sender is chosen

# For use in MIQ under the
# /Provisioning/StateMachines/Methods/CreateSES

require 'aws-sdk'
require 'net/http'
require 'uri/http'

def send_order_status(host, status, order_id, information, message = '')
  path = "/order_items/#{order_id}/provision_update"
  url = "http://#{host}#{path}"
  uri = URI.parse(url)

  information = information.merge('provision_status' => status.downcase)
  $evm.log('info', "send_order_status: Information: #{information}")
  json = {
    status: "#{status}",
    message: "#{message}",
    info: information
  }
  $evm.log('info', "send_order_status: Information #{json}")
  begin
    http = Net::HTTP.new(uri.host, uri.port)
    request = Net::HTTP::Put.new(uri.path)
    request.content_type = 'application/json'
    request.body = json.to_json
    response = http.request(request)
    $evm.log('info', "send_order_status: HTTP Response code: #{response.code}")
    $evm.log('info', "send_order_status: HTTP Response message: #{response.message}")
  rescue HTTPExceptions => e
    $evm.log('error', "send_order_status: HTTP Exception caught while sending response back to core: #{e.message}")
  rescue StandardError => e
    $evm.log('error', "send_order_status: Exception caught while sending response back to core: #{e.message}")
  end
end # End of function

$evm.log('info', 'CreateSES: Entering method')

# Retrieve properties from request
# MIQ makes product_details into a string.
# Must make into a hash
product_details = $evm.root['dialog_product_details']
$evm.log('info', "CreateSES: Product Details: #{product_details}")
product_hash = JSON.parse(product_details.gsub("'", '"').gsub('=>', ':'))
access_key = product_hash['access_key_id']
secret_access_key = product_hash['secret_access_key']
region = product_hash['region']
email = product_hash['email']
order_id = product_hash['id']
uuid = product_hash['uuid']

# Setup the SES Region if region was chosen
if region != ''
  AWS.config(
      access_key_id: access_key,
      secret_access_key: secret_access_key,
      ses: { region: region }
  )
else
  AWS.config(
      access_key_id: access_key,
      secret_access_key: secret_access_key
  )
end

$evm.log('info', 'CreateSES: create service')
ses = AWS::SimpleEmailService.new

# Setup a verified sender if a sender was chosen
if email != ''
  begin
    info = {
      'id' => order_id,
      'uuid' => uuid
    }
    email_identities = email.split(',')
    email_identities.each do |e|
      $evm.log('info', "CreateSES: E-mail Identity: #{e}")
      ses.identities.verify(e)
    end
  rescue AWS::SimpleEmailService::Errors::InvalidClientTokenId => e
    $evm.log('error', "CreateSES: Exception caught when creating instance: #{e.message}")
    send_order_status(host, 'CRITICAL', order_id, info, "#{e.message}")
    exit
  rescue AWS::RDS::Errors::InvalidParameterValue => e
    $evm.log('error', "CreateSES: Invalid parameter exception caught: #{e.message}")
    send_order_status(host, 'CRITICAL', order_id, info, "#{e.message}")
    exit
  rescue AWS::RDS::Errors => e
    $evm.log('error', "CreateSES: Exception caught: #{e.message}")
    send_order_status(host, 'CRITICAL', order_id, info, "#{e.message}")
    exit
  rescue StandardError => e
    $evm.log('error', "CreateSES: Exception caught #{e.message}")
    send_order_status(host, 'CRITICAL', order_id, info, "#{e.message}")
    exit
  end
end

# Return the response that it was created successfully
info = {
  'id' => order_id,
  'region' => region
}

$evm.log('info', 'CreateSES: Provision executed successfully.')
send_order_status(host, 'OK', order_id, info)
{'fraction_non_alphanumeric': 0.1455169681764162, 'fraction_numerical': 0.0, 'mean_word_length': 4.593796159527327, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '3000835', 'n_tokens_mistral': 2454, 'n_tokens_neox': 2502, 'n_words': 630}