2019-06-12 14:20:01 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-06-12 13:32:29 +00:00
|
|
|
class Feature
|
|
|
|
class Gitaly
|
2020-02-12 12:09:01 +00:00
|
|
|
PREFIX = "gitaly_"
|
2019-06-12 13:32:29 +00:00
|
|
|
|
|
|
|
class << self
|
2021-02-16 15:09:50 +00:00
|
|
|
def enabled?(feature_flag, project = nil)
|
2019-06-12 14:20:01 +00:00
|
|
|
return false unless Feature::FlipperFeature.table_exists?
|
|
|
|
|
2022-05-11 00:08:02 +00:00
|
|
|
Feature.enabled?("#{PREFIX}#{feature_flag}", project, type: :undefined, default_enabled_if_undefined: false)
|
2019-10-22 06:06:38 +00:00
|
|
|
rescue ActiveRecord::NoDatabaseError, PG::ConnectionBad
|
2019-06-12 13:32:29 +00:00
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2021-02-16 15:09:50 +00:00
|
|
|
def server_feature_flags(project = nil)
|
2020-03-31 12:08:09 +00:00
|
|
|
# We need to check that both the DB connection and table exists
|
2021-11-15 15:10:57 +00:00
|
|
|
return {} unless FlipperFeature.database.cached_table_exists?
|
2020-03-31 12:08:09 +00:00
|
|
|
|
2020-02-12 12:09:01 +00:00
|
|
|
Feature.persisted_names
|
|
|
|
.select { |f| f.start_with?(PREFIX) }
|
2021-02-16 15:09:50 +00:00
|
|
|
.to_h do |f|
|
2020-02-12 12:09:01 +00:00
|
|
|
flag = f.delete_prefix(PREFIX)
|
|
|
|
|
2021-02-16 15:09:50 +00:00
|
|
|
["gitaly-feature-#{flag.tr('_', '-')}", enabled?(flag, project).to_s]
|
|
|
|
end
|
2019-06-12 13:32:29 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|