2019-06-12 10:20:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'set'
|
|
|
|
|
2019-06-12 09:32:29 -04:00
|
|
|
class Feature
|
|
|
|
class Gitaly
|
2019-06-12 10:20:01 -04:00
|
|
|
# Server feature flags should use '_' to separate words.
|
|
|
|
# CATFILE_CACHE sets an incorrect example
|
2019-06-12 09:32:29 -04:00
|
|
|
CATFILE_CACHE = 'catfile-cache'.freeze
|
|
|
|
|
|
|
|
SERVER_FEATURE_FLAGS = [CATFILE_CACHE].freeze
|
2019-06-12 10:20:01 -04:00
|
|
|
DEFAULT_ON_FLAGS = Set.new([CATFILE_CACHE]).freeze
|
2019-06-12 09:32:29 -04:00
|
|
|
|
|
|
|
class << self
|
|
|
|
def enabled?(feature_flag)
|
2019-06-12 10:20:01 -04:00
|
|
|
return false unless Feature::FlipperFeature.table_exists?
|
|
|
|
|
|
|
|
default_on = DEFAULT_ON_FLAGS.include?(feature_flag)
|
|
|
|
Feature.enabled?("gitaly_#{feature_flag}", default_enabled: default_on)
|
2019-06-12 09:32:29 -04:00
|
|
|
rescue ActiveRecord::NoDatabaseError
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def server_feature_flags
|
2019-06-12 10:20:01 -04:00
|
|
|
SERVER_FEATURE_FLAGS.map do |f|
|
|
|
|
["gitaly-feature-#{f.tr('_', '-')}", enabled?(f).to_s]
|
|
|
|
end.to_h
|
2019-06-12 09:32:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|