Skip to content

Commit

Permalink
Update rubocop (acquia#250)
Browse files Browse the repository at this point in the history
* Update rubocop from 0.38.x to 0.49.x

Reason: CVE-2017-8418 Low severity

* make rubocop happy again

* try to fix travis

* revert travisfile changes, originall at least 2.2 worked

* pin bundler in travisfile?

* drop ruby 2.1
  • Loading branch information
yitsushi authored and tanuj.jain committed Aug 17, 2021
1 parent a867524 commit 0e2935b
Show file tree
Hide file tree
Showing 21 changed files with 87 additions and 71 deletions.
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ AllCops:
- 'lib/default/**/*'
Metrics/AbcSize:
Max: 35
Metrics/BlockLength:
Max: 35
Metrics/MethodLength:
Max: 30
Metrics/LineLength:
Expand All @@ -20,3 +22,7 @@ Metrics/ClassLength:
Max: 130
Style/Documentation:
Enabled: false
Style/MethodMissing:
Enabled: false
Layout/IndentHeredoc:
Enabled: false
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ gem 'rake', require: false

group :test do
gem 'codeclimate-test-reporter'
gem 'rubocop', '~> 0.38.0'
gem 'pry'
gem 'rubocop', '~> 0.49.0'
end
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ end

RSpec::Core::RakeTask.new(:spec)

task default: [:spec, :rubocop]
task default: %i[spec rubocop]
7 changes: 3 additions & 4 deletions lib/moonshot/always_use_default_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ module Moonshot
# answer files or command-line arguments will always apply.
class AlwaysUseDefaultSource
def get(sp)
unless sp.default?
raise "Parameter #{sp.name} does not have a default, cannot use AlwaysUseDefaultSource!"
end

# Don't do anything, the default will apply on create, and the
# previous value will be used on update.
return if sp.default?

raise "Parameter #{sp.name} does not have a default, cannot use AlwaysUseDefaultSource!"
end
end
end
4 changes: 2 additions & 2 deletions lib/moonshot/build_mechanism/script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ def run_script(step, env: {})
end

result = wait.value
if result.exitstatus == 0
if result.exitstatus.zero?
step.success "Build script #{@script} exited successfully!"
end
unless result.exitstatus == 0
unless result.exitstatus.zero?
ilog.error "Build script failed with exit status #{result.exitstatus}!"
ilog.error output.join("\n")
step.failure "Build script #{@script} failed with exit status #{result.exitstatus}!"
Expand Down
6 changes: 2 additions & 4 deletions lib/moonshot/build_mechanism/travis_deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,15 @@ def initialize(slug, pro: false, timeout: 900)
@cli_args = "-r #{@slug} #{@endpoint}"
end

def pre_build_hook(_)
end
def pre_build_hook(_); end

def build_hook(version)
job_number = find_build_and_job(version)
wait_for_job(job_number)
check_build(version)
end

def post_build_hook(_)
end
def post_build_hook(_); end

private

Expand Down
6 changes: 4 additions & 2 deletions lib/moonshot/change_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,16 @@ def execute
wait_for_change_set unless @change_set
@cf_client.execute_change_set(
change_set_name: @name,
stack_name: @stack_name)
stack_name: @stack_name
)
end

def delete
wait_for_change_set unless @change_set
@cf_client.delete_change_set(
change_set_name: @name,
stack_name: @stack_name)
stack_name: @stack_name
)
rescue Aws::CloudFormation::Errors::InvalidChangeSetStatus
sleep 1
retry
Expand Down
2 changes: 1 addition & 1 deletion lib/moonshot/command_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def run! # rubocop:disable CyclomaticComplexity, MethodLength, PerceivedComplexi

# Determine what command is being run, which should be the first argument.
command = ARGV.shift
if %w(--help -h help).include?(command) || command.nil?
if %w[--help -h help].include?(command) || command.nil?
usage
return
end
Expand Down
2 changes: 1 addition & 1 deletion lib/moonshot/command_line_dispatcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def build_parser(handler)

# Each mechanism / plugin may manipulate the OptionParser object
# associated with this command.
[:build_mechanism, :deployment_mechanism, :artifact_repository].each do |prov|
%i[build_mechanism deployment_mechanism artifact_repository].each do |prov|
provider = Moonshot.config.send(prov)

if provider.respond_to?(hook_func_name(@command))
Expand Down
3 changes: 2 additions & 1 deletion lib/moonshot/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ def doctor
def ssh
run_plugins(:pre_ssh)
@config.ssh_instance ||= SSHTargetSelector.new(
stack, asg_name: @config.ssh_auto_scaling_group_name).choose!
stack, asg_name: @config.ssh_auto_scaling_group_name
).choose!
cb = SSHCommandBuilder.new(@config.ssh_config, @config.ssh_instance)
result = cb.build(@config.ssh_command)

