diff --git a/.rubocop.yml b/.rubocop.yml index b5bcb01..c49dfc8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,6 +5,12 @@ require: AllCops: NewCops: enable + Exclude: + - 'lib/hawksi.rb' + +Style/HashSyntax: + Enabled: false + Layout/HeredocIndentation: Exclude: - 'lib/hawksi.rb' diff --git a/Gemfile b/Gemfile index c89eded..330ef14 100644 --- a/Gemfile +++ b/Gemfile @@ -12,7 +12,7 @@ group :development, :test do gem 'bundler' gem 'rake' gem 'rspec', '~> 3.13' - gem 'rubocop' + gem 'rubocop', '1.66.1' gem 'rubocop-rake' gem 'rubocop-rspec' gem 'ruby-lsp' diff --git a/Gemfile.lock b/Gemfile.lock index f143962..7f95f12 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -78,7 +78,7 @@ DEPENDENCIES rack-test (~> 1.1) rake rspec (~> 3.13) - rubocop + rubocop (= 1.66.1) rubocop-rake rubocop-rspec ruby-lsp diff --git a/lib/command_executor.rb b/lib/command_executor.rb index 217d5c7..135cd54 100644 --- a/lib/command_executor.rb +++ b/lib/command_executor.rb @@ -34,7 +34,7 @@ def execute_command(command, params) # rubocop:disable Metrics/MethodLength def build_request_body(command, params) { client_id: client_uuid, - command:, + command: command, instructions: params.join(' ') }.to_json end diff --git a/lib/hawksi.rb b/lib/hawksi.rb index 764d9fd..3195238 100644 --- a/lib/hawksi.rb +++ b/lib/hawksi.rb @@ -2,15 +2,13 @@ require 'cli' require 'request_interceptor' - BANNER = <<~BANNER _ _ - /\ /\__ ___ _| | _____(_) - / /_/ / _` \ \ /\ / / |/ / __| | -/ __ / (_| |\ V V /| <\__ \ | -\/ /_/ \__,_| \_/\_/ |_|\_\___/_| + /\\ /\\__ ___ _| | _____(_) + / /_/ / _` \\ \\ /\\ / / |/ / __| | +/ __ / (_| |\\ V V /| <\\__ \\ | +\\/ /_/ \\__,_| \\_/\\_/ |_|\\_\\___/_| BANNER - puts BANNER \ No newline at end of file diff --git a/lib/mocksi_handler.rb b/lib/mocksi_handler.rb index 8b4f001..dfd61e6 100644 --- a/lib/mocksi_handler.rb +++ b/lib/mocksi_handler.rb @@ -14,9 +14,11 @@ class << self def fetch_mocksi_server_url mocksi_server_url = Hawksi.configuration.mocksi_server raise 'Mocksi server URL not configured' if mocksi_server_url.nil? || mocksi_server_url.empty? + + mocksi_server_url end - def prep_headers((request)) + def prep_headers(request) headers = {} request.env.each do |key, value| if key.start_with?('HTTP_') @@ -57,7 +59,7 @@ def handle(request) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize headers['Cookie'] = request.cookies.map { |k, v| "#{k}=#{v}" }.join('; ') if request.cookies.any? # Initialize httpx with headers - http_client = HTTPX.with(headers:) + http_client = HTTPX.with(headers: headers) # Forward the body content if it's a POST or PUT request body = nil @@ -66,7 +68,9 @@ def handle(request) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize body = request.body.read end - response = http_client.request(request.request_method.downcase.to_sym, target_uri, body:) + response = http_client.request(request.request_method.downcase.to_sym, target_uri, body: body) + response_body = build_response_body(response) + response_headers = response.headers.to_h # Return the response in a format compatible with Rack [response.status, response_headers, [response_body]] diff --git a/spec/lib/request_interceptor_spec.rb b/spec/lib/request_interceptor_spec.rb index 9a0f9bc..6665dea 100644 --- a/spec/lib/request_interceptor_spec.rb +++ b/spec/lib/request_interceptor_spec.rb @@ -11,7 +11,7 @@ let(:app) { ->(_env) { [200, { 'Content-Type' => 'text/plain' }, ['Hello']] } } let(:logger) { double('Logger') } # rubocop:disable RSpec/VerifiedDoubles let(:storage) { double('FileStorage') } # rubocop:disable RSpec/VerifiedDoubles - let(:request_interceptor) { described_class.new(app, logger:, storage:) } + let(:request_interceptor) { described_class.new(app, logger: logger, storage: storage) } before do allow(logger).to receive(:info)