Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Rubocop, and add minitest reporters #122

Merged
merged 19 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
35 changes: 28 additions & 7 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
inherit_from: .rubocop_todo.yml

require:
- rubocop-minitest
- rubocop-performance
- rubocop-rake

AllCops:
TargetRubyVersion: 2.5

Rails:
Enabled: false

# Don't enforce documentation
Style/Documentation:
Enabled: false
Expand Down Expand Up @@ -35,7 +37,7 @@ Naming/FileName:
Naming/HeredocDelimiterNaming:
Enabled: false

Style/TrailingCommaInLiteral:
Style/TrailingCommaInArrayLiteral:
Enabled: false

Style/TrailingCommaInArguments:
Expand All @@ -59,9 +61,6 @@ Style/ClassAndModuleChildren:
Style/GuardClause:
Enabled: false

Style/BracesAroundHashParameters:
Enabled: false

Style/SignalException:
Enabled: false

Expand Down Expand Up @@ -97,3 +96,25 @@ Style/RescueModifier:

Style/Alias:
Enabled: false

Naming/MemoizedInstanceVariableName:
Enabled: false

Lint/ConstantDefinitionInBlock:
Exclude:
- 'test/io_buffer_test.rb'

Style/OptionalBooleanParameter:
Enabled: false

Lint/MissingSuper:
Enabled: false

Layout/LineLength:
Max: 197

Layout/EmptyLineAfterMagicComment:
Enabled: false

Style/SlicingWithRange:
Enabled: false
11 changes: 2 additions & 9 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2020-10-20 13:40:01 +0200 using RuboCop version 0.52.1.
# `rubocop --auto-gen-config --no-offense-counts --no-auto-gen-timestamp`
# using RuboCop version 1.28.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
# versions of RuboCop, may require this file to be generated again.

# Offense count: 33
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: when_needed, always, never
Style/FrozenStringLiteralComment:
Enabled: false
14 changes: 11 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
# frozen_string_literal: true
source 'https://rubygems.org'

gemspec :name => 'smart_proxy_dynflow'

group :rubocop do
gem 'rubocop', '~> 1.28.0'
gem 'rubocop-minitest'
gem 'rubocop-performance'
gem 'rubocop-rake'
end

group :development do
gem 'pry'
end

group :test do
gem 'smart_proxy', :git => "https://github.com/theforeman/smart-proxy", :branch => "develop"

gem 'minitest'
gem 'minitest-reporters'
gem 'mocha'
gem 'public_suffix'
gem 'rack-test'
gem 'rake'
gem 'rubocop', '~> 0.52.1'
gem 'smart_proxy', :git => "https://github.com/theforeman/smart-proxy", :branch => "develop"
gem 'webmock'
end

gem 'logging-journald', '~> 2.0', :platforms => [:ruby], :require => false
Expand Down
6 changes: 6 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'rake'
require 'rake/testtask'
require 'rubocop/rake_task'
Expand Down Expand Up @@ -28,3 +29,8 @@ if defined? RuboCop
task.fail_on_error = true
end
end

namespace :jenkins do
desc nil # No description means it's not listed in rake -T
task unit: :test
end
1 change: 1 addition & 0 deletions bundler.d/dynflow.rb
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# frozen_string_literal: true
gem 'smart_proxy_dynflow'
1 change: 1 addition & 0 deletions lib/smart_proxy_dynflow.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'dynflow'

require 'smart_proxy_dynflow/task_launcher_registry'
Expand Down
1 change: 1 addition & 0 deletions lib/smart_proxy_dynflow/action.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Proxy::Dynflow
module Action
end
Expand Down
1 change: 1 addition & 0 deletions lib/smart_proxy_dynflow/action/batch.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Proxy::Dynflow::Action
class Batch < ::Dynflow::Action
include Dynflow::Action::WithSubPlans
Expand Down
1 change: 1 addition & 0 deletions lib/smart_proxy_dynflow/action/batch_callback.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Proxy::Dynflow::Action
class BatchCallback < ::Dynflow::Action
def plan(input_hash, results)
Expand Down
1 change: 1 addition & 0 deletions lib/smart_proxy_dynflow/action/batch_runner.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'smart_proxy_dynflow/action/runner'