Expand Down
7 changes: 4 additions & 3 deletions lib/moonshot/controller_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ def in_account(name, &blk)
def update_for_account!
# Evaluated any account-specific configuration.
@account_alias = Moonshot::AccountContext.get
if @account_alias && @per_account_config.key?(account_alias)
@per_account_config[@account_alias].call(self)
end
return unless @account_alias
return unless @per_account_config.key?(@account_alias)

@per_account_config[@account_alias].call(self)
end
end
end
22 changes: 15 additions & 7 deletions lib/moonshot/deployment_mechanism/code_deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def initialize(
role: DEFAULT_ROLE_NAME,
app_name: nil,
group_name: nil,
config_name: 'CodeDeployDefault.OneAtATime')
config_name: 'CodeDeployDefault.OneAtATime'
)
@asg_logical_ids = Array(asg)
@optional_asg_logical_ids = Array(optional_asg)
@app_name = app_name
Expand Down Expand Up @@ -183,7 +184,9 @@ def load_auto_scaling_groups
end

groups = as_client.describe_auto_scaling_groups(
auto_scaling_group_names: [asg_name])
auto_scaling_group_names: [asg_name]
)

if groups.auto_scaling_groups.empty?
raise "Could not find ASG #{asg_name}."
end
Expand Down Expand Up @@ -220,13 +223,16 @@ def application_exists?

def deployment_group
cd_client.get_deployment_group(
application_name: app_name, deployment_group_name: group_name)
.deployment_group_info
application_name: app_name,
deployment_group_name: group_name
).deployment_group_info
end

def deployment_group_exists?
cd_client.get_deployment_group(
application_name: app_name, deployment_group_name: group_name)
application_name: app_name,
deployment_group_name: group_name
)
true
rescue Aws::CodeDeploy::Errors::ApplicationDoesNotExistException,
Aws::CodeDeploy::Errors::DeploymentGroupDoesNotExistException
Expand Down Expand Up @@ -284,7 +290,8 @@ def delete_deployment_group
ilog.start "Deleting #{pretty_deploy_group}." do |s|
cd_client.delete_deployment_group(
application_name: app_name,
deployment_group_name: group_name)
deployment_group_name: group_name
)
s.success
end
end
Expand All @@ -294,7 +301,8 @@ def create_deployment_group
application_name: app_name,
deployment_group_name: group_name,
service_role_arn: role.arn,
auto_scaling_groups: asg_names)
auto_scaling_groups: asg_names
)
end

def wait_for_asg_capacity
Expand Down
6 changes: 2 additions & 4 deletions lib/moonshot/interactive_logger_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ def initialize(logger)
@logger = logger
end

def blank
end
def blank; end

def continue(str = nil)
@logger.info(str) if str
Expand All @@ -21,8 +20,7 @@ def failure(str = 'Failure')
@logger.error(str)
end

def repaint
end
def repaint; end

def success(str = 'Success')
@logger.info(str)
Expand Down
10 changes: 6 additions & 4 deletions lib/moonshot/stack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,11 @@ def load_template_file

# Support the legacy file location from Moonshot 1.0.
YamlStackTemplate.new(
File.join(@config.project_root, 'cloud_formation', "#{@config.app_name}.yml")),
File.join(@config.project_root, 'cloud_formation', "#{@config.app_name}.yml")
),
JsonStackTemplate.new(
File.join(@config.project_root, 'cloud_formation', "#{@config.app_name}.json"))
File.join(@config.project_root, 'cloud_formation', "#{@config.app_name}.json")
)
]

# If a template file has been specified in the config, look there first.
Expand Down Expand Up @@ -206,7 +208,7 @@ def upload_template_to_s3
def create_stack
parameters = {
stack_name: @name,
capabilities: %w(CAPABILITY_IAM CAPABILITY_NAMED_IAM),
capabilities: %w[CAPABILITY_IAM CAPABILITY_NAMED_IAM],
parameters: @config.parameters.values.map(&:to_cf),
tags: make_tags
}
Expand All @@ -231,7 +233,7 @@ def new_change_set
change_set_name: change_set_name,
description: "Moonshot update command for application '#{Moonshot.config.app_name}'",
stack_name: @name,
capabilities: %w(CAPABILITY_IAM CAPABILITY_NAMED_IAM),
capabilities: %w[CAPABILITY_IAM CAPABILITY_NAMED_IAM],
parameters: @config.parameters.values.map(&:to_cf)
}
if @config.template_s3_bucket
Expand Down
8 changes: 5 additions & 3 deletions lib/moonshot/stack_asg_printer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# coding: utf-8

