Class: AwsCftTools::Runbook Abstract
- Inherits:
-
Object
- Object
- AwsCftTools::Runbook
- Defined in:
- lib/aws_cft_tools/runbook.rb,
lib/aws_cft_tools/runbook/report.rb
Overview
This is the base class for runbooks.
A runbook is a command that can be accessed via the ‘aws-cft` script. A runbook is implemented as a subclass of this class.
Callbacks
The AwsCftTools::CLI uses callbacks to manage runbook-specific options and behaviors.
Helpers
The various helpers make managing logic flow much easier. Rather than having to be aware of how the different modes (verbose
, change
, noop
) interplay and are configured, you can use the methods in this section to annotate the flow with your intent.
Direct Known Subclasses
Report, AwsCftTools::Runbooks::Deploy, AwsCftTools::Runbooks::Diff, AwsCftTools::Runbooks::Init, AwsCftTools::Runbooks::Retract
Defined Under Namespace
Classes: Report
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
The AwsCftTools::Client instance used by the runbook.
-
#options ⇒ Object
readonly
The configuration options passed in to the runbook.
Callbacks collapse
-
#_run ⇒ Object
An internal wrapper around
#run
to catch credential errors and print a useful message. -
#run ⇒ Object
A callback to implement the runbook actions.
Helpers collapse
-
#checking(description = nil) { ... } ⇒ Object
Runs the given block when in
check
mode and not innoop
mode. -
#debug(note = nil) ⇒ Object
Prints the given content to stdout if running in
debug
mode. -
#detail(description = nil) { ... } ⇒ Object
Prints out the given description and runs the block if in
verbose
mode. -
#doing(description = nil) { ... } ⇒ Object
Runs the given block when not in
check
ornoop
mode. -
#narrative(description = nil) ⇒ Object
Prints out the given description to stdout.
-
#operation(description = nil) { ... } ⇒ Object
Defines an operation that may or may not be narrated and that should not be run if in
noop
mode.
Instance Method Summary collapse
-
#initialize(configuration = {}) ⇒ Object
constructor
Recognized configuration options depend on the runbook but include any options valid for AwsCftTools::Client.
Constructor Details
#initialize(configuration = {}) ⇒ Object
Recognized configuration options depend on the runbook but include any options valid for AwsCftTools::Client.
Modes are selected by various configuration options:
:verbose
-
provide more narrative as the runbook executes
:noop
-
do nothing that could modify state
:change
-
do nothing that could permanently modify state, though some modifications are permitted
in order to examine what might change if permanent changes were made
48 49 50 51 52 |
# File 'lib/aws_cft_tools/runbook.rb', line 48 def initialize(configuration = {}) @options = configuration @client = AwsCftTools::Client.new() @stdout = $stdout end |
Instance Attribute Details
#client ⇒ Object (readonly)
The AwsCftTools::Client instance used by the runbook.
27 28 29 |
# File 'lib/aws_cft_tools/runbook.rb', line 27 def client @client end |
#options ⇒ Object (readonly)
The configuration options passed in to the runbook.
32 33 34 |
# File 'lib/aws_cft_tools/runbook.rb', line 32 def @options end |
Instance Method Details
#_run ⇒ Object
An internal wrapper around #run
to catch credential errors and print a useful message.
66 67 68 69 70 71 |
# File 'lib/aws_cft_tools/runbook.rb', line 66 def _run run rescue Aws::Errors::MissingCredentialsError puts 'Unable to access AWS without valid credentials. Either define a default credential' \ ' profile or use the -p option to specify an AWS credential profile.' end |
#checking(description = nil) { ... } ⇒ Object
Runs the given block when in check
mode and not in noop
mode. Outputs the description if the block is run.
105 106 107 108 109 |
# File 'lib/aws_cft_tools/runbook.rb', line 105 def checking(description = nil) return if [:noop] || ![:check] output(description) yield if block_given? end |
#debug(note = nil) ⇒ Object
Prints the given content to stdout if running in debug
mode. Debug statements are output without any capture when running multiple threads.
147 148 149 150 |
# File 'lib/aws_cft_tools/runbook.rb', line 147 def debug(note = nil) return unless note && [:debug] @stdout.puts "DEBUG\nDEBUG " + note.split(/\n/).join("\nDEBUG ") + "\nDEBUG" end |
#detail(description = nil) { ... } ⇒ Object
Prints out the given description and runs the block if in verbose
mode. This is useful if the verbose narrative might be computationally expensive.
166 167 168 169 170 |
# File 'lib/aws_cft_tools/runbook.rb', line 166 def detail(description = nil) return unless [:verbose] output(description) yield if block_given? end |
#doing(description = nil) { ... } ⇒ Object
Runs the given block when not in check
or noop
mode. Outputs the description if the block is run.
120 121 122 123 124 |
# File 'lib/aws_cft_tools/runbook.rb', line 120 def doing(description = nil) return if [:noop] || [:check] output(description) yield if block_given? end |
#narrative(description = nil) ⇒ Object
Prints out the given description to stdout. If in noop
mode, “ (noop)” is appended.
132 133 134 135 136 137 138 139 |
# File 'lib/aws_cft_tools/runbook.rb', line 132 def narrative(description = nil) return unless description if [:noop] puts "#{description} (noop)" else puts description end end |
#operation(description = nil) { ... } ⇒ Object
Defines an operation that may or may not be narrated and that should not be run if in noop
mode.
88 89 90 91 92 93 |
# File 'lib/aws_cft_tools/runbook.rb', line 88 def operation(description = nil) narrative(description) return if [:noop] yield if block_given? end |
#run ⇒ Object
A callback to implement the runbook actions. Nothing is passed in or returned.
61 |
# File 'lib/aws_cft_tools/runbook.rb', line 61 def run; end |