globus_client 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +9 -3
- data/api_test.rb +50 -34
- data/lib/globus_client/endpoint.rb +17 -31
- data/lib/globus_client/version.rb +1 -1
- data/lib/globus_client.rb +12 -4
- 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: d1fb97800b48bd1cd82b00c43cc82ea71e24212a4d1385bb84ffb432aaa61715
|
4
|
+
data.tar.gz: e29d9c2ee049c83d0e3c63fbcee2abedbdb1706f3fc29ad907870acad06e88e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b2fd795460970e2eb1449d1053a6baafa14a584d892ec2fa00c778e0921a5f23e7d6824cf98641a1c9d0a54c8d5644a563bcde93e935a42f21f4e0f0bd5e743
|
7
|
+
data.tar.gz: deb0f58b722e3c12208bbede68147d6d0311e0a3bbc85740dcfa764fdf46b2a57836e6e6391306aade37f93c182b7e3865ae37700485bdb17b5746b2a36a3b21
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -57,7 +57,13 @@ def create_user_directory
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def lookup_dir_contents
|
60
|
-
GlobusClient.
|
60
|
+
GlobusClient.list_files(user_id: "mjgiarlo@stanford.edu", path: "mjgiarlo/work1234/version1") do |files|
|
61
|
+
files_count = files.count
|
62
|
+
total_size = files.sum(&:size)
|
63
|
+
files_list = files.map(&:name)
|
64
|
+
|
65
|
+
return [files_count, total_size, files_list]
|
66
|
+
end
|
61
67
|
end
|
62
68
|
# ...
|
63
69
|
```
|
@@ -78,8 +84,8 @@ $ export GLOBUS_CLIENT_ID=$(vault kv get -field=content puppet/application/sdr/g
|
|
78
84
|
$ export GLOBUS_CLIENT_SECRET=$(vault kv get -field=content puppet/application/sdr/globus/{prod|qa|stage}/client_secret)
|
79
85
|
$ export GLOBUS_ENDPOINT=$(vault kv get -field=content puppet/application/sdr/globus/{prod|qa|stage}/endpoint_uuid)
|
80
86
|
$ export GLOBUS_UPLOADS_DIRECTORY=from_shared_configs
|
81
|
-
# NOTE: The
|
82
|
-
$ ./api_test.rb mjgiarlo
|
87
|
+
# NOTE: The two args below are a user ID (email) and a path such as a consumer might construct
|
88
|
+
$ ./api_test.rb mjgiarlo@stanford.edu mjgiarlo/work987/version1
|
83
89
|
|
84
90
|
Initial directory permissions: rw
|
85
91
|
Number of files in directory: 2
|
data/api_test.rb
CHANGED
@@ -1,40 +1,56 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
require "benchmark"
|
4
5
|
require "bundler/setup"
|
5
6
|
require "globus_client"
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
8
|
+
Benchmark.bm(20) do |benchmark|
|
9
|
+
user_id, path = *ARGV
|
10
|
+
|
11
|
+
benchmark.report("Configure:") do
|
12
|
+
GlobusClient.configure(
|
13
|
+
client_id: ENV["GLOBUS_CLIENT_ID"],
|
14
|
+
client_secret: ENV["GLOBUS_CLIENT_SECRET"],
|
15
|
+
uploads_directory: ENV["GLOBUS_UPLOADS_DIRECTORY"],
|
16
|
+
transfer_endpoint_id: ENV["GLOBUS_ENDPOINT"]
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
benchmark.report("mkdir:") do
|
21
|
+
GlobusClient.mkdir(user_id:, path:)
|
22
|
+
end
|
23
|
+
|
24
|
+
benchmark.report("user_exists?:") do
|
25
|
+
@user_exists = GlobusClient.user_exists?(user_id)
|
26
|
+
end
|
27
|
+
|
28
|
+
benchmark.report("before_perms:") do
|
29
|
+
# Not part of the public API but this allows us to test access changes
|
30
|
+
@before_permissions = GlobusClient::Endpoint.new(GlobusClient.config, user_id:, path:).send(:access_rule)["permissions"]
|
31
|
+
end
|
32
|
+
|
33
|
+
benchmark.report("list_files:") do
|
34
|
+
GlobusClient.list_files(user_id:, path:) do |files|
|
35
|
+
@files_count = files.count
|
36
|
+
@total_size = files.sum(&:size)
|
37
|
+
@files_list = files.map(&:name)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
benchmark.report("disallow_writes:") do
|
42
|
+
GlobusClient.disallow_writes(user_id:, path:)
|
43
|
+
end
|
44
|
+
|
45
|
+
benchmark.report("after_perms:") do
|
46
|
+
# Not part of the public API but this allows us to test access changes
|
47
|
+
@after_permissions = GlobusClient::Endpoint.new(GlobusClient.config, user_id:, path:).send(:access_rule)["permissions"]
|
48
|
+
end
|
49
|
+
|
50
|
+
puts "User #{user_id} exists: #{@user_exists}"
|
51
|
+
puts "Initial directory permissions: #{@before_permissions}"
|
52
|
+
puts "Number of files in directory: #{@files_count}"
|
53
|
+
puts "Total size of files in directory: #{@total_size}"
|
54
|
+
puts "List of files in directory: #{@files_list}"
|
55
|
+
puts "Final directory permissions: #{@after_permissions}"
|
56
|
+
end
|
@@ -5,6 +5,8 @@ class GlobusClient
|
|
5
5
|
class Endpoint
|
6
6
|
PATH_SEPARATOR = "/"
|
7
7
|
|
8
|
+
FileInfo = Struct.new(:name, :size)
|
9
|
+
|
8
10
|
# @param config [#token, #uploads_directory, #transfer_endpoint_id, #transfer_url, #auth_url] configuration for the gem
|
9
11
|
# @param path [String] the path to operate on
|
10
12
|
# @param user_id [String] a Globus user ID (e.g., a @stanford.edu email address)
|
@@ -14,12 +16,10 @@ class GlobusClient
|
|
14
16
|
@path = path
|
15
17
|
end
|
16
18
|
|
17
|
-
def
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
def total_size
|
22
|
-
files.sum { |file| file["size"] }
|
19
|
+
def list_files
|
20
|
+
ls_path(full_path, []).tap do |files|
|
21
|
+
yield files if block_given?
|
22
|
+
end
|
23
23
|
end
|
24
24
|
|
25
25
|
# Create a directory https://docs.globus.org/api/transfer/file_operations/#make_directory
|
@@ -56,17 +56,13 @@ class GlobusClient
|
|
56
56
|
access_request(permissions: "r")
|
57
57
|
end
|
58
58
|
|
59
|
-
def get_filenames
|
60
|
-
ls_path(full_path, [])
|
61
|
-
end
|
62
|
-
|
63
59
|
private
|
64
60
|
|
65
61
|
attr_reader :config, :path, :user_id
|
66
62
|
|
67
63
|
def connection
|
68
64
|
# Transfer API connection
|
69
|
-
Faraday.new(
|
65
|
+
@connection ||= Faraday.new(
|
70
66
|
url: config.transfer_url,
|
71
67
|
headers: {Authorization: "Bearer #{config.token}"}
|
72
68
|
)
|
@@ -81,7 +77,7 @@ class GlobusClient
|
|
81
77
|
# And this method returns:
|
82
78
|
# ["/uploads/mjgiarlo/", "/uploads/mjgiarlo/work123/", "/uploads/mjgiarlo/work123/version1/"]
|
83
79
|
def paths
|
84
|
-
path_segments.map.with_index do |_segment, index|
|
80
|
+
@paths ||= path_segments.map.with_index do |_segment, index|
|
85
81
|
File
|
86
82
|
.join(config.uploads_directory, path_segments.slice(..index))
|
87
83
|
.concat(PATH_SEPARATOR)
|
@@ -97,33 +93,23 @@ class GlobusClient
|
|
97
93
|
path.split(PATH_SEPARATOR)
|
98
94
|
end
|
99
95
|
|
100
|
-
def objects
|
101
|
-
# List files at an endpoint https://docs.globus.org/api/transfer/file_operations/#list_directory_contents
|
102
|
-
response = connection.get("#{transfer_path}/ls?path=#{full_path}")
|
103
|
-
return JSON.parse(response.body) if response.success?
|
104
|
-
|
105
|
-
UnexpectedResponse.call(response)
|
106
|
-
end
|
107
|
-
|
108
|
-
def files
|
109
|
-
objects["DATA"].select { |object| object["DATA_TYPE"] == "file" }
|
110
|
-
end
|
111
|
-
|
112
96
|
# @param filepath [String] an absolute path to look up contents e.g. /uploads/example/work123/version1
|
113
|
-
# @param
|
114
|
-
def ls_path(filepath,
|
97
|
+
# @param files [Array<FileInfo>] an array of FileInfo structs, each of which has a name and a size
|
98
|
+
def ls_path(filepath, files)
|
115
99
|
# List files recursively at an endpoint https://docs.globus.org/api/transfer/file_operations/#list_directory_contents
|
116
100
|
response = connection.get("#{transfer_path}/ls?path=#{filepath}")
|
117
101
|
if response.success?
|
118
102
|
data = JSON.parse(response.body)["DATA"]
|
119
|
-
data
|
120
|
-
.
|
121
|
-
|
122
|
-
|
103
|
+
data
|
104
|
+
.select { |object| object["type"] == "file" }
|
105
|
+
.each { |file| files << FileInfo.new("#{filepath}#{file["name"]}", file["size"]) }
|
106
|
+
data
|
107
|
+
.select { |object| object["type"] == "dir" }
|
108
|
+
.each { |dir| ls_path("#{filepath}#{dir["name"]}/", files) }
|
123
109
|
else
|
124
110
|
UnexpectedResponse.call(response)
|
125
111
|
end
|
126
|
-
|
112
|
+
files
|
127
113
|
end
|
128
114
|
|
129
115
|
def access_request(permissions:)
|
data/lib/globus_client.rb
CHANGED
@@ -32,7 +32,7 @@ class GlobusClient
|
|
32
32
|
self
|
33
33
|
end
|
34
34
|
|
35
|
-
delegate :config, :disallow_writes, :file_count, :mkdir, :total_size, :user_exists?, :get_filenames, to: :instance
|
35
|
+
delegate :config, :disallow_writes, :file_count, :list_files, :mkdir, :total_size, :user_exists?, :get_filenames, to: :instance
|
36
36
|
|
37
37
|
def default_transfer_url
|
38
38
|
"https://transfer.api.globusonline.org"
|
@@ -56,19 +56,27 @@ class GlobusClient
|
|
56
56
|
endpoint.disallow_writes
|
57
57
|
end
|
58
58
|
|
59
|
+
# NOTE: Can't use the `...` (argument forwarding) operator here because we
|
60
|
+
# want to route the keyword args to `Endpoint#new` and the block arg to
|
61
|
+
# `Endpoint#list_files`
|
62
|
+
def list_files(**keywords, &block)
|
63
|
+
endpoint = Endpoint.new(config, **keywords)
|
64
|
+
endpoint.list_files(&block)
|
65
|
+
end
|
66
|
+
|
59
67
|
def file_count(...)
|
60
68
|
endpoint = Endpoint.new(config, ...)
|
61
|
-
endpoint.
|
69
|
+
endpoint.list_files { |files| return files.count }
|
62
70
|
end
|
63
71
|
|
64
72
|
def total_size(...)
|
65
73
|
endpoint = Endpoint.new(config, ...)
|
66
|
-
endpoint.
|
74
|
+
endpoint.list_files { |files| return files.sum(&:size) }
|
67
75
|
end
|
68
76
|
|
69
77
|
def get_filenames(...)
|
70
78
|
endpoint = Endpoint.new(config, ...)
|
71
|
-
endpoint.
|
79
|
+
endpoint.list_files { |files| return files.map(&:name) }
|
72
80
|
end
|
73
81
|
|
74
82
|
def user_exists?(...)
|
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.7.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: 2022-12-
|
13
|
+
date: 2022-12-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -179,7 +179,7 @@ metadata:
|
|
179
179
|
source_code_uri: https://github.com/sul-dlss/globus_client
|
180
180
|
changelog_uri: https://github.com/sul-dlss/globus_client/releases
|
181
181
|
rubygems_mfa_required: 'true'
|
182
|
-
post_install_message:
|
182
|
+
post_install_message:
|
183
183
|
rdoc_options: []
|
184
184
|
require_paths:
|
185
185
|
- lib
|
@@ -194,8 +194,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
194
194
|
- !ruby/object:Gem::Version
|
195
195
|
version: '0'
|
196
196
|
requirements: []
|
197
|
-
rubygems_version: 3.3.
|
198
|
-
signing_key:
|
197
|
+
rubygems_version: 3.3.7
|
198
|
+
signing_key:
|
199
199
|
specification_version: 4
|
200
200
|
summary: Interface for interacting with the Globus API.
|
201
201
|
test_files: []
|