Sha256: 60354d1b5d58b645380adacb2e4a9dffe13dbf8f4593671330a0a198269e4e67
Contents?: true
Size: 1.46 KB
Versions: 12
Compression:
Stored size: 1.46 KB
Contents
# frozen_string_literal: true require_relative "includes" require_relative "logging" class AwsAssumeRole::Runner < Dry::Struct include AwsAssumeRole::Logging attribute :command, Dry::Types["coercible.array"].of(Dry::Types["strict.string"]).default([]) attribute :exit_on_error, Dry::Types["strict.bool"].default(true) attribute :expected_exit_code, Dry::Types["strict.integer"].default(0) attribute :environment, Dry::Types["strict.hash"].default({}) attribute :credentials, Dry::Types["object"].optional transform_types { |t| t.meta(omittable: true) } def initialize(options) super(options) command_to_exec = command.map(&:shellescape).join(" ") process_credentials unless credentials.blank? system @environment, command_to_exec exit_status = $CHILD_STATUS.exitstatus process_error(exit_status) if exit_status != expected_exit_code end private def process_credentials cred_env = { "AWS_ACCESS_KEY_ID" => credentials.credentials.access_key_id, "AWS_SECRET_ACCESS_KEY" => credentials.credentials.secret_access_key, "AWS_SESSION_TOKEN" => credentials.credentials.session_token, } @environment = environment.merge cred_env end def process_error(exit_status) logger.error "#{command} failed with #{exit_status}" exit exit_status if exit_on_error raise "#{command} failed with #{exit_status}" end end
Version data entries
12 entries across 12 versions & 1 rubygems