2015-11-06 05:22:30 +08:00
|
|
|
module Services
|
|
|
|
class RichContent
|
2016-02-26 04:59:36 +08:00
|
|
|
|
2015-11-06 05:22:30 +08:00
|
|
|
def self.env_for(root_account)
|
2016-02-26 04:59:36 +08:00
|
|
|
enabled = check_feature_flag(root_account, :rich_content_service)
|
2015-11-06 05:22:30 +08:00
|
|
|
env_hash = { RICH_CONTENT_SERVICE_ENABLED: enabled }
|
|
|
|
if enabled
|
2016-02-26 04:59:36 +08:00
|
|
|
env_hash = env_hash.merge(fine_grained_flags(root_account))
|
|
|
|
env_hash = env_hash.merge(service_settings)
|
2015-11-06 05:22:30 +08:00
|
|
|
end
|
|
|
|
env_hash
|
|
|
|
end
|
|
|
|
|
2016-02-26 04:59:36 +08:00
|
|
|
class << self
|
|
|
|
private
|
|
|
|
def check_feature_flag(root_account, flag)
|
|
|
|
return false unless root_account.present?
|
|
|
|
root_account.feature_enabled?(flag) || false # ensure true boolean
|
|
|
|
end
|
|
|
|
|
|
|
|
def service_settings
|
2016-02-27 07:18:56 +08:00
|
|
|
settings = Canvas::DynamicSettings.from_cache("rich-content-service", expires_in: 5.minutes)
|
2016-02-26 04:59:36 +08:00
|
|
|
{
|
|
|
|
RICH_CONTENT_APP_HOST: settings["app-host"],
|
|
|
|
RICH_CONTENT_CDN_HOST: settings["cdn-host"]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def fine_grained_flags(root_account)
|
|
|
|
{
|
|
|
|
RICH_CONTENT_SIDEBAR_ENABLED: check_feature_flag(root_account, :rich_content_service_with_sidebar),
|
|
|
|
RICH_CONTENT_HIGH_RISK_ENABLED: check_feature_flag(root_account, :rich_content_service_high_risk)
|
|
|
|
}
|
|
|
|
end
|
2015-11-06 05:22:30 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|