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