Commit f83801a9 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Update files to pass modern rubocop checks. Disable some of them

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 8f9046aa
This diff is collapsed.
...@@ -14,7 +14,7 @@ class GitAccessStatus ...@@ -14,7 +14,7 @@ class GitAccessStatus
def self.create_from_json(json) def self.create_from_json(json)
values = JSON.parse(json) values = JSON.parse(json)
self.new(values["status"], new(values["status"],
values["message"], values["message"],
gl_repository: values["gl_repository"], gl_repository: values["gl_repository"],
gl_username: values["gl_username"], gl_username: values["gl_username"],
......
...@@ -47,7 +47,7 @@ class GitlabCustomHook ...@@ -47,7 +47,7 @@ class GitlabCustomHook
# Submit changes to the hook via its stdin. # Submit changes to the hook via its stdin.
begin begin
IO.copy_stream(StringIO.new(changes), stdin_writer) IO.copy_stream(StringIO.new(changes), stdin_writer)
rescue Errno::EPIPE rescue Errno::EPIPE # rubocop:disable Lint/HandleExceptions
# It is not an error if the hook does not consume all of its input. # It is not an error if the hook does not consume all of its input.
end end
......
...@@ -4,19 +4,26 @@ require_relative 'gitlab_config' ...@@ -4,19 +4,26 @@ require_relative 'gitlab_config'
require_relative 'gitlab_logger' require_relative 'gitlab_logger'
require_relative 'gitlab_metrics' require_relative 'gitlab_metrics'
class GitlabKeys class GitlabKeys # rubocop:disable Metrics/ClassLength
class KeyError < StandardError ; end class KeyError < StandardError; end
attr_accessor :auth_file, :key attr_accessor :auth_file, :key
def self.command(key_id) def self.command(key_id)
raise KeyError.new("Invalid key_id: #{key_id.inspect}") unless /\A[a-z0-9-]+\z/ =~ key_id unless /\A[a-z0-9-]+\z/ =~ key_id
raise KeyError, "Invalid key_id: #{key_id.inspect}"
end
"#{ROOT_PATH}/bin/gitlab-shell #{key_id}" "#{ROOT_PATH}/bin/gitlab-shell #{key_id}"
end end
def self.key_line(key_id, public_key) def self.key_line(key_id, public_key)
public_key.chomp! public_key.chomp!
raise KeyError.new("Invalid public_key: #{public_key.inspect}") if public_key.include?("\n")
if public_key.include?("\n")
raise KeyError, "Invalid public_key: #{public_key.inspect}"
end
"command=\"#{command(key_id)}\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty #{public_key}" "command=\"#{command(key_id)}\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty #{public_key}"
end end
...@@ -31,19 +38,19 @@ class GitlabKeys ...@@ -31,19 +38,19 @@ class GitlabKeys
def exec def exec
GitlabMetrics.measure("command-#{@command}") do GitlabMetrics.measure("command-#{@command}") do
case @command case @command
when 'add-key'; when 'add-key'
add_key add_key
when 'batch-add-keys'; when 'batch-add-keys'
batch_add_keys batch_add_keys
when 'rm-key'; when 'rm-key'
rm_key rm_key
when 'list-keys'; when 'list-keys'
list_keys list_keys
when 'list-key-ids'; when 'list-key-ids'
list_key_ids list_key_ids
when 'clear'; when 'clear'
clear clear
when 'check-permissions'; when 'check-permissions'
check_permissions check_permissions
else else
$logger.warn "Attempt to execute invalid gitlab-keys command #{@command.inspect}." $logger.warn "Attempt to execute invalid gitlab-keys command #{@command.inspect}."
...@@ -111,7 +118,7 @@ class GitlabKeys ...@@ -111,7 +118,7 @@ class GitlabKeys
lock do lock do
$logger.info "Removing key #{@key_id}" $logger.info "Removing key #{@key_id}"
open_auth_file('r+') do |f| open_auth_file('r+') do |f|
while line = f.gets do while line = f.gets # rubocop:disable Style/AssignmentInCondition
next unless line.start_with?("command=\"#{self.class.command(@key_id)}\"") next unless line.start_with?("command=\"#{self.class.command(@key_id)}\"")
f.seek(-line.length, IO::SEEK_CUR) f.seek(-line.length, IO::SEEK_CUR)
# Overwrite the line with #'s. Because the 'line' variable contains # Overwrite the line with #'s. Because the 'line' variable contains
...@@ -145,7 +152,7 @@ class GitlabKeys ...@@ -145,7 +152,7 @@ class GitlabKeys
File.open(lock_file, "w+") do |f| File.open(lock_file, "w+") do |f|
begin begin
f.flock File::LOCK_EX f.flock File::LOCK_EX
Timeout::timeout(timeout) { yield } Timeout.timeout(timeout) { yield }
ensure ensure
f.flock File::LOCK_UN f.flock File::LOCK_UN
end end
......
...@@ -11,13 +11,11 @@ class GitlabLfsAuthentication ...@@ -11,13 +11,11 @@ class GitlabLfsAuthentication
end end
def self.build_from_json(json) def self.build_from_json(json)
begin
values = JSON.parse(json) values = JSON.parse(json)
self.new(values['username'], values['lfs_token'], values['repository_http_path']) new(values['username'], values['lfs_token'], values['repository_http_path'])
rescue rescue
nil nil
end end
end
def authentication_payload def authentication_payload
authorization = { authorization = {
......
...@@ -2,7 +2,7 @@ require 'logger' ...@@ -2,7 +2,7 @@ require 'logger'
require_relative 'gitlab_config' require_relative 'gitlab_config'
def convert_log_level log_level def convert_log_level(log_level)
Logger.const_get(log_level.upcase) Logger.const_get(log_level.upcase)
rescue NameError rescue NameError
$stderr.puts "WARNING: Unrecognized log level #{log_level.inspect}." $stderr.puts "WARNING: Unrecognized log level #{log_level.inspect}."
......
...@@ -8,7 +8,7 @@ require_relative 'gitlab_access' ...@@ -8,7 +8,7 @@ require_relative 'gitlab_access'
require_relative 'gitlab_lfs_authentication' require_relative 'gitlab_lfs_authentication'
require_relative 'httpunix' require_relative 'httpunix'
class GitlabNet class GitlabNet # rubocop:disable Metrics/ClassLength
class ApiUnreachableError < StandardError; end class ApiUnreachableError < StandardError; end
class NotFound < StandardError; end class NotFound < StandardError; end
...@@ -16,7 +16,7 @@ class GitlabNet ...@@ -16,7 +16,7 @@ class GitlabNet
READ_TIMEOUT = 300 READ_TIMEOUT = 300
def check_access(cmd, gl_repository, repo, actor, changes, protocol, env: {}) def check_access(cmd, gl_repository, repo, actor, changes, protocol, env: {})
changes = changes.join("\n") unless changes.kind_of?(String) changes = changes.join("\n") unless changes.is_a?(String)
params = { params = {
action: cmd, action: cmd,
...@@ -73,7 +73,7 @@ class GitlabNet ...@@ -73,7 +73,7 @@ class GitlabNet
end end
def merge_request_urls(gl_repository, repo_path, changes) def merge_request_urls(gl_repository, repo_path, changes)
changes = changes.join("\n") unless changes.kind_of?(String) changes = changes.join("\n") unless changes.is_a?(String)
changes = changes.encode('UTF-8', 'ASCII', invalid: :replace, replace: '') changes = changes.encode('UTF-8', 'ASCII', invalid: :replace, replace: '')
url = "#{host}/merge_request_urls?project=#{URI.escape(repo_path)}&changes=#{URI.escape(changes)}" url = "#{host}/merge_request_urls?project=#{URI.escape(repo_path)}&changes=#{URI.escape(changes)}"
url += "&gl_repository=#{URI.escape(gl_repository)}" if gl_repository url += "&gl_repository=#{URI.escape(gl_repository)}" if gl_repository
...@@ -152,7 +152,7 @@ class GitlabNet ...@@ -152,7 +152,7 @@ class GitlabNet
"#{config.gitlab_url}/api/v4/internal" "#{config.gitlab_url}/api/v4/internal"
end end
def http_client_for(uri, options={}) def http_client_for(uri, options = {})
http = if uri.is_a?(URI::HTTPUNIX) http = if uri.is_a?(URI::HTTPUNIX)
Net::HTTPUNIX.new(uri.hostname) Net::HTTPUNIX.new(uri.hostname)
else else
...@@ -189,7 +189,7 @@ class GitlabNet ...@@ -189,7 +189,7 @@ class GitlabNet
request request
end end
def request(method, url, params = {}, options={}) def request(method, url, params = {}, options = {})
$logger.debug "Performing #{method.to_s.upcase} #{url}" $logger.debug "Performing #{method.to_s.upcase} #{url}"
uri = URI.parse(url) uri = URI.parse(url)
...@@ -205,7 +205,7 @@ class GitlabNet ...@@ -205,7 +205,7 @@ class GitlabNet
raise ApiUnreachableError raise ApiUnreachableError
ensure ensure
$logger.info do $logger.info do
sprintf('%s %s %0.5f', method.to_s.upcase, url, Time.new - start_time) sprintf('%s %s %0.5f', method.to_s.upcase, url, Time.new - start_time) # rubocop:disable Style/FormatString
end end
end end
...@@ -218,7 +218,7 @@ class GitlabNet ...@@ -218,7 +218,7 @@ class GitlabNet
response response
end end
def get(url, options={}) def get(url, options = {})
request(:get, url, {}, options) request(:get, url, {}, options)
end end
...@@ -231,13 +231,11 @@ class GitlabNet ...@@ -231,13 +231,11 @@ class GitlabNet
store = OpenSSL::X509::Store.new store = OpenSSL::X509::Store.new
store.set_default_paths store.set_default_paths
if ca_file = config.http_settings['ca_file'] ca_file = config.http_settings['ca_file']
store.add_file(ca_file) store.add_file(ca_file) if ca_file
end
if ca_path = config.http_settings['ca_path'] ca_path = config.http_settings['ca_path']
store.add_path(ca_path) store.add_path(ca_path) if ca_path
end
store store
end end
......
...@@ -50,9 +50,9 @@ class GitlabPostReceive ...@@ -50,9 +50,9 @@ class GitlabPostReceive
def print_merge_request_link(merge_request) def print_merge_request_link(merge_request)
message = message =
if merge_request["new_merge_request"] if merge_request["new_merge_request"]
"To create a merge request for #{merge_request["branch_name"]}, visit:" "To create a merge request for #{merge_request['branch_name']}, visit:"
else else
"View merge request for #{merge_request["branch_name"]}:" "View merge request for #{merge_request['branch_name']}:"
end end
puts message puts message
......
...@@ -4,7 +4,7 @@ require 'pathname' ...@@ -4,7 +4,7 @@ require 'pathname'
require_relative 'gitlab_net' require_relative 'gitlab_net'
require_relative 'gitlab_metrics' require_relative 'gitlab_metrics'
class GitlabShell class GitlabShell # rubocop:disable Metrics/ClassLength
class AccessDeniedError < StandardError; end class AccessDeniedError < StandardError; end
class DisallowedCommandError < StandardError; end class DisallowedCommandError < StandardError; end
class InvalidRepositoryPathError < StandardError; end class InvalidRepositoryPathError < StandardError; end
...@@ -12,7 +12,7 @@ class GitlabShell ...@@ -12,7 +12,7 @@ class GitlabShell
GIT_COMMANDS = %w(git-upload-pack git-receive-pack git-upload-archive git-lfs-authenticate).freeze GIT_COMMANDS = %w(git-upload-pack git-receive-pack git-upload-archive git-lfs-authenticate).freeze
GITALY_MIGRATED_COMMANDS = { GITALY_MIGRATED_COMMANDS = {
'git-upload-pack' => File.join(ROOT_PATH, 'bin', 'gitaly-upload-pack'), 'git-upload-pack' => File.join(ROOT_PATH, 'bin', 'gitaly-upload-pack'),
'git-receive-pack' => File.join(ROOT_PATH, 'bin', 'gitaly-receive-pack'), 'git-receive-pack' => File.join(ROOT_PATH, 'bin', 'gitaly-receive-pack')
}.freeze }.freeze
API_COMMANDS = %w(2fa_recovery_codes).freeze API_COMMANDS = %w(2fa_recovery_codes).freeze
GL_PROTOCOL = 'ssh'.freeze GL_PROTOCOL = 'ssh'.freeze
...@@ -44,7 +44,7 @@ class GitlabShell ...@@ -44,7 +44,7 @@ class GitlabShell
process_cmd(args) process_cmd(args)
true true
rescue GitlabNet::ApiUnreachableError => ex rescue GitlabNet::ApiUnreachableError
$stderr.puts "GitLab: Failed to authorize your Git request: internal API unreachable" $stderr.puts "GitLab: Failed to authorize your Git request: internal API unreachable"
false false
rescue AccessDeniedError => ex rescue AccessDeniedError => ex
...@@ -53,13 +53,13 @@ class GitlabShell ...@@ -53,13 +53,13 @@ class GitlabShell
$stderr.puts "GitLab: #{ex.message}" $stderr.puts "GitLab: #{ex.message}"
false false
rescue DisallowedCommandError => ex rescue DisallowedCommandError
message = "gitlab-shell: Attempt to execute disallowed command <#{origin_cmd}> by #{log_username}." message = "gitlab-shell: Attempt to execute disallowed command <#{origin_cmd}> by #{log_username}."
$logger.warn message $logger.warn message
$stderr.puts "GitLab: Disallowed command" $stderr.puts "GitLab: Disallowed command"
false false
rescue InvalidRepositoryPathError => ex rescue InvalidRepositoryPathError
$stderr.puts "GitLab: Invalid repository path" $stderr.puts "GitLab: Invalid repository path"
false false
end end
...@@ -113,7 +113,7 @@ class GitlabShell ...@@ -113,7 +113,7 @@ class GitlabShell
end end
def process_cmd(args) def process_cmd(args)
return self.send("api_#{@command}") if API_COMMANDS.include?(@command) return send("api_#{@command}") if API_COMMANDS.include?(@command)
if @command == 'git-lfs-authenticate' if @command == 'git-lfs-authenticate'
GitlabMetrics.measure('lfs-authenticate') do GitlabMetrics.measure('lfs-authenticate') do
...@@ -126,7 +126,7 @@ class GitlabShell ...@@ -126,7 +126,7 @@ class GitlabShell
executable = @command executable = @command
args = [repo_path] args = [repo_path]
if GITALY_MIGRATED_COMMANDS.has_key?(executable) && @gitaly if GITALY_MIGRATED_COMMANDS.key?(executable) && @gitaly
executable = GITALY_MIGRATED_COMMANDS[executable] executable = GITALY_MIGRATED_COMMANDS[executable]
gitaly_address = @gitaly['address'] gitaly_address = @gitaly['address']
...@@ -172,15 +172,15 @@ class GitlabShell ...@@ -172,15 +172,15 @@ class GitlabShell
end end
if git_trace_available? if git_trace_available?
env.merge!({ env.merge!(
'GIT_TRACE' => @config.git_trace_log_file, 'GIT_TRACE' => @config.git_trace_log_file,
'GIT_TRACE_PACKET' => @config.git_trace_log_file, 'GIT_TRACE_PACKET' => @config.git_trace_log_file,
'GIT_TRACE_PERFORMANCE' => @config.git_trace_log_file, 'GIT_TRACE_PERFORMANCE' => @config.git_trace_log_file
}) )
end end
# We use 'chdir: ROOT_PATH' to let the next executable know where config.yml is. # We use 'chdir: ROOT_PATH' to let the next executable know where config.yml is.
Kernel::exec(env, *args, unsetenv_others: true, chdir: ROOT_PATH) Kernel.exec(env, *args, unsetenv_others: true, chdir: ROOT_PATH)
end end
def api def api
......
...@@ -11,7 +11,7 @@ module URI ...@@ -11,7 +11,7 @@ module URI
class HTTPUNIX < HTTP class HTTPUNIX < HTTP
def hostname def hostname
# decode %XX from path to file # decode %XX from path to file
v = self.host v = host
URI.decode(v) URI.decode(v)
end end
...@@ -30,7 +30,7 @@ end ...@@ -30,7 +30,7 @@ end
# - Net::HTTP::connect # - Net::HTTP::connect
module Net module Net
class HTTPUNIX < HTTP class HTTPUNIX < HTTP
def initialize(socketpath, port=nil) def initialize(socketpath, port = nil)
super(socketpath, port) super(socketpath, port)
@port = nil # HTTP will set it to default - override back -> set DEFAULT_PORT @port = nil # HTTP will set it to default - override back -> set DEFAULT_PORT
end end
......
...@@ -5,7 +5,7 @@ def main(check) ...@@ -5,7 +5,7 @@ def main(check)
cmd = %w[gofmt -s -l] cmd = %w[gofmt -s -l]
cmd << '-w' unless check cmd << '-w' unless check
cmd += go_files cmd += go_files
output = IO.popen(cmd, 'r') { |io| io.read } output = IO.popen(cmd, 'r', &:read)
$stdout.write(output) $stdout.write(output)
abort 'gofmt failed' unless $?.success? abort 'gofmt failed' unless $?.success?
if check && output.lines.any? { |l| l != "\n" } if check && output.lines.any? { |l| l != "\n" }
......
...@@ -12,7 +12,7 @@ module GoBuild ...@@ -12,7 +12,7 @@ module GoBuild
GO_ENV = { GO_ENV = {
'GOPATH' => BUILD_DIR, 'GOPATH' => BUILD_DIR,
'GO15VENDOREXPERIMENT' => '1', 'GO15VENDOREXPERIMENT' => '1'
}.freeze }.freeze
def create_fresh_build_dir def create_fresh_build_dir
...@@ -26,7 +26,7 @@ module GoBuild ...@@ -26,7 +26,7 @@ module GoBuild
raise "env must be a hash" unless env.is_a?(Hash) raise "env must be a hash" unless env.is_a?(Hash)
raise "cmd must be an array" unless cmd.is_a?(Array) raise "cmd must be an array" unless cmd.is_a?(Array)
if !system(env, *cmd) unless system(env, *cmd)
abort "command failed: #{env.inspect} #{cmd.join(' ')}" abort "command failed: #{env.inspect} #{cmd.join(' ')}"
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment