globus_client 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/api_test.rb +5 -0
- data/lib/globus_client/endpoint.rb +29 -12
- data/lib/globus_client/version.rb +1 -1
- data/lib/globus_client.rb +9 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98ab11c317225b75273064fa994c5959d2dd5de9e5276f0c3cc81e264d52140c
|
4
|
+
data.tar.gz: 445c5c522f4e41a735331f3cf3c47a07a6854cc39c308e028bab616759f07703
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 332fdd907867b012edb68cdb145241dcd666f264a8afc806eaf41028af8af3addcd76b16560c79a2db49c69ecce1d9b3cc5cdb4a718e07fe6ede80b117dc7387
|
7
|
+
data.tar.gz: f614098b8258b8598f92fe4fd1e73257e1b413cb8573bb2ccb84235278ebe93f0c249392a5113bc56dae88f3b55b09dc876ed11c20e40fabd0ee4d55b7ec18a4
|
data/Gemfile.lock
CHANGED
data/api_test.rb
CHANGED
@@ -30,6 +30,10 @@ Benchmark.bm(20) do |benchmark|
|
|
30
30
|
@before_permissions = GlobusClient::Endpoint.new(GlobusClient.config, user_id:, path:).send(:access_rule)["permissions"]
|
31
31
|
end
|
32
32
|
|
33
|
+
benchmark.report("has_files?:") do
|
34
|
+
@has_files = GlobusClient.has_files?(user_id:, path:)
|
35
|
+
end
|
36
|
+
|
33
37
|
benchmark.report("list_files:") do
|
34
38
|
GlobusClient.list_files(user_id:, path:) do |files|
|
35
39
|
@files_count = files.count
|
@@ -49,6 +53,7 @@ Benchmark.bm(20) do |benchmark|
|
|
49
53
|
|
50
54
|
puts "User #{user_id} exists: #{@user_exists}"
|
51
55
|
puts "Initial directory permissions: #{@before_permissions}"
|
56
|
+
puts "Directory has files? #{@has_files}"
|
52
57
|
puts "Number of files in directory: #{@files_count}"
|
53
58
|
puts "Total size of files in directory: #{@total_size}"
|
54
59
|
puts "List of files in directory: #{@files_list}"
|
@@ -16,6 +16,10 @@ class GlobusClient
|
|
16
16
|
@path = path
|
17
17
|
end
|
18
18
|
|
19
|
+
def has_files?
|
20
|
+
ls_path(full_path, [], return_presence: true)
|
21
|
+
end
|
22
|
+
|
19
23
|
def list_files
|
20
24
|
ls_path(full_path, []).tap do |files|
|
21
25
|
yield files if block_given?
|
@@ -90,25 +94,38 @@ class GlobusClient
|
|
90
94
|
end
|
91
95
|
|
92
96
|
def path_segments
|
97
|
+
raise ArgumentError, "Unexpected path provided: #{path.inspect}" unless path.respond_to?(:split)
|
98
|
+
|
93
99
|
path.split(PATH_SEPARATOR)
|
94
100
|
end
|
95
101
|
|
102
|
+
# List files recursively at an endpoint https://docs.globus.org/api/transfer/file_operations/#list_directory_contents
|
96
103
|
# @param filepath [String] an absolute path to look up contents e.g. /uploads/example/work123/version1
|
97
104
|
# @param files [Array<FileInfo>] an array of FileInfo structs, each of which has a name and a size
|
98
|
-
|
99
|
-
|
105
|
+
# @param return_presence [Boolean] if true, return a boolean to indicate if any files at all are present, short-circuiting the recursive operation
|
106
|
+
def ls_path(filepath, files, return_presence: false)
|
100
107
|
response = connection.get("#{transfer_path}/ls?path=#{filepath}")
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
108
|
+
return UnexpectedResponse.call(response) unless response.success?
|
109
|
+
|
110
|
+
data = JSON.parse(response.body)["DATA"]
|
111
|
+
data
|
112
|
+
.select { |object| object["type"] == "file" }
|
113
|
+
.each do |file|
|
114
|
+
return true if return_presence
|
115
|
+
|
116
|
+
files << FileInfo.new("#{filepath}#{file["name"]}", file["size"])
|
117
|
+
end
|
118
|
+
data
|
119
|
+
.select { |object| object["type"] == "dir" }
|
120
|
+
.each do |dir|
|
121
|
+
# NOTE: This allows the recursive method to short-circuit iff ls_path
|
122
|
+
# returns true, which only happens when return_presence is true
|
123
|
+
# and the first file is found in the ls operation.
|
124
|
+
return true if ls_path("#{filepath}#{dir["name"]}/", files, return_presence:) == true
|
111
125
|
end
|
126
|
+
|
127
|
+
return false if return_presence
|
128
|
+
|
112
129
|
files
|
113
130
|
end
|
114
131
|
|
data/lib/globus_client.rb
CHANGED
@@ -34,7 +34,8 @@ class GlobusClient
|
|
34
34
|
self
|
35
35
|
end
|
36
36
|
|
37
|
-
delegate :config, :disallow_writes, :file_count, :list_files, :mkdir, :total_size,
|
37
|
+
delegate :config, :disallow_writes, :file_count, :list_files, :mkdir, :total_size,
|
38
|
+
:user_exists?, :get_filenames, :has_files?, to: :instance
|
38
39
|
|
39
40
|
def default_transfer_url
|
40
41
|
"https://transfer.api.globusonline.org"
|
@@ -93,6 +94,13 @@ class GlobusClient
|
|
93
94
|
end
|
94
95
|
end
|
95
96
|
|
97
|
+
def has_files?(...)
|
98
|
+
TokenWrapper.refresh(config) do
|
99
|
+
endpoint = Endpoint.new(config, ...)
|
100
|
+
endpoint.has_files?
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
96
104
|
def user_exists?(...)
|
97
105
|
TokenWrapper.refresh(config) do
|
98
106
|
identity = Identity.new(config)
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: globus_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Collier
|
8
8
|
- Laura Wrubel
|
9
9
|
- Mike Giarlo
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2023-01-
|
13
|
+
date: 2023-01-12 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -180,7 +180,7 @@ metadata:
|
|
180
180
|
source_code_uri: https://github.com/sul-dlss/globus_client
|
181
181
|
changelog_uri: https://github.com/sul-dlss/globus_client/releases
|
182
182
|
rubygems_mfa_required: 'true'
|
183
|
-
post_install_message:
|
183
|
+
post_install_message:
|
184
184
|
rdoc_options: []
|
185
185
|
require_paths:
|
186
186
|
- lib
|
@@ -195,8 +195,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
195
195
|
- !ruby/object:Gem::Version
|
196
196
|
version: '0'
|
197
197
|
requirements: []
|
198
|
-
rubygems_version: 3.3.
|
199
|
-
signing_key:
|
198
|
+
rubygems_version: 3.3.7
|
199
|
+
signing_key:
|
200
200
|
specification_version: 4
|
201
201
|
summary: Interface for interacting with the Globus API.
|
202
202
|
test_files: []
|