2020-10-27 00:50:13 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-28 04:06:18 +08:00
|
|
|
#
|
|
|
|
# Copyright (C) 2015 - present Instructure, Inc.
|
|
|
|
#
|
|
|
|
# This file is part of Canvas.
|
|
|
|
#
|
|
|
|
# Canvas is free software: you can redistribute it and/or modify it under
|
|
|
|
# the terms of the GNU Affero General Public License as published by the Free
|
|
|
|
# Software Foundation, version 3 of the License.
|
|
|
|
#
|
|
|
|
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
|
|
# details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License along
|
|
|
|
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2015-11-06 05:22:30 +08:00
|
|
|
module Services
|
|
|
|
class RichContent
|
2019-03-23 02:41:43 +08:00
|
|
|
def self.env_for(user: nil, domain: nil, real_user: nil, context: nil)
|
|
|
|
env_hash = service_settings.dup
|
|
|
|
if user && domain
|
|
|
|
begin
|
|
|
|
env_hash[:JWT] = Canvas::Security::ServicesJwt.for_user(
|
|
|
|
domain,
|
|
|
|
user,
|
|
|
|
context: context,
|
|
|
|
real_user: real_user,
|
|
|
|
workflows: [:rich_content, :ui]
|
|
|
|
)
|
|
|
|
rescue Canvas::Security::InvalidJwtKey => exception
|
|
|
|
Canvas::Errors.capture_exception(:jwt, exception)
|
|
|
|
env_hash[:JWT] = "InvalidJwtKey"
|
2016-03-18 04:04:13 +08:00
|
|
|
end
|
2015-11-06 05:22:30 +08:00
|
|
|
end
|
2019-03-23 02:41:43 +08:00
|
|
|
|
|
|
|
# TODO: Remove once rich content service pull from jwt
|
|
|
|
env_hash[:RICH_CONTENT_CAN_UPLOAD_FILES] = (
|
|
|
|
user &&
|
|
|
|
context &&
|
|
|
|
context.grants_any_right?(user, :manage_files)
|
|
|
|
) || false
|
2015-11-06 05:22:30 +08:00
|
|
|
env_hash
|
|
|
|
end
|
|
|
|
|
2016-02-26 04:59:36 +08:00
|
|
|
class << self
|
|
|
|
private
|
|
|
|
def service_settings
|
2017-09-08 05:11:43 +08:00
|
|
|
settings = Canvas::DynamicSettings.find("rich-content-service", default_ttl: 5.minutes)
|
2016-02-26 04:59:36 +08:00
|
|
|
{
|
2017-05-25 06:24:57 +08:00
|
|
|
RICH_CONTENT_APP_HOST: settings['app-host'],
|
2017-10-20 06:33:19 +08:00
|
|
|
RICH_CONTENT_SKIP_SIDEBAR: settings['skip-sidebar']
|
2016-02-26 04:59:36 +08:00
|
|
|
}
|
2017-01-12 00:13:28 +08:00
|
|
|
rescue Imperium::TimeoutError,
|
|
|
|
Imperium::UnableToConnectError,
|
|
|
|
Canvas::DynamicSettings::ConsulError => e
|
2016-03-03 03:45:33 +08:00
|
|
|
Canvas::Errors.capture_exception(:rce_flag, e)
|
|
|
|
{
|
|
|
|
RICH_CONTENT_APP_HOST: "error",
|
|
|
|
}
|
2016-02-26 04:59:36 +08:00
|
|
|
end
|
2015-11-06 05:22:30 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|