Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# The behavior of RuboCop can be controlled via the .rubocop.yml
# configuration file. It makes it possible to enable/disable
# certain cops (checks) and to alter their behavior if they accept
# any parameters. The file can be placed either in your home
# directory or in some project directory.
#
# RuboCop will start looking for the configuration file in the directory
# where the inspected file is and continue its way up to the root directory.
#
# See https://docs.rubocop.org/rubocop/configuration

inherit_mode:
merge:
- Exclude
inherit_from: .rubocop_todo.yml

AllCops:
Expand Down
48 changes: 8 additions & 40 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 100 --no-offense-counts --no-auto-gen-timestamp`
# using RuboCop version 1.81.7.
# using RuboCop version 1.84.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -18,12 +18,6 @@ Layout/TrailingWhitespace:
Exclude:
- 'spec/stack_master/commands/status_spec.rb'

# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowSafeAssignment.
Lint/AssignmentInCondition:
Exclude:
- 'lib/stack_master/parameter_resolvers/latest_container.rb'

# Configuration parameters: AllowedMethods.
# AllowedMethods: enums
Lint/ConstantDefinitionInBlock:
Expand All @@ -41,11 +35,6 @@ Lint/DuplicateMethods:
- 'lib/stack_master/stack_definition.rb'
- 'lib/stack_master/test_driver/cloud_formation.rb'

Lint/IneffectiveAccessModifier:
Exclude:
- 'lib/stack_master/parameter_loader.rb'
- 'lib/stack_master/template_compilers/sparkle_formation.rb'

# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: standard_error, runtime_error
Expand Down Expand Up @@ -99,33 +88,19 @@ Lint/SelfAssignment:
Exclude:
- 'lib/stack_master/cli.rb'

# This cop supports safe autocorrection (--autocorrect).
Lint/SendWithMixinArgument:
Exclude:
- 'lib/stack_master/sparkle_formation/template_file.rb'

# Configuration parameters: AllowComments, AllowNil.
Lint/SuppressedException:
Exclude:
- 'Rakefile'
- 'lib/stack_master/stack_events/streamer.rb'
- 'lib/stack_master/stack_status.rb'

# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
Lint/UnusedBlockArgument:
Exclude:
- 'features/step_definitions/parameter_store_steps.rb'
- 'lib/stack_master/stack_differ.rb'

# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods, NotImplementedExceptions.
# NotImplementedExceptions: NotImplementedError
Lint/UnusedMethodArgument:
Exclude:
- 'lib/stack_master/test_driver/cloud_formation.rb'
- 'lib/stack_master/test_driver/s3.rb'
- 'spec/stack_master/parameter_resolver_spec.rb'
- 'spec/support/aws_stubs.rb'

# This cop supports safe autocorrection (--autocorrect).
Expand All @@ -135,14 +110,6 @@ Lint/UselessAccessModifier:
- 'lib/stack_master/parameter_loader.rb'
- 'lib/stack_master/template_compilers/sparkle_formation.rb'

# This cop supports safe autocorrection (--autocorrect).
Lint/UselessAssignment:
Exclude:
- 'lib/stack_master/cli.rb'
- 'lib/stack_master/commands/tidy.rb'
- 'lib/stack_master/parameter_resolvers/latest_ami_by_tags.rb'
- 'lib/stack_master/template_compiler.rb'

# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: CheckForMethodsWithNoSideEffects.
Lint/Void:
Expand Down Expand Up @@ -176,7 +143,6 @@ Metrics/AbcSize:
# AllowedMethods: refine
Metrics/BlockLength:
Exclude:
- '**/*.gemspec'
- 'example/simple/templates/myapp_vpc.rb'
- 'spec/integration/drift_spec.rb'
- 'spec/stack_master/aws_driver/s3_spec.rb'
Expand Down Expand Up @@ -320,7 +286,6 @@ Naming/AccessorMethodName:
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
Naming/FileName:
Exclude:
- 'Rakefile.rb'
- 'spec/fixtures/templates/rb/cfndsl/sample-ctp-repeated.rb'
- 'spec/fixtures/templates/rb/cfndsl/sample-ctp.rb'

Expand Down Expand Up @@ -352,7 +317,6 @@ Naming/MethodParameterName:
# MethodDefinitionMacros: define_method, define_singleton_method
Naming/PredicatePrefix:
Exclude:
- 'spec/**/*'
- 'lib/stack_master/parameter_resolvers/one_password.rb'
- 'lib/stack_master/sparkle_formation/compile_time/definitions_validator.rb'
- 'lib/stack_master/sparkle_formation/compile_time/empty_validator.rb'
Expand Down Expand Up @@ -405,8 +369,6 @@ Style/ClassAndModuleChildren:
# Configuration parameters: AllowedConstants.
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'lib/stack_master.rb'
- 'lib/stack_master/aws_driver/cloud_formation.rb'
- 'lib/stack_master/aws_driver/s3.rb'
Expand Down Expand Up @@ -503,6 +465,13 @@ Style/GlobalStdStream:
- 'lib/stack_master/cli.rb'
- 'spec/stack_master/commands/apply_spec.rb'

# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: braces, no_braces
Style/HashAsLastArrayItem:
Exclude:
- 'spec/integration/drift_spec.rb'

# This cop supports unsafe autocorrection (--autocorrect-all).
Style/HashTransformValues:
Exclude:
Expand Down Expand Up @@ -541,7 +510,6 @@ Style/MutableConstant:
# SupportedStyles: predicate, comparison
Style/NumericPredicate:
Exclude:
- 'spec/**/*'
- 'lib/stack_master/cli.rb'
- 'lib/stack_master/commands/events.rb'
- 'lib/stack_master/commands/nag.rb'
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ The format is based on [Keep a Changelog], and this project adheres to

## [Unreleased]

### Fixed

- Resolve lint issues identified by RuboCop. ([#401])

[Unreleased]: https://github.com/envato/stack_master/compare/v2.18.0...HEAD
[#401]: https://github.com/envato/stack_master/pull/401

## [2.18.0] - 2026-02-02

Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/parameter_store_steps.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Given(/^(?:a|the)\ SSM\ parameter(?:\ named)?\ "([^"]*)"
\ with\ value\ "([^"]*)"\ in\ region\ "([^"]*)"$/x) do |parameter_name, parameter_value, parameter_region|
\ with\ value\ "([^"]*)"\ in\ region\ "([^"]*)"$/x) do |parameter_name, parameter_value, _parameter_region|
Aws.config[:ssm] = {
stub_responses: {
get_parameter: {
Expand Down
4 changes: 2 additions & 2 deletions lib/stack_master/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def default_config_file
def load_config(file)
stack_file = file || default_config_file
StackMaster::Config.load!(stack_file)
rescue Errno::ENOENT => e
rescue Errno::ENOENT
say "Failed to load config file #{stack_file}"
@kernel.exit false
end
Expand Down Expand Up @@ -301,7 +301,7 @@ def execute_stacks_command(command, args, options)
end

def show_other_region_candidates(config, stack_name)
candidates = config.filter(region = '', stack_name = stack_name)
candidates = config.filter('', stack_name = stack_name)
return if candidates.empty?

StackMaster.stdout.puts "Stack name #{stack_name} exists in regions: #{candidates.map(&:region).join(', ')}"
Expand Down
5 changes: 1 addition & 4 deletions lib/stack_master/commands/tidy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ class Tidy
include StackMaster::Commands::TerminalHelper

def perform
used_templates = []
used_parameter_files = []

templates = Set.new(find_templates)
parameter_files = Set.new(find_parameter_files)

status = @config.stacks.each do |stack_definition|
@config.stacks.each do |stack_definition|
parameter_files.subtract(stack_definition.parameter_files_from_globs)
template = File.absolute_path(stack_definition.template_file_path)

Expand Down
62 changes: 32 additions & 30 deletions lib/stack_master/parameter_loader.rb
Original file line number Diff line number Diff line change
@@ -1,46 +1,48 @@
require 'active_support/core_ext/object/deep_dup'

module StackMaster
class ParameterLoader
module ParameterLoader
COMPILE_TIME_PARAMETERS_KEY = 'compile_time_parameters'

def self.load(parameter_files: [], parameters: {})
StackMaster.debug 'Searching for parameter files...'
all_parameters = parameter_files.map { |file_name| load_parameters(file_name) } + [parameters]
all_parameters.each_with_object({ template_parameters: {}, compile_time_parameters: {} }) do |parameters, hash|
template_parameters = create_template_parameters(parameters)
compile_time_parameters = create_compile_time_parameters(parameters)

merge_and_camelize(hash[:template_parameters], template_parameters)
merge_and_camelize(hash[:compile_time_parameters], compile_time_parameters)
class << self
def load(parameter_files: [], parameters: {})
StackMaster.debug 'Searching for parameter files...'
all_parameters = parameter_files.map { |file_name| load_parameters(file_name) } + [parameters]
all_parameters.each_with_object({ template_parameters: {}, compile_time_parameters: {} }) do |parameters, hash|
template_parameters = create_template_parameters(parameters)
compile_time_parameters = create_compile_time_parameters(parameters)

merge_and_camelize(hash[:template_parameters], template_parameters)
merge_and_camelize(hash[:compile_time_parameters], compile_time_parameters)
end
end
end

private
private

def self.load_parameters(file_name)
file_exists = File.exist?(file_name)
StackMaster.debug file_exists ? " #{file_name} found" : " #{file_name} not found"
file_exists ? load_file(file_name) : {}
end
def load_parameters(file_name)
file_exists = File.exist?(file_name)
StackMaster.debug file_exists ? " #{file_name} found" : " #{file_name} not found"
file_exists ? load_file(file_name) : {}
end

def self.load_file(file_name)
YAML.load(File.read(file_name)) || {}
end
def load_file(file_name)
YAML.load(File.read(file_name)) || {}
end

def self.create_template_parameters(parameters)
parameters.deep_dup.tap do |parameters_clone|
parameters_clone.delete(COMPILE_TIME_PARAMETERS_KEY) ||
parameters_clone.delete(COMPILE_TIME_PARAMETERS_KEY.camelize)
def create_template_parameters(parameters)
parameters.deep_dup.tap do |parameters_clone|
parameters_clone.delete(COMPILE_TIME_PARAMETERS_KEY) ||
parameters_clone.delete(COMPILE_TIME_PARAMETERS_KEY.camelize)
end
end
end

def self.create_compile_time_parameters(parameters)
(parameters[COMPILE_TIME_PARAMETERS_KEY] || parameters[COMPILE_TIME_PARAMETERS_KEY.camelize] || {}).deep_dup
end
def create_compile_time_parameters(parameters)
(parameters[COMPILE_TIME_PARAMETERS_KEY] || parameters[COMPILE_TIME_PARAMETERS_KEY.camelize] || {}).deep_dup
end

def self.merge_and_camelize(hash, parameters)
parameters.each { |key, value| hash[key.camelize] = value }
def merge_and_camelize(hash, parameters)
parameters.each { |key, value| hash[key.camelize] = value }
end
end
end
end
2 changes: 1 addition & 1 deletion lib/stack_master/parameter_resolvers/latest_ami_by_tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def initialize(config, stack_definition)
end

def resolve(value)
filters = @ami_finder.build_filters_from_string(value, prefix = 'tag')
filters = @ami_finder.build_filters_from_string(value, 'tag')
@ami_finder.find_latest_ami(filters)&.image_id
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/stack_master/parameter_resolvers/latest_container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def resolve(parameters)
def fetch_images(repository_name, registry_id, ecr)
images = []
next_token = nil
while resp = ecr.describe_images(
while (resp = ecr.describe_images(
{
repository_name: repository_name,
registry_id: registry_id,
Expand All @@ -46,7 +46,7 @@ def fetch_images(repository_name, registry_id, ecr)
tag_status: 'TAGGED'
}
}
)
))

images += resp.image_details
next_token = resp.next_token
Expand Down
4 changes: 2 additions & 2 deletions lib/stack_master/sparkle_formation/template_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ def _user_data_file(file_name, vars = {})
end
end

SparkleFormation::SparkleAttribute::Aws.send(:include, StackMaster::SparkleFormation::UserDataFile)
SparkleFormation::SparkleAttribute::Aws.send(:include, StackMaster::SparkleFormation::JoinedFile)
SparkleFormation::SparkleAttribute::Aws.include StackMaster::SparkleFormation::UserDataFile
SparkleFormation::SparkleAttribute::Aws.include StackMaster::SparkleFormation::JoinedFile
2 changes: 1 addition & 1 deletion lib/stack_master/stack_differ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def output_diff

def noecho_keys
if @current_stack
@current_stack.parameters_with_defaults.select do |key, value|
@current_stack.parameters_with_defaults.select do |_key, value|
value == '****'
end.keys
else
Expand Down
2 changes: 1 addition & 1 deletion lib/stack_master/template_compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def self.compile(config, template_compiler, template_dir, template, compile_time
end
compiler.require_dependencies
compiler.compile(template_dir, template, compile_time_parameters, compiler_options)
rescue StandardError => e
rescue StandardError
raise TemplateCompilationFailed, "Failed to compile #{template}"
end

Expand Down
Loading