summaryrefslogtreecommitdiff
path: root/scripts/lint-rugged
blob: ae5eddbe3b4b58e3e135980be659f1e374ebeda3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env ruby
# frozen_string_literal: true

ALLOWED = [
  # https://gitlab.com/gitlab-org/gitaly/issues/760
  'lib/elasticsearch/git/repository.rb',

  # Needed to handle repositories that are not in any storage
  'lib/gitlab/bare_repository_import/repository.rb',

  # Needed to avoid using the git binary to validate a branch name
  'lib/gitlab/git_ref_validator.rb',

  # Reverted Rugged calls due to Gitaly atop NFS performance
  # See https://docs.gitlab.com/ee/development/gitaly.html#legacy-rugged-code.
  'lib/gitlab/git/rugged_impl/',
  'lib/gitlab/gitaly_client/storage_settings.rb',

  # Needed to detect Rugged enabled: https://gitlab.com/gitlab-org/gitlab/issues/35371
  'lib/gitlab/config_checker/puma_rugged_checker.rb',

  # Needed for GPG/X509 commit signature API
  #
  'app/models/commit.rb',
  'lib/api/entities/commit_signature.rb',

  # Needed for logging
  'config/initializers/peek.rb',
  'config/initializers/lograge.rb',
  'lib/gitlab/grape_logging/loggers/perf_logger.rb',
  'lib/gitlab/instrumentation_helper.rb',
  'lib/gitlab/sidekiq_middleware/instrumentation_logger.rb',
  'lib/gitlab/rugged_instrumentation.rb',
  'lib/peek/views/rugged.rb'
].freeze

rugged_lines = IO.popen(%w[git grep -i -n rugged -- app config lib], &:read).lines
rugged_lines = rugged_lines.select { |l| /^[^:]*\.rb:/ =~ l }
rugged_lines = rugged_lines.reject { |l| l.start_with?(*ALLOWED) }
rugged_lines = rugged_lines.reject { |l| /(include|prepend) Gitlab::Git::RuggedImpl/ =~ l }
rugged_lines = rugged_lines.reject { |l| l.include?('Gitlab::ConfigChecker::PumaRuggedChecker.check') }
rugged_lines = rugged_lines.reject do |line|
  code, _comment = line.split('# ', 2)
  code !~ /rugged/i
end

exit if rugged_lines.empty?

puts "Using Rugged is only allowed in test and #{ALLOWED}\n\n"

puts rugged_lines

exit(false)