globus_client 0.14.0 → 0.16.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/.rubocop.yml +3 -2
- data/Gemfile.lock +85 -76
- data/README.md +1 -2
- data/api_test.rb +2 -4
- data/globus_client.gemspec +1 -1
- data/lib/globus_client/authenticator.rb +5 -13
- data/lib/globus_client/endpoint.rb +41 -21
- data/lib/globus_client/endpoint_manager.rb +45 -0
- data/lib/globus_client/identity.rb +2 -10
- data/lib/globus_client/version.rb +1 -1
- data/lib/globus_client.rb +43 -12
- metadata +4 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e2a9f5ea8b86fba80105171529f3c22b751e00703905d0ba3b20d08ea61111c
|
4
|
+
data.tar.gz: 1376671b1dbd3dd2adba6bf2e076097f8c96d13f9773a0a976270dfd4592cf4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bde893f245af7928af36da0676452bd503cfd3c9d847b1d66efb9be18591563ab1d09ef12b8341223968fa1c0534c31a90263689b392f739539a4fadbf1b091c
|
7
|
+
data.tar.gz: b37a773e0005668970a04895e47d4f188cc53d38991283c717eb5d9a52a756218b666538c5ce9da1ee6559b71facaace57ca9eae3d0fc2094e47b373d047ba2f
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
globus_client (0.
|
5
|
-
activesupport (>= 4.2
|
4
|
+
globus_client (0.16.0)
|
5
|
+
activesupport (>= 4.2)
|
6
6
|
faraday
|
7
7
|
faraday-retry
|
8
8
|
zeitwerk
|
@@ -10,110 +10,119 @@ PATH
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
activesupport (
|
13
|
+
activesupport (8.0.2)
|
14
14
|
base64
|
15
|
+
benchmark (>= 0.3)
|
15
16
|
bigdecimal
|
16
|
-
concurrent-ruby (~> 1.0, >= 1.
|
17
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
17
18
|
connection_pool (>= 2.2.5)
|
18
19
|
drb
|
19
20
|
i18n (>= 1.6, < 2)
|
21
|
+
logger (>= 1.4.2)
|
20
22
|
minitest (>= 5.1)
|
21
|
-
|
22
|
-
tzinfo (~> 2.0)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
securerandom (>= 0.3)
|
24
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
25
|
+
uri (>= 0.13.1)
|
26
|
+
addressable (2.8.7)
|
27
|
+
public_suffix (>= 2.0.2, < 7.0)
|
28
|
+
ast (2.4.3)
|
29
|
+
base64 (0.2.0)
|
30
|
+
benchmark (0.4.0)
|
31
|
+
bigdecimal (3.1.9)
|
32
|
+
byebug (12.0.0)
|
33
|
+
concurrent-ruby (1.3.5)
|
34
|
+
connection_pool (2.5.3)
|
35
|
+
crack (1.0.0)
|
36
|
+
bigdecimal
|
32
37
|
rexml
|
33
|
-
diff-lcs (1.
|
34
|
-
docile (1.4.
|
35
|
-
drb (2.
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
faraday-retry (2.
|
38
|
+
diff-lcs (1.6.2)
|
39
|
+
docile (1.4.1)
|
40
|
+
drb (2.2.3)
|
41
|
+
faraday (2.13.1)
|
42
|
+
faraday-net_http (>= 2.0, < 3.5)
|
43
|
+
json
|
44
|
+
logger
|
45
|
+
faraday-net_http (3.4.0)
|
46
|
+
net-http (>= 0.5.0)
|
47
|
+
faraday-retry (2.3.1)
|
43
48
|
faraday (~> 2.0)
|
44
|
-
hashdiff (1.0
|
45
|
-
i18n (1.14.
|
49
|
+
hashdiff (1.2.0)
|
50
|
+
i18n (1.14.7)
|
46
51
|
concurrent-ruby (~> 1.0)
|
47
|
-
json (2.
|
48
|
-
language_server-protocol (3.17.0.
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
52
|
+
json (2.12.2)
|
53
|
+
language_server-protocol (3.17.0.5)
|
54
|
+
lint_roller (1.1.0)
|
55
|
+
logger (1.7.0)
|
56
|
+
minitest (5.25.5)
|
57
|
+
net-http (0.6.0)
|
58
|
+
uri
|
59
|
+
parallel (1.27.0)
|
60
|
+
parser (3.3.8.0)
|
53
61
|
ast (~> 2.4.1)
|
54
62
|
racc
|
55
|
-
|
56
|
-
|
63
|
+
prism (1.4.0)
|
64
|
+
public_suffix (6.0.2)
|
65
|
+
racc (1.8.1)
|
57
66
|
rainbow (3.1.1)
|
58
|
-
rake (13.
|
59
|
-
regexp_parser (2.
|
60
|
-
rexml (3.
|
61
|
-
rspec (3.
|
62
|
-
rspec-core (~> 3.
|
63
|
-
rspec-expectations (~> 3.
|
64
|
-
rspec-mocks (~> 3.
|
65
|
-
rspec-core (3.
|
66
|
-
rspec-support (~> 3.
|
67
|
-
rspec-expectations (3.
|
67
|
+
rake (13.2.1)
|
68
|
+
regexp_parser (2.10.0)
|
69
|
+
rexml (3.4.1)
|
70
|
+
rspec (3.13.0)
|
71
|
+
rspec-core (~> 3.13.0)
|
72
|
+
rspec-expectations (~> 3.13.0)
|
73
|
+
rspec-mocks (~> 3.13.0)
|
74
|
+
rspec-core (3.13.3)
|
75
|
+
rspec-support (~> 3.13.0)
|
76
|
+
rspec-expectations (3.13.4)
|
68
77
|
diff-lcs (>= 1.2.0, < 2.0)
|
69
|
-
rspec-support (~> 3.
|
70
|
-
rspec-mocks (3.
|
78
|
+
rspec-support (~> 3.13.0)
|
79
|
+
rspec-mocks (3.13.4)
|
71
80
|
diff-lcs (>= 1.2.0, < 2.0)
|
72
|
-
rspec-support (~> 3.
|
73
|
-
rspec-support (3.
|
74
|
-
rubocop (1.
|
75
|
-
base64 (~> 0.1.1)
|
81
|
+
rspec-support (~> 3.13.0)
|
82
|
+
rspec-support (3.13.3)
|
83
|
+
rubocop (1.75.7)
|
76
84
|
json (~> 2.3)
|
77
|
-
language_server-protocol (
|
85
|
+
language_server-protocol (~> 3.17.0.2)
|
86
|
+
lint_roller (~> 1.1.0)
|
78
87
|
parallel (~> 1.10)
|
79
|
-
parser (>= 3.
|
88
|
+
parser (>= 3.3.0.2)
|
80
89
|
rainbow (>= 2.2.2, < 4.0)
|
81
|
-
regexp_parser (>=
|
82
|
-
|
83
|
-
rubocop-ast (>= 1.28.1, < 2.0)
|
90
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
91
|
+
rubocop-ast (>= 1.44.0, < 2.0)
|
84
92
|
ruby-progressbar (~> 1.7)
|
85
|
-
unicode-display_width (>= 2.4.0, <
|
86
|
-
rubocop-ast (1.
|
87
|
-
parser (>= 3.
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
rubocop (
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
rubocop (~> 1.33)
|
97
|
-
rubocop-capybara (~> 2.17)
|
98
|
-
rubocop-factory_bot (~> 2.22)
|
93
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
94
|
+
rubocop-ast (1.44.1)
|
95
|
+
parser (>= 3.3.7.2)
|
96
|
+
prism (~> 1.4)
|
97
|
+
rubocop-performance (1.25.0)
|
98
|
+
lint_roller (~> 1.1)
|
99
|
+
rubocop (>= 1.75.0, < 2.0)
|
100
|
+
rubocop-ast (>= 1.38.0, < 2.0)
|
101
|
+
rubocop-rspec (3.6.0)
|
102
|
+
lint_roller (~> 1.1)
|
103
|
+
rubocop (~> 1.72, >= 1.72.1)
|
99
104
|
ruby-progressbar (1.13.0)
|
100
|
-
|
105
|
+
securerandom (0.4.1)
|
101
106
|
simplecov (0.22.0)
|
102
107
|
docile (~> 1.1)
|
103
108
|
simplecov-html (~> 0.11)
|
104
109
|
simplecov_json_formatter (~> 0.1)
|
105
|
-
simplecov-html (0.
|
110
|
+
simplecov-html (0.13.1)
|
106
111
|
simplecov_json_formatter (0.1.4)
|
107
112
|
tzinfo (2.0.6)
|
108
113
|
concurrent-ruby (~> 1.0)
|
109
|
-
unicode-display_width (
|
110
|
-
|
114
|
+
unicode-display_width (3.1.4)
|
115
|
+
unicode-emoji (~> 4.0, >= 4.0.4)
|
116
|
+
unicode-emoji (4.0.4)
|
117
|
+
uri (1.0.3)
|
118
|
+
webmock (3.25.1)
|
111
119
|
addressable (>= 2.8.0)
|
112
120
|
crack (>= 0.3.2)
|
113
121
|
hashdiff (>= 0.4.0, < 2.0.0)
|
114
|
-
zeitwerk (2.
|
122
|
+
zeitwerk (2.7.3)
|
115
123
|
|
116
124
|
PLATFORMS
|
125
|
+
arm64-darwin-23
|
117
126
|
x86_64-darwin-19
|
118
127
|
x86_64-darwin-20
|
119
128
|
x86_64-darwin-21
|
@@ -131,4 +140,4 @@ DEPENDENCIES
|
|
131
140
|
webmock
|
132
141
|
|
133
142
|
BUNDLED WITH
|
134
|
-
2.
|
143
|
+
2.6.9
|
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
[](https://badge.fury.io/rb/globus_client)
|
2
2
|
[](https://circleci.com/gh/sul-dlss/globus_client)
|
3
|
-
[](https://codeclimate.com/github/sul-dlss/globus_client/test_coverage)
|
3
|
+
[](https://codecov.io/github/sul-dlss/globus_client)
|
5
4
|
|
6
5
|
# GlobusClient
|
7
6
|
|
data/api_test.rb
CHANGED
@@ -27,8 +27,7 @@ Benchmark.bm(20) do |benchmark| # rubocop:disable Metrics/BlockLength
|
|
27
27
|
|
28
28
|
benchmark.report('before_perms:') do
|
29
29
|
# Not part of the public API but this allows us to test access changes
|
30
|
-
@before_permissions = GlobusClient::Endpoint.new(
|
31
|
-
path:).send(:access_rule)['permissions']
|
30
|
+
@before_permissions = GlobusClient::Endpoint.new(user_id:, path:).send(:access_rule)['permissions']
|
32
31
|
end
|
33
32
|
|
34
33
|
benchmark.report('has_files?:') do
|
@@ -49,8 +48,7 @@ Benchmark.bm(20) do |benchmark| # rubocop:disable Metrics/BlockLength
|
|
49
48
|
|
50
49
|
benchmark.report('after_perms:') do
|
51
50
|
# Not part of the public API but this allows us to test access changes
|
52
|
-
@after_permissions = GlobusClient::Endpoint.new(
|
53
|
-
path:).send(:access_rule)['permissions']
|
51
|
+
@after_permissions = GlobusClient::Endpoint.new(user_id:, path:).send(:access_rule)['permissions']
|
54
52
|
end
|
55
53
|
|
56
54
|
puts "User #{user_id} exists: #{@user_exists}"
|
data/globus_client.gemspec
CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
32
32
|
spec.require_paths = ['lib']
|
33
33
|
|
34
|
-
spec.add_dependency 'activesupport', '>= 4.2'
|
34
|
+
spec.add_dependency 'activesupport', '>= 4.2'
|
35
35
|
spec.add_dependency 'faraday'
|
36
36
|
spec.add_dependency 'faraday-retry'
|
37
37
|
spec.add_dependency 'zeitwerk'
|
@@ -3,14 +3,8 @@
|
|
3
3
|
class GlobusClient
|
4
4
|
# The namespace for the "login" command
|
5
5
|
class Authenticator
|
6
|
-
def self.token
|
7
|
-
new
|
8
|
-
end
|
9
|
-
|
10
|
-
def initialize(client_id, client_secret, auth_url)
|
11
|
-
@client_id = client_id
|
12
|
-
@client_secret = client_secret
|
13
|
-
@auth_url = auth_url
|
6
|
+
def self.token
|
7
|
+
new.token
|
14
8
|
end
|
15
9
|
|
16
10
|
# Request an access_token
|
@@ -24,16 +18,14 @@ class GlobusClient
|
|
24
18
|
|
25
19
|
private
|
26
20
|
|
27
|
-
attr_reader :client_id, :client_secret, :auth_url
|
28
|
-
|
29
21
|
def connection
|
30
|
-
Faraday.new(url: auth_url)
|
22
|
+
Faraday.new(url: GlobusClient.config.auth_url)
|
31
23
|
end
|
32
24
|
|
33
25
|
def form_data
|
34
26
|
{
|
35
|
-
client_id
|
36
|
-
client_secret
|
27
|
+
client_id: GlobusClient.config.client_id,
|
28
|
+
client_secret: GlobusClient.config.client_secret,
|
37
29
|
encoding: 'form',
|
38
30
|
grant_type: 'client_credentials',
|
39
31
|
scope: 'urn:globus:auth:scope:transfer.api.globus.org:all'
|
@@ -7,12 +7,10 @@ class GlobusClient
|
|
7
7
|
|
8
8
|
FileInfo = Struct.new(:name, :size)
|
9
9
|
|
10
|
-
# @param client [GlobusClient] a configured instance of the GlobusClient
|
11
10
|
# @param path [String] the path to operate on
|
12
11
|
# @param user_id [String] a Globus user ID (e.g., a @stanford.edu email address)
|
13
12
|
# @param notify_email [Boolean] indicates if we should ask Globus to send emails on access change (default: true)
|
14
|
-
def initialize(
|
15
|
-
@client = client
|
13
|
+
def initialize(path:, user_id:, notify_email: true)
|
16
14
|
@user_id = user_id
|
17
15
|
@path = path
|
18
16
|
@notify_email = notify_email
|
@@ -32,8 +30,8 @@ class GlobusClient
|
|
32
30
|
def mkdir
|
33
31
|
# transfer API does not support recursive directory creation
|
34
32
|
paths.each do |path|
|
35
|
-
|
36
|
-
base_url:
|
33
|
+
GlobusClient.instance.post(
|
34
|
+
base_url: GlobusClient.config.transfer_url,
|
37
35
|
path: "#{transfer_path}/mkdir",
|
38
36
|
body: { DATA_TYPE: 'mkdir', path: },
|
39
37
|
expected_response: lambda { |resp|
|
@@ -57,18 +55,40 @@ class GlobusClient
|
|
57
55
|
def delete_access_rule
|
58
56
|
raise(StandardError, "Access rule not found for #{path}") unless access_rule_id
|
59
57
|
|
60
|
-
|
61
|
-
base_url:
|
58
|
+
GlobusClient.instance.delete(
|
59
|
+
base_url: GlobusClient.config.transfer_url,
|
62
60
|
path: "#{access_path}/#{access_rule_id}"
|
63
61
|
)
|
64
62
|
end
|
65
63
|
|
64
|
+
# Renames a directory https://docs.globus.org/api/transfer/file_operations/#rename
|
65
|
+
def rename(new_path:)
|
66
|
+
GlobusClient.instance.post(
|
67
|
+
base_url: GlobusClient.config.transfer_url,
|
68
|
+
path: "#{transfer_path}/rename",
|
69
|
+
body: { DATA_TYPE: 'rename', old_path: path, new_path: }
|
70
|
+
)
|
71
|
+
end
|
72
|
+
|
73
|
+
# @returns true if the file / directory exists at the path
|
74
|
+
# See https://docs.globus.org/api/transfer/file_operations/#stat
|
75
|
+
def exists?
|
76
|
+
GlobusClient.instance.get(
|
77
|
+
base_url: GlobusClient.config.transfer_url,
|
78
|
+
path: "#{transfer_path}/stat",
|
79
|
+
params: { path: }
|
80
|
+
)
|
81
|
+
true
|
82
|
+
rescue GlobusClient::UnexpectedResponse::ResourceNotFound
|
83
|
+
false
|
84
|
+
end
|
85
|
+
|
66
86
|
private
|
67
87
|
|
68
|
-
attr_reader :
|
88
|
+
attr_reader :path, :user_id, :notify_email
|
69
89
|
|
70
90
|
def globus_identity_id
|
71
|
-
Identity.new
|
91
|
+
Identity.new.get_identity_id(user_id)
|
72
92
|
end
|
73
93
|
|
74
94
|
# Builds up a path from a list of path elements. E.g., input would look like:
|
@@ -78,7 +98,7 @@ class GlobusClient
|
|
78
98
|
def paths
|
79
99
|
@paths ||= path_segments.map.with_index do |_segment, index|
|
80
100
|
File
|
81
|
-
.join(
|
101
|
+
.join(GlobusClient.config.uploads_directory, path_segments.slice(..index))
|
82
102
|
.concat(PATH_SEPARATOR)
|
83
103
|
end
|
84
104
|
end
|
@@ -99,8 +119,8 @@ class GlobusClient
|
|
99
119
|
# @param files [Array<FileInfo>] an array of FileInfo structs, each of which has a name and a size
|
100
120
|
# @param return_presence [Boolean] if true, return a boolean to indicate if any files at all are present, short-circuiting the recursive operation
|
101
121
|
def ls_path(filepath, files, return_presence: false)
|
102
|
-
response =
|
103
|
-
base_url:
|
122
|
+
response = GlobusClient.instance.get(
|
123
|
+
base_url: GlobusClient.config.transfer_url,
|
104
124
|
path: "#{transfer_path}/ls",
|
105
125
|
params: { path: filepath }
|
106
126
|
)
|
@@ -139,8 +159,8 @@ class GlobusClient
|
|
139
159
|
permissions:
|
140
160
|
}
|
141
161
|
body[:notify_email] = user_id if notify_email
|
142
|
-
|
143
|
-
base_url:
|
162
|
+
GlobusClient.instance.post(
|
163
|
+
base_url: GlobusClient.config.transfer_url,
|
144
164
|
path: access_path,
|
145
165
|
body:
|
146
166
|
)
|
@@ -150,8 +170,8 @@ class GlobusClient
|
|
150
170
|
def update_access_request(permissions:)
|
151
171
|
raise(StandardError, "Access rule not found for #{path}") unless access_rule_id
|
152
172
|
|
153
|
-
|
154
|
-
base_url:
|
173
|
+
GlobusClient.instance.put(
|
174
|
+
base_url: GlobusClient.config.transfer_url,
|
155
175
|
path: "#{access_path}/#{access_rule_id}",
|
156
176
|
body: {
|
157
177
|
DATA_TYPE: 'access',
|
@@ -161,8 +181,8 @@ class GlobusClient
|
|
161
181
|
end
|
162
182
|
|
163
183
|
def access_rule
|
164
|
-
response =
|
165
|
-
base_url:
|
184
|
+
response = GlobusClient.instance.get(
|
185
|
+
base_url: GlobusClient.config.transfer_url,
|
166
186
|
path: access_list_path,
|
167
187
|
content_type: 'application/json'
|
168
188
|
)
|
@@ -175,15 +195,15 @@ class GlobusClient
|
|
175
195
|
end
|
176
196
|
|
177
197
|
def transfer_path
|
178
|
-
"/v0.10/operation/endpoint/#{
|
198
|
+
"/v0.10/operation/endpoint/#{GlobusClient.config.transfer_endpoint_id}"
|
179
199
|
end
|
180
200
|
|
181
201
|
def access_path
|
182
|
-
"/v0.10/endpoint/#{
|
202
|
+
"/v0.10/endpoint/#{GlobusClient.config.transfer_endpoint_id}/access"
|
183
203
|
end
|
184
204
|
|
185
205
|
def access_list_path
|
186
|
-
"/v0.10/endpoint/#{
|
206
|
+
"/v0.10/endpoint/#{GlobusClient.config.transfer_endpoint_id}/access_list"
|
187
207
|
end
|
188
208
|
end
|
189
209
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class GlobusClient
|
4
|
+
# The namespace for endpoint management API operations
|
5
|
+
class EndpointManager
|
6
|
+
IN_PROGRESS_STATUSES = %w[ACTIVE INACTIVE].freeze
|
7
|
+
|
8
|
+
# List tasks for the configured transfer endpoint
|
9
|
+
# https://docs.globus.org/api/transfer/advanced_collection_management/#get_tasks
|
10
|
+
# Note that this method does not support pagination, as there are unlikely to be many tasks.
|
11
|
+
# Also note that if destination_path is provided, only transfer tasks will be returned.
|
12
|
+
# @param owner_id [String] the Globus user ID (a UUID, not email address)
|
13
|
+
# @param status [Array] the status of the tasks to filter on. Values are ACTIVE, INACTIVE, SUCCEEDED, or FAILED.
|
14
|
+
# @param destination_path [String] the destination path to filter tasks by
|
15
|
+
# @return [Array] list of task documents
|
16
|
+
def task_list(owner_id: nil, status: [], destination_path: nil)
|
17
|
+
tasks = GlobusClient.instance.get(
|
18
|
+
base_url: GlobusClient.config.transfer_url,
|
19
|
+
path: '/v0.10/endpoint_manager/task_list',
|
20
|
+
params: task_list_params(owner_id:, status:)
|
21
|
+
)['DATA']
|
22
|
+
return tasks unless destination_path
|
23
|
+
|
24
|
+
destination_base_path = destination_path.delete_suffix('/') << '/'
|
25
|
+
tasks.select { |task| task['destination_base_path']&.start_with?(destination_base_path) }
|
26
|
+
end
|
27
|
+
|
28
|
+
# @param owner_id [String] the Globus user ID (a UUID, not email address)
|
29
|
+
# @param destination_path [String] the destination path to filter tasks by
|
30
|
+
# @return [boolean] true if there are tasks in progress
|
31
|
+
def tasks_in_progress?(owner_id: nil, destination_path: nil)
|
32
|
+
task_list(owner_id:, destination_path:, status: IN_PROGRESS_STATUSES).present?
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def task_list_params(owner_id:, status:)
|
38
|
+
{
|
39
|
+
filter_endpoint: GlobusClient.config.transfer_endpoint_id,
|
40
|
+
filter_owner_id: owner_id,
|
41
|
+
filter_status: Array(status).join(',').presence
|
42
|
+
}.compact
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -3,15 +3,11 @@
|
|
3
3
|
class GlobusClient
|
4
4
|
# Lookup of a Globus identity ID
|
5
5
|
class Identity
|
6
|
-
def initialize(client)
|
7
|
-
@client = client
|
8
|
-
end
|
9
|
-
|
10
6
|
# @param user_id [String] the username in the form of an email addresss
|
11
7
|
# @return [Hash] id and status of Globus identity
|
12
8
|
def get_identity(user_id)
|
13
|
-
response =
|
14
|
-
base_url:
|
9
|
+
response = GlobusClient.instance.get(
|
10
|
+
base_url: GlobusClient.config.auth_url,
|
15
11
|
path: '/v2/api/identities',
|
16
12
|
params: { usernames: user_id }
|
17
13
|
)
|
@@ -30,9 +26,5 @@ class GlobusClient
|
|
30
26
|
def get_identity_id(user_id)
|
31
27
|
get_identity(user_id)['id']
|
32
28
|
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
attr_reader :client
|
37
29
|
end
|
38
30
|
end
|
data/lib/globus_client.rb
CHANGED
@@ -48,8 +48,9 @@ class GlobusClient # rubocop:disable Metrics/ClassLength
|
|
48
48
|
end
|
49
49
|
# rubocop:enable Metrics/ParameterLists
|
50
50
|
|
51
|
-
delegate :config, :disallow_writes, :delete_access_rule, :file_count, :list_files, :mkdir, :total_size,
|
52
|
-
:user_valid?, :get_filenames, :has_files?, :
|
51
|
+
delegate :config, :disallow_writes, :allow_writes, :delete_access_rule, :file_count, :list_files, :mkdir, :rename, :total_size,
|
52
|
+
:user_valid?, :get_filenames, :has_files?, :exists?, :task_list, :tasks_in_progress?,
|
53
|
+
:delete, :get, :post, :put, to: :instance
|
53
54
|
|
54
55
|
def default_transfer_url
|
55
56
|
'https://transfer.api.globusonline.org'
|
@@ -140,7 +141,7 @@ class GlobusClient # rubocop:disable Metrics/ClassLength
|
|
140
141
|
end
|
141
142
|
|
142
143
|
def mkdir(...)
|
143
|
-
Endpoint.new(
|
144
|
+
Endpoint.new(...).tap do |endpoint|
|
144
145
|
endpoint.mkdir
|
145
146
|
endpoint.allow_writes
|
146
147
|
end
|
@@ -148,55 +149,85 @@ class GlobusClient # rubocop:disable Metrics/ClassLength
|
|
148
149
|
|
149
150
|
def disallow_writes(...)
|
150
151
|
Endpoint
|
151
|
-
.new(
|
152
|
+
.new(...)
|
152
153
|
.disallow_writes
|
153
154
|
end
|
154
155
|
|
156
|
+
def allow_writes(...)
|
157
|
+
Endpoint
|
158
|
+
.new(...)
|
159
|
+
.allow_writes
|
160
|
+
end
|
161
|
+
|
155
162
|
def delete_access_rule(...)
|
156
163
|
Endpoint
|
157
|
-
.new(
|
164
|
+
.new(...)
|
158
165
|
.delete_access_rule
|
159
166
|
end
|
160
167
|
|
168
|
+
def rename(new_path:, **args)
|
169
|
+
Endpoint
|
170
|
+
.new(**args)
|
171
|
+
.rename(new_path:)
|
172
|
+
end
|
173
|
+
|
161
174
|
# NOTE: Can't use the `...` (argument forwarding) operator here because we
|
162
175
|
# want to route the keyword args to `Endpoint#new` and the block arg to
|
163
176
|
# `Endpoint#list_files`
|
164
177
|
def list_files(**keywords, &)
|
165
178
|
Endpoint
|
166
|
-
.new(
|
179
|
+
.new(**keywords)
|
167
180
|
.list_files(&)
|
168
181
|
end
|
169
182
|
|
170
183
|
def file_count(...)
|
171
184
|
Endpoint
|
172
|
-
.new(
|
185
|
+
.new(...)
|
173
186
|
.list_files { |files| return files.count }
|
174
187
|
end
|
175
188
|
|
176
189
|
def total_size(...)
|
177
190
|
Endpoint
|
178
|
-
.new(
|
191
|
+
.new(...)
|
179
192
|
.list_files { |files| return files.sum(&:size) }
|
180
193
|
end
|
181
194
|
|
182
195
|
def get_filenames(...)
|
183
196
|
Endpoint
|
184
|
-
.new(
|
197
|
+
.new(...)
|
185
198
|
.list_files { |files| return files.map(&:name) }
|
186
199
|
end
|
187
200
|
|
188
201
|
def has_files?(...)
|
189
202
|
Endpoint
|
190
|
-
.new(
|
203
|
+
.new(...)
|
191
204
|
.has_files?
|
192
205
|
end
|
193
206
|
|
207
|
+
def exists?(...)
|
208
|
+
Endpoint
|
209
|
+
.new(...)
|
210
|
+
.exists?
|
211
|
+
end
|
212
|
+
|
194
213
|
def user_valid?(...)
|
195
214
|
Identity
|
196
|
-
.new
|
215
|
+
.new
|
197
216
|
.valid?(...)
|
198
217
|
end
|
199
218
|
|
219
|
+
def task_list(...)
|
220
|
+
EndpointManager
|
221
|
+
.new
|
222
|
+
.task_list(...)
|
223
|
+
end
|
224
|
+
|
225
|
+
def tasks_in_progress?(...)
|
226
|
+
EndpointManager
|
227
|
+
.new
|
228
|
+
.tasks_in_progress?(...)
|
229
|
+
end
|
230
|
+
|
200
231
|
private
|
201
232
|
|
202
233
|
Config = Struct.new(:client_id, :auth_url, :client_secret, :transfer_endpoint_id, :transfer_url, :uploads_directory, :token, keyword_init: true)
|
@@ -230,7 +261,7 @@ class GlobusClient # rubocop:disable Metrics/ClassLength
|
|
230
261
|
|
231
262
|
# if unauthorized, token has likely expired. try to get a new token and then retry the same request(s).
|
232
263
|
if response.status == 401
|
233
|
-
config.token = Authenticator.token
|
264
|
+
config.token = Authenticator.token
|
234
265
|
response = yield
|
235
266
|
end
|
236
267
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: globus_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Collier
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2025-05-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -19,9 +19,6 @@ dependencies:
|
|
19
19
|
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '4.2'
|
22
|
-
- - "<"
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version: '8'
|
25
22
|
type: :runtime
|
26
23
|
prerelease: false
|
27
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,9 +26,6 @@ dependencies:
|
|
29
26
|
- - ">="
|
30
27
|
- !ruby/object:Gem::Version
|
31
28
|
version: '4.2'
|
32
|
-
- - "<"
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: '8'
|
35
29
|
- !ruby/object:Gem::Dependency
|
36
30
|
name: faraday
|
37
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -96,6 +90,7 @@ files:
|
|
96
90
|
- lib/globus_client.rb
|
97
91
|
- lib/globus_client/authenticator.rb
|
98
92
|
- lib/globus_client/endpoint.rb
|
93
|
+
- lib/globus_client/endpoint_manager.rb
|
99
94
|
- lib/globus_client/identity.rb
|
100
95
|
- lib/globus_client/unexpected_response.rb
|
101
96
|
- lib/globus_client/version.rb
|
@@ -121,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
116
|
- !ruby/object:Gem::Version
|
122
117
|
version: '0'
|
123
118
|
requirements: []
|
124
|
-
rubygems_version: 3.
|
119
|
+
rubygems_version: 3.5.11
|
125
120
|
signing_key:
|
126
121
|
specification_version: 4
|
127
122
|
summary: Interface for interacting with the Globus API.
|