module Proxy::Dynflow::Action
Expand Down
1 change: 1 addition & 0 deletions lib/smart_proxy_dynflow/action/external_polling.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Proxy::Dynflow::Action
module WithExternalPolling
Poll = Algebrick.atom
Expand Down
1 change: 1 addition & 0 deletions lib/smart_proxy_dynflow/action/output_collector.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Proxy::Dynflow::Action
class OutputCollector < ::Proxy::Dynflow::Action::Runner
def init_run
Expand Down
1 change: 1 addition & 0 deletions lib/smart_proxy_dynflow/action/runner.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'smart_proxy_dynflow/action/shareable'
require 'smart_proxy_dynflow/action/external_polling'
module Proxy::Dynflow
Expand Down
1 change: 1 addition & 0 deletions lib/smart_proxy_dynflow/action/shareable.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Proxy::Dynflow::Action
class Shareable < ::Dynflow::Action
def plan(input)
Expand Down
1 change: 1 addition & 0 deletions lib/smart_proxy_dynflow/action/single_runner_batch.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Proxy::Dynflow::Action
class SingleRunnerBatch < Batch
def plan(launcher, input_hash)
Expand Down
3 changes: 2 additions & 1 deletion lib/smart_proxy_dynflow/api.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'sinatra/base'
require 'proxy/helpers'
require 'sinatra/authorization'
Expand All @@ -11,7 +12,7 @@ class Api < ::Sinatra::Base

include ::Sinatra::Authorization::Helpers

TASK_UPDATE_REGEXP_PATH = %r{/tasks/(\S+)/(update|done)}
TASK_UPDATE_REGEXP_PATH = %r{/tasks/(\S+)/(update|done)}.freeze

before do
if match = request.path_info.match(TASK_UPDATE_REGEXP_PATH)
Expand Down
2 changes: 2 additions & 0 deletions lib/smart_proxy_dynflow/callback.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'rest-client'

module Proxy::Dynflow
Expand All @@ -15,6 +16,7 @@ def callback(payload)
if response.code.to_s != "200"
raise "Failed performing callback to Foreman server: #{response.code} #{response.body}"
end

response
end
end
Expand Down
3 changes: 3 additions & 0 deletions lib/smart_proxy_dynflow/continuous_output.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Proxy::Dynflow
class ContinuousOutput
attr_accessor :raw_outputs
Expand All @@ -12,6 +13,7 @@ def add_raw_output(raw_output)
unless missing_args.empty?
raise ArgumentError, "Missing args for raw output: #{missing_args.inspect}"
end

@raw_outputs << raw_output
end

Expand All @@ -21,6 +23,7 @@ def empty?

def last_timestamp
return if @raw_outputs.empty?

@raw_outputs.last.fetch('timestamp')
end

Expand Down
6 changes: 4 additions & 2 deletions lib/smart_proxy_dynflow/core.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'fileutils'

module Proxy::Dynflow
Expand All @@ -24,6 +25,7 @@ def create_world(&block)

def persistence_conn_string
return ENV['DYNFLOW_DB_CONN_STRING'] if ENV.key? 'DYNFLOW_DB_CONN_STRING'

db_conn_string = 'sqlite:/'

db_file = Settings.instance.database
Expand Down Expand Up @@ -72,6 +74,7 @@ class << self

def ensure_initialized
return @instance if @instance

@instance = Core.new
after_initialize_blocks.each { |block| block.call(@instance) }
@instance
Expand All @@ -87,7 +90,7 @@ def register_silencer_matchers(matchers)

def web_console
require 'dynflow/web'
dynflow_console = ::Dynflow::Web.setup do
::Dynflow::Web.setup do
# we can't use the proxy's after_activation hook, as
# it happens before the Daemon forks the process (including
# closing opened file descriptors)
Expand All @@ -103,7 +106,6 @@ def web_console
Core.ensure_initialized
set :world, Core.world
end
dynflow_console
end

def world
Expand Down
1 change: 1 addition & 0 deletions lib/smart_proxy_dynflow/helpers.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'smart_proxy_dynflow/action/external_polling'
require 'smart_proxy_dynflow/action/runner'

