debian-mirror-gitlab/lib/gitlab/gitaly_client/storage_settings.rb

71 lines
2.3 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2018-05-09 12:01:36 +05:30
module Gitlab
module GitalyClient
# This is a chokepoint that is meant to help us stop remove all places
# where production code (app, config, db, lib) touches Git repositories
# directly.
class StorageSettings
2018-11-08 19:23:39 +05:30
extend Gitlab::TemporarilyAllow
2018-05-09 12:01:36 +05:30
DirectPathAccessError = Class.new(StandardError)
2018-11-08 19:23:39 +05:30
InvalidConfigurationError = Class.new(StandardError)
INVALID_STORAGE_MESSAGE = <<~MSG.freeze
Storage is invalid because it has no `path` key.
For source installations, update your config/gitlab.yml Refer to gitlab.yml.example for an updated example.
2018-12-05 23:21:45 +05:30
If you're using the GitLab Development Kit, you can update your configuration running `gdk reconfigure`.
2018-11-08 19:23:39 +05:30
MSG
2018-05-09 12:01:36 +05:30
# This class will give easily recognizable NoMethodErrors
Deprecated = Class.new
2018-11-08 19:23:39 +05:30
MUTEX = Mutex.new
DISK_ACCESS_DENIED_FLAG = :deny_disk_access
ALLOW_KEY = :allow_disk_access
# If your code needs this method then your code needs to be fixed.
def self.allow_disk_access
temporarily_allow(ALLOW_KEY) { yield }
end
def self.disk_access_denied?
!temporarily_allowed?(ALLOW_KEY) && GitalyClient.feature_enabled?(DISK_ACCESS_DENIED_FLAG)
rescue
false # Err on the side of caution, don't break gitlab for people
end
2018-05-09 12:01:36 +05:30
def initialize(storage)
2018-11-08 19:23:39 +05:30
raise InvalidConfigurationError, "expected a Hash, got a #{storage.class.name}" unless storage.is_a?(Hash)
raise InvalidConfigurationError, INVALID_STORAGE_MESSAGE unless storage.has_key?('path')
2018-05-09 12:01:36 +05:30
# Support a nil 'path' field because some of the circuit breaker tests use it.
@legacy_disk_path = File.expand_path(storage['path'], Rails.root) if storage['path']
storage['path'] = Deprecated
@hash = storage
end
def gitaly_address
@hash.fetch(:gitaly_address)
end
2018-11-08 19:23:39 +05:30
def legacy_disk_path
if self.class.disk_access_denied?
raise DirectPathAccessError, "git disk access denied via the gitaly_#{DISK_ACCESS_DENIED_FLAG} feature"
end
@legacy_disk_path
end
2018-05-09 12:01:36 +05:30
private
2018-11-18 11:00:15 +05:30
def method_missing(msg, *args, &block)
@hash.public_send(msg, *args, &block) # rubocop:disable GitlabSecurity/PublicSend
2018-05-09 12:01:36 +05:30
end
end
end
end