Skip to content

Commit

Permalink
Merge pull request #105 from ITV/ecosystem_fix
Browse files Browse the repository at this point in the history
check ecosystem before aws-vault kpi commands
  • Loading branch information
jjfarrelly committed Apr 4, 2023
2 parents 0a09de0 + 60f873d commit 1c72451
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 13.0.3
BUGFIX:
- check ecosystem before aws-vault kpi commands
# 13.0.2
BUGFIX:
- cleanup kpi csv file after upload
Expand Down
10 changes: 6 additions & 4 deletions lib/dome/helpers/shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ def execute_command(command, failure_message)
end

def upload_kpi(product, environment, author, bucket_name, file_name)
ecosystem = environment == 'prd' ? 'prd' : 'dev'
puts "ecosystem: #{ecosystem}"
puts "#{product},#{environment},#{author},#{bucket_name},#{file_name}"
timestamp = Time.now.strftime('%Y-%m-%d-%H-%M-%S')
object_exists, stderr, status = Open3.capture3("aws-vault exec #{product}-prd-pe -- env -- aws s3 ls s3://itv-core-terraform-kpi/#{product}-infra/dome_kpi.csv")
object_exists, stderr, status = Open3.capture3("aws-vault exec #{product}-#{ecosystem}-pe -- env -- aws s3 ls s3://itv-core-terraform-kpi/#{product}-infra/dome_kpi.csv")
if object_exists.include? "dome_kpi.csv"
command_output("aws-vault exec #{product}-prd-pe -- env -- aws s3 cp s3://itv-core-terraform-kpi/#{product}-infra/dome_kpi.csv dome_kpi.csv", "Failed to copy existing object")
version_id = command_output("aws-vault exec #{product}-prd-pe -- env -- aws s3api list-object-versions --bucket #{bucket_name} --prefix #{file_name} | jq -r '.Versions[] | select(.IsLatest==true) | .VersionId'", "Failed to get version id").strip
command_output("aws-vault exec #{product}-#{ecosystem}-pe -- env -- aws s3 cp s3://itv-core-terraform-kpi/#{product}-infra/dome_kpi.csv dome_kpi.csv", "Failed to copy existing object")
version_id = command_output("aws-vault exec #{product}-#{ecosystem}-pe -- env -- aws s3api list-object-versions --bucket #{bucket_name} --prefix #{file_name} | jq -r '.Versions[] | select(.IsLatest==true) | .VersionId'", "Failed to get version id").strip
File.open("dome_kpi.csv", "a") do |f|
puts "#{timestamp},#{product},#{environment},#{author},#{version_id},#{bucket_name},#{file_name}"
f.puts "#{timestamp},#{product},#{environment},#{author},#{version_id},#{bucket_name},#{file_name}"
end
command_output("aws-vault exec #{product}-prd-pe -- env -- aws s3 cp dome_kpi.csv s3://itv-core-terraform-kpi/#{product}-infra/dome_kpi.csv", "Failed to upload new object")
command_output("aws-vault exec #{product}-#{ecosystem}-pe -- env -- aws s3 cp dome_kpi.csv s3://itv-core-terraform-kpi/#{product}-infra/dome_kpi.csv", "Failed to upload new object")
File.delete("dome_kpi.csv")
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/dome/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Dome
VERSION = '13.0.2'
VERSION = '13.0.3'
end

0 comments on commit 1c72451

Please sign in to comment.