Sha256: c9e44831363c92857aee135e1cab2e1e1039faa08a79c4651823f17649cab277
Contents?: true
Size: 1.43 KB
Versions: 14
Compression:
Stored size: 1.43 KB
Contents
# frozen_string_literal: true require_relative "includes" require_relative "logging" class AwsAssumeRole::Runner < Dry::Struct include AwsAssumeRole::Logging constructor_type :schema 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.int"].default(0) attribute :environment, Dry::Types["strict.hash"].default({}) attribute :credentials, Dry::Types["object"].optional 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
14 entries across 14 versions & 1 rubygems