require 'colorize'
require 'ruby-duration'

Expand All @@ -16,8 +17,8 @@ def initialize(stack, table)
def print
asgs.each do |asg|
asg_info = as_client.describe_auto_scaling_groups(
auto_scaling_group_names: [asg.physical_resource_id])
.auto_scaling_groups.first
auto_scaling_group_names: [asg.physical_resource_id]
).auto_scaling_groups.first
t_asg_info = @table.add_leaf("ASG: #{asg.logical_resource_id}")

add_asg_info(t_asg_info, asg_info)
Expand Down Expand Up @@ -142,7 +143,8 @@ def uptime_format(launch_time)
def add_recent_activity_leaf(table, asg_name)
recent = table.add_leaf('Recent Activity')
resp = as_client.describe_scaling_activities(
auto_scaling_group_name: asg_name).activities
auto_scaling_group_name: asg_name
).activities

rows = resp.sort_by(&:start_time).reverse.first(10).map do |activity|
row_for_activity(activity)
Expand Down
2 changes: 1 addition & 1 deletion lib/moonshot/stack_events_poller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def latest_events
def filter_events(events)
if @errors_only
events.select do |event|
%w(CREATE_FAILED UPDATE_FAILED DELETE_FAILED).include?(event.resource_status)
%w[CREATE_FAILED UPDATE_FAILED DELETE_FAILED].include?(event.resource_status)
end
else
events
Expand Down
16 changes: 8 additions & 8 deletions lib/moonshot/tools/asg_rollout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ def wait_for_in_service(new_instance)
end

def run_pre_detach(instance)
if @config.pre_detach
log.start_threaded "Running PreDetach hook on #{instance.blue}..." do |s|
he = HookExecEnvironment.new(@controller.config, instance)
if false == @config.pre_detach.call(he)
s.failure "PreDetach hook failed for #{instance.blue}!"
raise "PreDetach hook failed for #{instance.blue}!"
end
return unless @config.pre_detach

s.success "PreDetach hook complete for #{instance.blue}!"
log.start_threaded "Running PreDetach hook on #{instance.blue}..." do |s|
he = HookExecEnvironment.new(@controller.config, instance)
if @config.pre_detach.call(he) == false
s.failure "PreDetach hook failed for #{instance.blue}!"
raise "PreDetach hook failed for #{instance.blue}!"
end

s.success "PreDetach hook complete for #{instance.blue}!"
end
end

Expand Down
22 changes: 13 additions & 9 deletions lib/moonshot/tools/asg_rollout/asg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ def set_max_and_desired(max, desired)
autoscaling.update_auto_scaling_group(
auto_scaling_group_name: @name,
max_size: max,
desired_capacity: desired)
desired_capacity: desired
)
end

def non_conforming_instances
asg = load_asg

asg.instances
.select { |i| i.launch_configuration_name != asg.launch_configuration_name }
.reject { |i| i.launch_configuration_name == asg.launch_configuration_name }
.map(&:instance_id)
end

Expand Down Expand Up @@ -59,7 +60,8 @@ def detach_instance(id, decrement:)
resp = autoscaling.detach_instances(
auto_scaling_group_name: @name,
instance_ids: [id],
should_decrement_desired_capacity: decrement)
should_decrement_desired_capacity: decrement
)

activity = resp.activities.first
unless activity
Expand All @@ -69,7 +71,8 @@ def detach_instance(id, decrement:)
# Wait for the detach activity to complete:
loop do
resp = autoscaling.describe_scaling_activities(
auto_scaling_group_name: @name)
auto_scaling_group_name: @name
)

current_status = resp.activities
.find { |a| a.activity_id == activity.activity_id }
Expand Down Expand Up @@ -97,7 +100,8 @@ def instance_health(id)

def asg_instance_state(id)
resp = autoscaling.describe_auto_scaling_instances(
instance_ids: [id])
instance_ids: [id]
)

instance_info = resp.auto_scaling_instances.first
return 'Missing' unless instance_info
Expand All @@ -108,9 +112,8 @@ def asg_instance_state(id)
def elb_instance_state(id)
resp = loadbalancing.describe_instance_health(
load_balancer_name: elb_name,
instances: [
{ instance_id: id }
])
instances: [{ instance_id: id }]
)

instance_info = resp.instance_states.first
unless instance_info
Expand All @@ -133,7 +136,8 @@ def loadbalancing

def load_asg
resp = autoscaling.describe_auto_scaling_groups(
auto_scaling_group_names: [@name])
auto_scaling_group_names: [@name]
)

if resp.auto_scaling_groups.empty?
raise "Failed to call DescribeAutoScalingGroups for #{@name}!"
Expand Down
Loading

0 comments on commit 0e2935b

Please sign in to comment.