Skip to content

Commit

Permalink
Add method for listing Rclone remotes (#2264)
Browse files Browse the repository at this point in the history
  • Loading branch information
robinkar authored Sep 8, 2022
1 parent 1b38c8e commit 2954166
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions apps/dashboard/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ en:
files_remote_disabled: "Remote file support is not enabled"
files_remote_empty_dir_unsupported: "Remote does not support empty directories"
files_remote_dir_not_created: "Did not create directory %{path}"
files_remote_error_listing_remotes: "Error listing Rclone remotes: %{error}"

jobs_project_created: "Project successfully created!"
jobs_project_deleted: "Project successfully deleted!"
Expand Down
11 changes: 11 additions & 0 deletions apps/dashboard/lib/rclone_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,17 @@ def remote_type(remote)
end
end

# Lists remotes configured in default rclone.conf or environment variables
# @return [Array<String>] Rclone remotes
def list_remotes
o, e, s = rclone("listremotes")
if s.success?
o.lines.map { |l| l.strip.delete_suffix(":") }
else
raise RcloneError.new(s.exitstatus), I18n.t("dashboard.files_remote_error_listing_remotes", error: e)
end
end

def rclone_cmd
# TODO: Make this configurable
"rclone"
Expand Down
7 changes: 7 additions & 0 deletions apps/dashboard/test/fixtures/config/rclone/rclone.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[s3]
type = s3
provider = Other
env_auth = false
access_key_id =
secret_access_key =
acl = private
3 changes: 2 additions & 1 deletion apps/dashboard/test/rclone_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ def remote_files_conf(root_dir)
OOD_FILES_APP_REMOTE_FILES: 'true',
RCLONE_CONFIG_LOCAL_REMOTE_TYPE: 'local',
RCLONE_CONFIG_ALIAS_REMOTE_TYPE: 'alias',
RCLONE_CONFIG_ALIAS_REMOTE_REMOTE: "local_remote:#{root_dir}"
RCLONE_CONFIG_ALIAS_REMOTE_REMOTE: "local_remote:#{root_dir}",
RCLONE_CONFIG: Rails.root.join('test/fixtures/config/rclone/rclone.conf').to_s
}
end

Expand Down
17 changes: 17 additions & 0 deletions apps/dashboard/test/unit/rclone_util_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'test_helper'
require 'rclone_helper'
require 'rclone_util'

class RcloneUtilTest < ActiveSupport::TestCase
test "list_remotes handles rclone.conf and env" do
with_rclone_conf("/") do
assert_equal ["alias_remote", "local_remote", "s3"], RcloneUtil.list_remotes
end
end

test "list_remotes handles missing rclone conf" do
with_modified_env(RCLONE_CONFIG: "/dev/null") do
assert_equal [], RcloneUtil.list_remotes
end
end
end

0 comments on commit 2954166

Please sign in to comment.