From 92a4f9ea88c4d99a3c0e904093c54a7e199eae73 Mon Sep 17 00:00:00 2001 From: Xander Moffatt Date: Thu, 17 Aug 2017 14:54:21 -0600 Subject: [PATCH] add initial inst-fs integration * register instfs plugin * add instfs data to consul closes CNVS-38588 test plan: none Change-Id: Iaabcea702b001be75532b24ced3e8eeee574e424 Reviewed-on: https://gerrit.instructure.com/123199 Reviewed-by: Jacob Fugal Tested-by: Jenkins Product-Review: Xander Moffatt QA-Review: Xander Moffatt --- app/views/plugins/_inst_fs_settings.html.erb | 20 ++++++++++ config/consul.yml.example | 6 +++ lib/canvas/plugins/default_plugins.rb | 9 +++++ lib/inst_fs.rb | 41 ++++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 app/views/plugins/_inst_fs_settings.html.erb create mode 100644 lib/inst_fs.rb diff --git a/app/views/plugins/_inst_fs_settings.html.erb b/app/views/plugins/_inst_fs_settings.html.erb new file mode 100644 index 000000000000..056d495cdb95 --- /dev/null +++ b/app/views/plugins/_inst_fs_settings.html.erb @@ -0,0 +1,20 @@ +<% +# Copyright (C) 2016 - 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 . +%> + +<%= fields_for :settings, OpenObject.new(settings) do |f| %> +<% end %> diff --git a/config/consul.yml.example b/config/consul.yml.example index 465f26b0f285..fb862408e311 100644 --- a/config/consul.yml.example +++ b/config/consul.yml.example @@ -19,6 +19,9 @@ test: address-book: app-host: http://address-book.docker secret: opensesame + inst-fs: + app-host: http://api.instfs.docker + secret: supersecretyup live-events-subscription-service: app-host: http://les.docker sad-panda: null @@ -36,6 +39,9 @@ development: address-book: app-host: http://address-book.docker secret: opensesame + inst-fs: + app-host: http://api.instfs.docker + secret: supersecretyup live-events-subscription-service: app-host: http://les.docker live-events: diff --git a/lib/canvas/plugins/default_plugins.rb b/lib/canvas/plugins/default_plugins.rb index c3f766ac7fcb..cb065d125575 100644 --- a/lib/canvas/plugins/default_plugins.rb +++ b/lib/canvas/plugins/default_plugins.rb @@ -425,4 +425,13 @@ :settings_partial => 'plugins/live_events_settings', :validator => 'LiveEventsValidator' }) +Canvas::Plugin.register('inst_fs', nil, { + :name =>lambda{ t :name, 'Inst-FS' }, + :description => lambda{ t :description, 'File service that proxies for S3.' }, + :author => 'Instructure', + :author_website => 'http://www.instructure.com', + :version => '0.0.1', + :settings => nil, + :settings_partial => 'plugins/inst_fs_settings' +}) require_dependency 'canvas/plugins/address_book' diff --git a/lib/inst_fs.rb b/lib/inst_fs.rb new file mode 100644 index 000000000000..685745ff407f --- /dev/null +++ b/lib/inst_fs.rb @@ -0,0 +1,41 @@ +# +# Copyright (C) 2016 - 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 . + +module InstFS + class << self + def enabled? + Canvas::Plugin.find('inst_fs').enabled? + end + + def app_host + setting("app-host") + end + + def jwt_secret + setting("secret") + end + + private + def setting(key) + settings = Canvas::DynamicSettings.from_cache("inst-fs", expires_in: 5.minutes, use_env: false) + settings[key] + rescue Imperium::TimeoutError => e + Canvas::Errors.capture_exception(:inst_fs, e) + nil + end + end +end \ No newline at end of file