Expand Down
1 change: 1 addition & 0 deletions lib/smart_proxy_dynflow/http_config.ru
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'smart_proxy_dynflow/api'

map "/dynflow" do
Expand Down
5 changes: 3 additions & 2 deletions lib/smart_proxy_dynflow/io_buffer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Proxy
module Dynflow
# A buffer around an IO object providing buffering and convenience methods
Expand Down Expand Up @@ -71,7 +72,7 @@ def close
def read_available!
data = ''
loop { data += @io.read_nonblock(4096) }
rescue IO::WaitReadable # rubocop:disable Lint/HandleExceptions
rescue IO::WaitReadable # rubocop:disable Lint/SuppressedException
rescue EOFError
close
ensure
Expand All @@ -88,7 +89,7 @@ def write_available!
n = @io.write_nonblock(@buffer)
@buffer = @buffer[n..-1]
end
rescue IO::WaitWritable # rubocop:disable Lint/HandleExceptions
rescue IO::WaitWritable # rubocop:disable Lint/SuppressedException
rescue EOFError
close
end
Expand Down
3 changes: 2 additions & 1 deletion lib/smart_proxy_dynflow/log.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# frozen_string_literal: true
require 'logging'

module Proxy::Dynflow
class Log
LOGGER_NAME = 'dynflow-core'.freeze
LOGGER_NAME = 'dynflow-core'

begin
require 'syslog/logger'
Expand Down
5 changes: 3 additions & 2 deletions lib/smart_proxy_dynflow/middleware/keep_current_request_id.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Actions
module Middleware
class KeepCurrentRequestID < Dynflow::Middleware
Expand Down Expand Up @@ -26,11 +27,11 @@ def hook(*args)

private

def with_current_request_id
def with_current_request_id(&block)
if action.input[:current_request_id].nil?
yield
else
restore_current_request_id { yield }
restore_current_request_id(&block)
end
end

Expand Down
6 changes: 4 additions & 2 deletions lib/smart_proxy_dynflow/otp_manager.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'base64'
require 'securerandom'

Expand All @@ -20,9 +21,10 @@ def passwords
def authenticate(hash, expected_user: nil, clear: true)
plain = Base64.decode64(hash)
username, otp = plain.split(':', 2)
if expected_user
return false unless expected_user == username
if expected_user && expected_user != username
return false
end

password_matches = passwords[username] == otp
passwords.delete(username) if clear && password_matches
password_matches
Expand Down
1 change: 1 addition & 0 deletions lib/smart_proxy_dynflow/plugin.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'proxy/log'
require 'proxy/pluggable'
require 'proxy/plugin'
Expand Down
2 changes: 2 additions & 0 deletions lib/smart_proxy_dynflow/process_manager.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'smart_proxy_dynflow/io_buffer'

module Proxy
Expand Down Expand Up @@ -117,6 +118,7 @@ def done?
# @return [void]
def process(timeout: nil)
raise 'Cannot process until the manager is started' unless started?

writers = [@stdin].reject { |buf| buf.empty? || buf.closed? }
readers = [@stdout, @stderr].reject(&:closed?)

Expand Down
1 change: 1 addition & 0 deletions lib/smart_proxy_dynflow/proxy_adapter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Proxy
module Dynflow
class ProxyAdapter < ::Dynflow::LoggerAdapters::Simple
Expand Down
1 change: 1 addition & 0 deletions lib/smart_proxy_dynflow/runner.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Proxy::Dynflow
module Runner
end
Expand Down
4 changes: 3 additions & 1 deletion lib/smart_proxy_dynflow/runner/base.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Proxy::Dynflow
module Runner
# Runner is an object that is able to initiate some action and
Expand All @@ -13,7 +14,7 @@ def initialize(*_args, suspended_action: nil, id: nil)
end

def logger
@logger ||= Logger.new(STDERR)
@logger ||= Logger.new($stderr)
end

def run_refresh
Expand Down Expand Up @@ -77,6 +78,7 @@ def dispatch_exception(context, exception)

def generate_updates
return no_update if @continuous_output.empty? && @exit_status.nil?

new_data = @continuous_output
@continuous_output = Proxy::Dynflow::ContinuousOutput.new
new_update(new_data, @exit_status)
Expand Down
Loading