diff --git a/.rubocop.yml b/.rubocop.yml index 4e7bf46..b89a735 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -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 @@ -35,7 +37,7 @@ Naming/FileName: Naming/HeredocDelimiterNaming: Enabled: false -Style/TrailingCommaInLiteral: +Style/TrailingCommaInArrayLiteral: Enabled: false Style/TrailingCommaInArguments: @@ -59,9 +61,6 @@ Style/ClassAndModuleChildren: Style/GuardClause: Enabled: false -Style/BracesAroundHashParameters: - Enabled: false - Style/SignalException: Enabled: false @@ -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 \ No newline at end of file diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index caa0d60..0f17bfe 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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 diff --git a/Gemfile b/Gemfile index c8ee723..aae7795 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Rakefile b/Rakefile index 984d9b1..c7f453e 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'rake' require 'rake/testtask' require 'rubocop/rake_task' @@ -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 diff --git a/bundler.d/dynflow.rb b/bundler.d/dynflow.rb index 42d604c..5dbe46f 100644 --- a/bundler.d/dynflow.rb +++ b/bundler.d/dynflow.rb @@ -1 +1,2 @@ +# frozen_string_literal: true gem 'smart_proxy_dynflow' diff --git a/lib/smart_proxy_dynflow.rb b/lib/smart_proxy_dynflow.rb index fc211a4..dbdc652 100644 --- a/lib/smart_proxy_dynflow.rb +++ b/lib/smart_proxy_dynflow.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'dynflow' require 'smart_proxy_dynflow/task_launcher_registry' diff --git a/lib/smart_proxy_dynflow/action.rb b/lib/smart_proxy_dynflow/action.rb index 20ff452..51beb87 100644 --- a/lib/smart_proxy_dynflow/action.rb +++ b/lib/smart_proxy_dynflow/action.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Proxy::Dynflow module Action end diff --git a/lib/smart_proxy_dynflow/action/batch.rb b/lib/smart_proxy_dynflow/action/batch.rb index 06e94ae..29b8492 100644 --- a/lib/smart_proxy_dynflow/action/batch.rb +++ b/lib/smart_proxy_dynflow/action/batch.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Proxy::Dynflow::Action class Batch < ::Dynflow::Action include Dynflow::Action::WithSubPlans diff --git a/lib/smart_proxy_dynflow/action/batch_callback.rb b/lib/smart_proxy_dynflow/action/batch_callback.rb index 88100c5..3a96512 100644 --- a/lib/smart_proxy_dynflow/action/batch_callback.rb +++ b/lib/smart_proxy_dynflow/action/batch_callback.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Proxy::Dynflow::Action class BatchCallback < ::Dynflow::Action def plan(input_hash, results) diff --git a/lib/smart_proxy_dynflow/action/batch_runner.rb b/lib/smart_proxy_dynflow/action/batch_runner.rb index 35a3e55..33d2b2e 100644 --- a/lib/smart_proxy_dynflow/action/batch_runner.rb +++ b/lib/smart_proxy_dynflow/action/batch_runner.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'smart_proxy_dynflow/action/runner' module Proxy::Dynflow::Action diff --git a/lib/smart_proxy_dynflow/action/external_polling.rb b/lib/smart_proxy_dynflow/action/external_polling.rb index 195b204..b62c567 100644 --- a/lib/smart_proxy_dynflow/action/external_polling.rb +++ b/lib/smart_proxy_dynflow/action/external_polling.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Proxy::Dynflow::Action module WithExternalPolling Poll = Algebrick.atom diff --git a/lib/smart_proxy_dynflow/action/output_collector.rb b/lib/smart_proxy_dynflow/action/output_collector.rb index 6195813..b97f3cd 100644 --- a/lib/smart_proxy_dynflow/action/output_collector.rb +++ b/lib/smart_proxy_dynflow/action/output_collector.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Proxy::Dynflow::Action class OutputCollector < ::Proxy::Dynflow::Action::Runner def init_run diff --git a/lib/smart_proxy_dynflow/action/runner.rb b/lib/smart_proxy_dynflow/action/runner.rb index ce49fe7..eeba136 100644 --- a/lib/smart_proxy_dynflow/action/runner.rb +++ b/lib/smart_proxy_dynflow/action/runner.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'smart_proxy_dynflow/action/shareable' require 'smart_proxy_dynflow/action/external_polling' module Proxy::Dynflow diff --git a/lib/smart_proxy_dynflow/action/shareable.rb b/lib/smart_proxy_dynflow/action/shareable.rb index d157e48..13155f8 100644 --- a/lib/smart_proxy_dynflow/action/shareable.rb +++ b/lib/smart_proxy_dynflow/action/shareable.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Proxy::Dynflow::Action class Shareable < ::Dynflow::Action def plan(input) diff --git a/lib/smart_proxy_dynflow/action/single_runner_batch.rb b/lib/smart_proxy_dynflow/action/single_runner_batch.rb index fdb6e1f..165aa84 100644 --- a/lib/smart_proxy_dynflow/action/single_runner_batch.rb +++ b/lib/smart_proxy_dynflow/action/single_runner_batch.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Proxy::Dynflow::Action class SingleRunnerBatch < Batch def plan(launcher, input_hash) diff --git a/lib/smart_proxy_dynflow/api.rb b/lib/smart_proxy_dynflow/api.rb index 02d775a..36f8a10 100644 --- a/lib/smart_proxy_dynflow/api.rb +++ b/lib/smart_proxy_dynflow/api.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'sinatra/base' require 'proxy/helpers' require 'sinatra/authorization' @@ -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) diff --git a/lib/smart_proxy_dynflow/callback.rb b/lib/smart_proxy_dynflow/callback.rb index 4a5740b..766c62b 100644 --- a/lib/smart_proxy_dynflow/callback.rb +++ b/lib/smart_proxy_dynflow/callback.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'rest-client' module Proxy::Dynflow @@ -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 diff --git a/lib/smart_proxy_dynflow/continuous_output.rb b/lib/smart_proxy_dynflow/continuous_output.rb index 3b8e97d..814a63a 100644 --- a/lib/smart_proxy_dynflow/continuous_output.rb +++ b/lib/smart_proxy_dynflow/continuous_output.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Proxy::Dynflow class ContinuousOutput attr_accessor :raw_outputs @@ -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 @@ -21,6 +23,7 @@ def empty? def last_timestamp return if @raw_outputs.empty? + @raw_outputs.last.fetch('timestamp') end diff --git a/lib/smart_proxy_dynflow/core.rb b/lib/smart_proxy_dynflow/core.rb index 23dc906..3ff43f7 100644 --- a/lib/smart_proxy_dynflow/core.rb +++ b/lib/smart_proxy_dynflow/core.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'fileutils' module Proxy::Dynflow @@ -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 @@ -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 @@ -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) @@ -103,7 +106,6 @@ def web_console Core.ensure_initialized set :world, Core.world end - dynflow_console end def world diff --git a/lib/smart_proxy_dynflow/helpers.rb b/lib/smart_proxy_dynflow/helpers.rb index f4f6daa..604b069 100644 --- a/lib/smart_proxy_dynflow/helpers.rb +++ b/lib/smart_proxy_dynflow/helpers.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'smart_proxy_dynflow/action/external_polling' require 'smart_proxy_dynflow/action/runner' diff --git a/lib/smart_proxy_dynflow/http_config.ru b/lib/smart_proxy_dynflow/http_config.ru index f7f29c8..7da3d65 100644 --- a/lib/smart_proxy_dynflow/http_config.ru +++ b/lib/smart_proxy_dynflow/http_config.ru @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'smart_proxy_dynflow/api' map "/dynflow" do diff --git a/lib/smart_proxy_dynflow/io_buffer.rb b/lib/smart_proxy_dynflow/io_buffer.rb index 98cdbfe..35477e4 100644 --- a/lib/smart_proxy_dynflow/io_buffer.rb +++ b/lib/smart_proxy_dynflow/io_buffer.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Proxy module Dynflow # A buffer around an IO object providing buffering and convenience methods @@ -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 @@ -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 diff --git a/lib/smart_proxy_dynflow/log.rb b/lib/smart_proxy_dynflow/log.rb index 5884eb3..e107884 100644 --- a/lib/smart_proxy_dynflow/log.rb +++ b/lib/smart_proxy_dynflow/log.rb @@ -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' diff --git a/lib/smart_proxy_dynflow/middleware/keep_current_request_id.rb b/lib/smart_proxy_dynflow/middleware/keep_current_request_id.rb index 3c59a22..8423d2a 100644 --- a/lib/smart_proxy_dynflow/middleware/keep_current_request_id.rb +++ b/lib/smart_proxy_dynflow/middleware/keep_current_request_id.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Actions module Middleware class KeepCurrentRequestID < Dynflow::Middleware @@ -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 diff --git a/lib/smart_proxy_dynflow/otp_manager.rb b/lib/smart_proxy_dynflow/otp_manager.rb index a165466..e6b7ba1 100644 --- a/lib/smart_proxy_dynflow/otp_manager.rb +++ b/lib/smart_proxy_dynflow/otp_manager.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'base64' require 'securerandom' @@ -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 diff --git a/lib/smart_proxy_dynflow/plugin.rb b/lib/smart_proxy_dynflow/plugin.rb index 4e55f07..11e1c63 100644 --- a/lib/smart_proxy_dynflow/plugin.rb +++ b/lib/smart_proxy_dynflow/plugin.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'proxy/log' require 'proxy/pluggable' require 'proxy/plugin' diff --git a/lib/smart_proxy_dynflow/process_manager.rb b/lib/smart_proxy_dynflow/process_manager.rb index dc57fb4..735b70e 100644 --- a/lib/smart_proxy_dynflow/process_manager.rb +++ b/lib/smart_proxy_dynflow/process_manager.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'smart_proxy_dynflow/io_buffer' module Proxy @@ -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?) diff --git a/lib/smart_proxy_dynflow/proxy_adapter.rb b/lib/smart_proxy_dynflow/proxy_adapter.rb index 8bb9a89..d7ec34d 100644 --- a/lib/smart_proxy_dynflow/proxy_adapter.rb +++ b/lib/smart_proxy_dynflow/proxy_adapter.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Proxy module Dynflow class ProxyAdapter < ::Dynflow::LoggerAdapters::Simple diff --git a/lib/smart_proxy_dynflow/runner.rb b/lib/smart_proxy_dynflow/runner.rb index d1d4e13..218d95f 100644 --- a/lib/smart_proxy_dynflow/runner.rb +++ b/lib/smart_proxy_dynflow/runner.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Proxy::Dynflow module Runner end diff --git a/lib/smart_proxy_dynflow/runner/base.rb b/lib/smart_proxy_dynflow/runner/base.rb index 451c63f..e2e39e4 100644 --- a/lib/smart_proxy_dynflow/runner/base.rb +++ b/lib/smart_proxy_dynflow/runner/base.rb @@ -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 @@ -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 @@ -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) diff --git a/lib/smart_proxy_dynflow/runner/command.rb b/lib/smart_proxy_dynflow/runner/command.rb index 6a55084..f6d6a41 100644 --- a/lib/smart_proxy_dynflow/runner/command.rb +++ b/lib/smart_proxy_dynflow/runner/command.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Proxy::Dynflow module Runner # This module expects to be included into a Runner action, where it can be @@ -22,6 +23,7 @@ def initialize_command(*command) def refresh return if @command_out.nil? + ready_outputs, * = IO.select([@command_out], nil, nil, 0.1) if ready_outputs if @command_out.nread.positive? diff --git a/lib/smart_proxy_dynflow/runner/command_runner.rb b/lib/smart_proxy_dynflow/runner/command_runner.rb index 2751419..a3b9c3f 100644 --- a/lib/smart_proxy_dynflow/runner/command_runner.rb +++ b/lib/smart_proxy_dynflow/runner/command_runner.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'io/wait' require 'pty' require 'smart_proxy_dynflow/runner/command' diff --git a/lib/smart_proxy_dynflow/runner/dispatcher.rb b/lib/smart_proxy_dynflow/runner/dispatcher.rb index 560930a..9b42533 100644 --- a/lib/smart_proxy_dynflow/runner/dispatcher.rb +++ b/lib/smart_proxy_dynflow/runner/dispatcher.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'smart_proxy_dynflow/ticker' module Proxy::Dynflow @@ -5,6 +6,7 @@ module Runner class Dispatcher def self.instance return @instance if @instance + @instance = new(Proxy::Dynflow::Core.world.clock, Proxy::Dynflow::Core.world.logger) end @@ -110,6 +112,7 @@ def handle_exception(exception, fatal = true) end attr_reader :ticker + def initialize(clock, logger) @mutex = Mutex.new @clock = clock @@ -126,14 +129,15 @@ def synchronize(&block) def start(suspended_action, runner) synchronize do raise "Actor with runner id #{runner.id} already exists" if @runner_actors[runner.id] + runner.logger = @logger runner_actor = RunnerActor.spawn("runner-actor-#{runner.id}", self, suspended_action, runner, @clock, @logger) @runner_actors[runner.id] = runner_actor @runner_suspended_actions[runner.id] = suspended_action runner_actor.tell(:start_runner) return runner.id - rescue => exception - _handle_command_exception(runner.id, exception) + rescue => e + _handle_command_exception(runner.id, e) return nil end end @@ -142,16 +146,16 @@ def kill(runner_id) synchronize do runner_actor = @runner_actors[runner_id] runner_actor&.tell(:kill) - rescue => exception - _handle_command_exception(runner_id, exception, false) + rescue => e + _handle_command_exception(runner_id, e, false) end end def finish(runner_id) synchronize do _finish(runner_id) - rescue => exception - _handle_command_exception(runner_id, exception, false) + rescue => e + _handle_command_exception(runner_id, e, false) end end @@ -181,6 +185,7 @@ def refresh_interval def _finish(runner_id) runner_actor = @runner_actors.delete(runner_id) return unless runner_actor + @logger.debug("closing session for command [#{runner_id}]," \ "#{@runner_actors.size} actors left ") runner_actor.tell([:start_termination, Concurrent::Promises.resolvable_future]) diff --git a/lib/smart_proxy_dynflow/runner/parent.rb b/lib/smart_proxy_dynflow/runner/parent.rb index 572eea0..1a4e2ad 100644 --- a/lib/smart_proxy_dynflow/runner/parent.rb +++ b/lib/smart_proxy_dynflow/runner/parent.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Proxy::Dynflow module Runner class Parent < Base diff --git a/lib/smart_proxy_dynflow/runner/process_manager_command.rb b/lib/smart_proxy_dynflow/runner/process_manager_command.rb index 169ac6b..e3b03f0 100644 --- a/lib/smart_proxy_dynflow/runner/process_manager_command.rb +++ b/lib/smart_proxy_dynflow/runner/process_manager_command.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'smart_proxy_dynflow/process_manager' module Proxy::Dynflow @@ -20,7 +21,7 @@ def initialize_command(*command) end end - def set_process_manager_callbacks(pm) + def set_process_manager_callbacks(pm) # rubocop:disable Naming/MethodParameterName pm.on_stdout do |data| publish_data(data, 'stdout') '' diff --git a/lib/smart_proxy_dynflow/runner/update.rb b/lib/smart_proxy_dynflow/runner/update.rb index 5f63085..990ce02 100644 --- a/lib/smart_proxy_dynflow/runner/update.rb +++ b/lib/smart_proxy_dynflow/runner/update.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'smart_proxy_dynflow/continuous_output' module Proxy::Dynflow @@ -6,6 +7,7 @@ module Runner # can be consumed by other components, such as RunnerAction class Update attr_reader :continuous_output, :exit_status + def initialize(continuous_output, exit_status) @continuous_output = continuous_output @exit_status = exit_status @@ -20,6 +22,7 @@ def self.encode_exception(context, exception, fatal = true) class ExternalEvent attr_reader :data + def initialize(data = {}) @data = data end diff --git a/lib/smart_proxy_dynflow/settings.rb b/lib/smart_proxy_dynflow/settings.rb index e90e0f7..ac89ad4 100644 --- a/lib/smart_proxy_dynflow/settings.rb +++ b/lib/smart_proxy_dynflow/settings.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # require 'ostruct' module Proxy::Dynflow diff --git a/lib/smart_proxy_dynflow/settings_loader.rb b/lib/smart_proxy_dynflow/settings_loader.rb index 368abd4..4e30e29 100644 --- a/lib/smart_proxy_dynflow/settings_loader.rb +++ b/lib/smart_proxy_dynflow/settings_loader.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Proxy::Dynflow module SettingsLoader def self.settings_registry @@ -21,6 +22,7 @@ def self.register_settings(names, object) names.each do |name| raise 'settings name has to be a symbol' unless name.is_a? Symbol raise "settings #{name} already registered" if SettingsLoader.settings_registered?(name) + name_to_settings[name] = object end settings_registry[names] = object @@ -28,6 +30,7 @@ def self.register_settings(names, object) def self.setup_settings(name, settings) raise "Settings for #{name} were not registered" unless settings_registered?(name) + name_to_settings[name].initialize_settings(settings) end @@ -43,6 +46,7 @@ def initialize_settings(settings = {}) def settings raise "Settings for #{self} not initalized" unless @settings + @settings end diff --git a/lib/smart_proxy_dynflow/task_launcher.rb b/lib/smart_proxy_dynflow/task_launcher.rb index 95a5d16..7d5d452 100644 --- a/lib/smart_proxy_dynflow/task_launcher.rb +++ b/lib/smart_proxy_dynflow/task_launcher.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Proxy::Dynflow module TaskLauncher end diff --git a/lib/smart_proxy_dynflow/task_launcher/abstract.rb b/lib/smart_proxy_dynflow/task_launcher/abstract.rb index f2e792d..86c3440 100644 --- a/lib/smart_proxy_dynflow/task_launcher/abstract.rb +++ b/lib/smart_proxy_dynflow/task_launcher/abstract.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true module Proxy::Dynflow module TaskLauncher class Abstract attr_reader :callback, :options, :results, :world + def initialize(world, callback, options = {}) @world = world @callback = callback diff --git a/lib/smart_proxy_dynflow/task_launcher/batch.rb b/lib/smart_proxy_dynflow/task_launcher/batch.rb index e39b1aa..7e20bc2 100644 --- a/lib/smart_proxy_dynflow/task_launcher/batch.rb +++ b/lib/smart_proxy_dynflow/task_launcher/batch.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Proxy::Dynflow module TaskLauncher class Batch < Abstract diff --git a/lib/smart_proxy_dynflow/task_launcher/group.rb b/lib/smart_proxy_dynflow/task_launcher/group.rb index d800182..d52dd6d 100644 --- a/lib/smart_proxy_dynflow/task_launcher/group.rb +++ b/lib/smart_proxy_dynflow/task_launcher/group.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'smart_proxy_dynflow/runner' module Proxy::Dynflow diff --git a/lib/smart_proxy_dynflow/task_launcher/single.rb b/lib/smart_proxy_dynflow/task_launcher/single.rb index 27d8751..ffb69a8 100644 --- a/lib/smart_proxy_dynflow/task_launcher/single.rb +++ b/lib/smart_proxy_dynflow/task_launcher/single.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Proxy::Dynflow module TaskLauncher class Single < Abstract diff --git a/lib/smart_proxy_dynflow/task_launcher_registry.rb b/lib/smart_proxy_dynflow/task_launcher_registry.rb index 9368b63..a089be0 100644 --- a/lib/smart_proxy_dynflow/task_launcher_registry.rb +++ b/lib/smart_proxy_dynflow/task_launcher_registry.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Proxy::Dynflow class TaskLauncherRegistry class << self diff --git a/lib/smart_proxy_dynflow/testing.rb b/lib/smart_proxy_dynflow/testing.rb index 20996a6..969bafb 100644 --- a/lib/smart_proxy_dynflow/testing.rb +++ b/lib/smart_proxy_dynflow/testing.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'dynflow/testing' unless defined? DYNFLOW_TESTING_LOG_LEVEL diff --git a/lib/smart_proxy_dynflow/ticker.rb b/lib/smart_proxy_dynflow/ticker.rb index fd21a44..22a46ad 100644 --- a/lib/smart_proxy_dynflow/ticker.rb +++ b/lib/smart_proxy_dynflow/ticker.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'dynflow' module Proxy::Dynflow diff --git a/lib/smart_proxy_dynflow/version.rb b/lib/smart_proxy_dynflow/version.rb index 34a9133..df569cc 100644 --- a/lib/smart_proxy_dynflow/version.rb +++ b/lib/smart_proxy_dynflow/version.rb @@ -1,5 +1,6 @@ +# frozen_string_literal: true module Proxy module Dynflow - VERSION = '0.9.0'.freeze + VERSION = '0.9.0' end end diff --git a/smart_proxy_dynflow.gemspec b/smart_proxy_dynflow.gemspec index 51497c0..46759f3 100644 --- a/smart_proxy_dynflow.gemspec +++ b/smart_proxy_dynflow.gemspec @@ -1,4 +1,5 @@ -lib = File.expand_path('../lib', __FILE__) +# frozen_string_literal: true +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'smart_proxy_dynflow/version' @@ -26,9 +27,5 @@ Gem::Specification.new do |gem| gem.add_runtime_dependency('sqlite3') gem.add_development_dependency "bundler", ">= 1.7" - gem.add_development_dependency 'minitest' - gem.add_development_dependency 'mocha', '~> 1' - gem.add_development_dependency 'rack-test', '~> 0' - gem.add_development_dependency "rake", "~> 10.0" - gem.add_development_dependency 'webmock', '~> 1' + gem.metadata['rubygems_mfa_required'] = 'true' end diff --git a/test/api_test.rb b/test/api_test.rb index f74484b..aae7c96 100644 --- a/test/api_test.rb +++ b/test/api_test.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true require 'test_helper' require 'json' -require 'smart_proxy_dynflow/api.rb' +require 'smart_proxy_dynflow/api' require 'smart_proxy_dynflow/runner/update' module Proxy::Dynflow diff --git a/test/callback_test.rb b/test/callback_test.rb index 486b91c..80ef314 100644 --- a/test/callback_test.rb +++ b/test/callback_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'test_helper' module Proxy diff --git a/test/dispatcher_test.rb b/test/dispatcher_test.rb index f89a659..3bdee92 100644 --- a/test/dispatcher_test.rb +++ b/test/dispatcher_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'test_helper' require 'smart_proxy_dynflow/runner' diff --git a/test/helpers_test.rb b/test/helpers_test.rb index 389aa76..9214cc6 100644 --- a/test/helpers_test.rb +++ b/test/helpers_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'ostruct' require 'test_helper' require 'smart_proxy_dynflow/otp_manager' @@ -16,18 +17,18 @@ def app it 'is not authenticated over HTTP' do get '/tasks/count', {}, {} - assert last_response.status == 200 + assert_equal last_response.status, 200 end it 'requires client SSL certificate when using https' do Log.instance.expects(:error) # HTTPS without client cert get '/tasks/count', {}, { 'HTTPS' => 'yes' } - assert last_response.status == 403 + assert_equal last_response.status, 403 # HTTPS with valid cert get '/tasks/count', {}, { 'HTTPS' => 'yes', 'SSL_CLIENT_CERT' => 'valid cert' } - assert last_response.status == 200 + assert_equal last_response.status, 200 end it 'performs token-based authentication for task update/done paths' do @@ -36,30 +37,30 @@ def app # Happy path for update otp = ::Proxy::Dynflow::OtpManager.generate_otp(username) - http_auth = 'Basic ' + ::Proxy::Dynflow::OtpManager.tokenize(username, otp) + http_auth = "Basic #{::Proxy::Dynflow::OtpManager.tokenize(username, otp)}" Log.instance.stubs(:debug) post "/tasks/#{task_id}/update", '{}', 'HTTP_AUTHORIZATION' => http_auth - assert last_response.status == 200 + assert_equal last_response.status, 200 # Wrong password - http_auth = 'Basic ' + ::Proxy::Dynflow::OtpManager.tokenize(username, 'wrong pass') + http_auth = "Basic #{::Proxy::Dynflow::OtpManager.tokenize(username, 'wrong pass')}" post "/tasks/#{task_id}/update", '{}', 'HTTP_AUTHORIZATION' => http_auth - assert last_response.status == 403 + assert_equal last_response.status, 403 # Wrong task id - http_auth = 'Basic ' + ::Proxy::Dynflow::OtpManager.tokenize(username, otp) + http_auth = "Basic #{::Proxy::Dynflow::OtpManager.tokenize(username, otp)}" post "/tasks/#{other_task_id}/update", '{}', 'HTTP_AUTHORIZATION' => http_auth - assert last_response.status == 403 + assert_equal last_response.status, 403 # Happy path for done - http_auth = 'Basic ' + ::Proxy::Dynflow::OtpManager.tokenize(username, otp) + http_auth = "Basic #{::Proxy::Dynflow::OtpManager.tokenize(username, otp)}" post "/tasks/#{task_id}/done", '{}', 'HTTP_AUTHORIZATION' => http_auth - assert last_response.status == 200 + assert_equal last_response.status, 200 # Call to done should remove the token, so using it the second time should fail - http_auth = 'Basic ' + ::Proxy::Dynflow::OtpManager.tokenize(username, otp) + http_auth = "Basic #{::Proxy::Dynflow::OtpManager.tokenize(username, otp)}" post "/tasks/#{task_id}/done", '{}', 'HTTP_AUTHORIZATION' => http_auth - assert last_response.status == 403 + assert_equal last_response.status, 403 end end end diff --git a/test/io_buffer_test.rb b/test/io_buffer_test.rb index 3800a56..b560731 100644 --- a/test/io_buffer_test.rb +++ b/test/io_buffer_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'test_helper' require 'smart_proxy_dynflow/io_buffer' require 'ostruct' @@ -8,7 +9,7 @@ class IOBufferTest let(:buffer) { IOBuffer.new(StringIO.new) } it 'is empty by default' do - assert buffer.empty? + assert_empty buffer assert_equal buffer.buffer, '' end diff --git a/test/otp_manager_test.rb b/test/otp_manager_test.rb index ae03c8c..05c82b3 100644 --- a/test/otp_manager_test.rb +++ b/test/otp_manager_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'test_helper' require 'smart_proxy_dynflow/otp_manager' diff --git a/test/process_manager_test.rb b/test/process_manager_test.rb index 1215689..9304a6d 100644 --- a/test/process_manager_test.rb +++ b/test/process_manager_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'test_helper' require 'smart_proxy_dynflow/process_manager' require 'ostruct' diff --git a/test/runner_test.rb b/test/runner_test.rb index 22460ac..cc721ba 100644 --- a/test/runner_test.rb +++ b/test/runner_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'test_helper' require 'smart_proxy_dynflow/runner' require 'ostruct' diff --git a/test/task_launcher_registry_test.rb b/test/task_launcher_registry_test.rb index 267889c..0ca8eca 100644 --- a/test/task_launcher_registry_test.rb +++ b/test/task_launcher_registry_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'test_helper' module Proxy::Dynflow diff --git a/test/task_launcher_test.rb b/test/task_launcher_test.rb index 0eb75c2..c03dd6b 100644 --- a/test/task_launcher_test.rb +++ b/test/task_launcher_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'test_helper' require 'smart_proxy_dynflow/action/batch' require 'smart_proxy_dynflow/task_launcher' diff --git a/test/test_helper.rb b/test/test_helper.rb index 4acd595..f4e7ba1 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'minitest/autorun' ENV['RACK_ENV'] = 'test' @@ -5,12 +6,15 @@ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', '..', 'lib') require 'mocha/minitest' require "rack/test" +require 'minitest/reporters' require 'smart_proxy_for_testing' require 'dynflow' require 'smart_proxy_dynflow' require 'smart_proxy_dynflow/testing' +Minitest::Reporters.use! + Proxy::Dynflow::Plugin.load_test_settings({}) logdir = File.join(File.dirname(__FILE__), '..', '..', 'logs') @@ -22,6 +26,7 @@ def wait_until(iterations: 10, interval: 0.2, msg: nil) iterations.times do return if yield + sleep interval end raise msg || "Failed waiting for something to happen"