Class: Gitlab::GitalyClient::StorageSettings
- Inherits:
-
Object
- Object
- Gitlab::GitalyClient::StorageSettings
- Extended by:
- TemporarilyAllow
- Defined in:
- lib/gitlab/gitaly_client/storage_settings.rb
Overview
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.
Constant Summary collapse
- DirectPathAccessError =
Class.new(StandardError)
- 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. If you're using the GitLab Development Kit, you can update your configuration running `gdk reconfigure`. MSG
- Deprecated =
This class will give easily recognizable NoMethodErrors
Class.new
- MUTEX =
Mutex.new
- DISK_ACCESS_DENIED_FLAG =
:deny_disk_access
- ALLOW_KEY =
:allow_disk_access
Constants included from TemporarilyAllow
TemporarilyAllow::TEMPORARILY_ALLOW_MUTEX
Class Method Summary collapse
-
.allow_disk_access ⇒ Object
If your code needs this method then your code needs to be fixed.
- .disk_access_denied? ⇒ Boolean
- .rugged_enabled? ⇒ Boolean
Instance Method Summary collapse
- #gitaly_address ⇒ Object
-
#initialize(storage) ⇒ StorageSettings
constructor
A new instance of StorageSettings.
- #legacy_disk_path ⇒ Object
Methods included from TemporarilyAllow
temporarily_allow, temporarily_allowed?
Constructor Details
#initialize(storage) ⇒ StorageSettings
Returns a new instance of StorageSettings.
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/gitlab/gitaly_client/storage_settings.rb', line 48 def initialize(storage) 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') # Support a nil 'path' field because some of the circuit breaker tests use it. @legacy_disk_path = File.(storage['path'], Rails.root) if storage['path'] storage['path'] = Deprecated @hash = storage.with_indifferent_access end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(msg, *args, &block) ⇒ Object (private)
73 74 75 |
# File 'lib/gitlab/gitaly_client/storage_settings.rb', line 73 def method_missing(msg, *args, &block) @hash.public_send(msg, *args, &block) # rubocop:disable GitlabSecurity/PublicSend end |
Class Method Details
.allow_disk_access ⇒ Object
If your code needs this method then your code needs to be fixed.
30 31 32 |
# File 'lib/gitlab/gitaly_client/storage_settings.rb', line 30 def self.allow_disk_access temporarily_allow(ALLOW_KEY) { yield } end |
.disk_access_denied? ⇒ Boolean
34 35 36 37 38 39 40 |
# File 'lib/gitlab/gitaly_client/storage_settings.rb', line 34 def self.disk_access_denied? return false if rugged_enabled? !temporarily_allowed?(ALLOW_KEY) && Feature::Gitaly.enabled?(DISK_ACCESS_DENIED_FLAG) rescue false # Err on the side of caution, don't break gitlab for people end |
.rugged_enabled? ⇒ Boolean
42 43 44 45 46 |
# File 'lib/gitlab/gitaly_client/storage_settings.rb', line 42 def self.rugged_enabled? Gitlab::Git::RuggedImpl::Repository::FEATURE_FLAGS.any? do |flag| Feature.enabled?(flag) end end |
Instance Method Details
#gitaly_address ⇒ Object
59 60 61 |
# File 'lib/gitlab/gitaly_client/storage_settings.rb', line 59 def gitaly_address @hash.fetch(:gitaly_address) end |
#legacy_disk_path ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/gitlab/gitaly_client/storage_settings.rb', line 63 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 |