globus_client 0.7.0 → 0.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d1fb97800b48bd1cd82b00c43cc82ea71e24212a4d1385bb84ffb432aaa61715
4
- data.tar.gz: e29d9c2ee049c83d0e3c63fbcee2abedbdb1706f3fc29ad907870acad06e88e9
3
+ metadata.gz: 40f9903f67d10be16104fe3664bf68dd467b24414cb7f0c84bfb6539cd2acee5
4
+ data.tar.gz: bbcc3c1f811df83d8a4d473ff3cd646b33d6f7f950aaa99c0f86e0e10165130d
5
5
  SHA512:
6
- metadata.gz: 1b2fd795460970e2eb1449d1053a6baafa14a584d892ec2fa00c778e0921a5f23e7d6824cf98641a1c9d0a54c8d5644a563bcde93e935a42f21f4e0f0bd5e743
7
- data.tar.gz: deb0f58b722e3c12208bbede68147d6d0311e0a3bbc85740dcfa764fdf46b2a57836e6e6391306aade37f93c182b7e3865ae37700485bdb17b5746b2a36a3b21
6
+ metadata.gz: f5334d262c97ac5512d5a6bbaf9a0927e98fea577a318ba0b08c3dbac33bfbb53c01bdb95205df271886c36df2ce7144c078e7ae8deadc5bea8af9a8d9180479
7
+ data.tar.gz: a850d0854a936f24653d0ebf0bfd96be478ab2a0c6be908c1cd47defb3872b306281a35d56b76cff898cc48ba9340d20dde4d4a96051d36007d6c29d3f5a4a53
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- globus_client (0.7.0)
4
+ globus_client (0.8.0)
5
5
  activesupport (>= 4.2, < 8)
6
6
  faraday
7
7
  zeitwerk
@@ -23,7 +23,7 @@ GEM
23
23
  rexml
24
24
  diff-lcs (1.5.0)
25
25
  docile (1.4.0)
26
- faraday (2.7.1)
26
+ faraday (2.7.2)
27
27
  faraday-net_http (>= 2.0, < 3.1)
28
28
  ruby2_keywords (>= 0.0.4)
29
29
  faraday-net_http (3.0.2)
@@ -32,9 +32,9 @@ GEM
32
32
  concurrent-ruby (~> 1.0)
33
33
  json (2.6.3)
34
34
  language_server-protocol (3.17.0.2)
35
- minitest (5.16.3)
35
+ minitest (5.17.0)
36
36
  parallel (1.22.1)
37
- parser (3.1.3.0)
37
+ parser (3.2.0.0)
38
38
  ast (~> 2.4.1)
39
39
  public_suffix (5.0.1)
40
40
  rainbow (3.1.1)
@@ -47,45 +47,45 @@ GEM
47
47
  rspec-mocks (~> 3.12.0)
48
48
  rspec-core (3.12.0)
49
49
  rspec-support (~> 3.12.0)
50
- rspec-expectations (3.12.0)
50
+ rspec-expectations (3.12.2)
51
51
  diff-lcs (>= 1.2.0, < 2.0)
52
52
  rspec-support (~> 3.12.0)
53
- rspec-mocks (3.12.1)
53
+ rspec-mocks (3.12.2)
54
54
  diff-lcs (>= 1.2.0, < 2.0)
55
55
  rspec-support (~> 3.12.0)
56
56
  rspec-support (3.12.0)
57
- rubocop (1.39.0)
57
+ rubocop (1.42.0)
58
58
  json (~> 2.3)
59
59
  parallel (~> 1.10)
60
60
  parser (>= 3.1.2.1)
61
61
  rainbow (>= 2.2.2, < 4.0)
62
62
  regexp_parser (>= 1.8, < 3.0)
63
63
  rexml (>= 3.2.5, < 4.0)
64
- rubocop-ast (>= 1.23.0, < 2.0)
64
+ rubocop-ast (>= 1.24.1, < 2.0)
65
65
  ruby-progressbar (~> 1.7)
66
66
  unicode-display_width (>= 1.4.0, < 3.0)
67
- rubocop-ast (1.24.0)
67
+ rubocop-ast (1.24.1)
68
68
  parser (>= 3.1.1.0)
69
- rubocop-performance (1.15.1)
69
+ rubocop-performance (1.15.2)
70
70
  rubocop (>= 1.7.0, < 2.0)
71
71
  rubocop-ast (>= 0.4.0)
72
- rubocop-rspec (2.15.0)
72
+ rubocop-rspec (2.16.0)
73
73
  rubocop (~> 1.33)
74
74
  ruby-progressbar (1.11.0)
75
75
  ruby2_keywords (0.0.5)
76
- simplecov (0.21.2)
76
+ simplecov (0.22.0)
77
77
  docile (~> 1.1)
78
78
  simplecov-html (~> 0.11)
79
79
  simplecov_json_formatter (~> 0.1)
80
80
  simplecov-html (0.12.3)
81
81
  simplecov_json_formatter (0.1.4)
82
- standard (1.19.1)
82
+ standard (1.21.1)
83
83
  language_server-protocol (~> 3.17.0.2)
84
- rubocop (= 1.39.0)
85
- rubocop-performance (= 1.15.1)
84
+ rubocop (= 1.42.0)
85
+ rubocop-performance (= 1.15.2)
86
86
  tzinfo (2.0.5)
87
87
  concurrent-ruby (~> 1.0)
88
- unicode-display_width (2.3.0)
88
+ unicode-display_width (2.4.2)
89
89
  webmock (3.18.1)
90
90
  addressable (>= 2.8.0)
91
91
  crack (>= 0.3.2)
@@ -20,7 +20,8 @@ class GlobusClient
20
20
  def exists?(user_id)
21
21
  get_identity_id(user_id)
22
22
  true
23
- rescue
23
+ # if no active user is returned
24
+ rescue RuntimeError
24
25
  false
25
26
  end
26
27
 
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class GlobusClient
4
+ # Wraps API operations to request new access token if expired
5
+ class TokenWrapper
6
+ def self.refresh(config, &block)
7
+ yield
8
+ rescue UnexpectedResponse::UnauthorizedError
9
+ config.token = Authenticator.token(config.client_id, config.client_secret, config.auth_url)
10
+ yield
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class GlobusClient
4
- VERSION = "0.7.0"
4
+ VERSION = "0.8.0"
5
5
  end
data/lib/globus_client.rb CHANGED
@@ -23,6 +23,8 @@ class GlobusClient
23
23
  def configure(client_id:, client_secret:, uploads_directory:, transfer_endpoint_id:, transfer_url: default_transfer_url, auth_url: default_auth_url)
24
24
  instance.config = OpenStruct.new(
25
25
  token: Authenticator.token(client_id, client_secret, auth_url),
26
+ client_id:,
27
+ client_secret:,
26
28
  uploads_directory:,
27
29
  transfer_endpoint_id:,
28
30
  transfer_url:,
@@ -46,41 +48,55 @@ class GlobusClient
46
48
  attr_accessor :config
47
49
 
48
50
  def mkdir(...)
49
- endpoint = Endpoint.new(config, ...)
50
- endpoint.mkdir
51
- endpoint.allow_writes
51
+ TokenWrapper.refresh(config) do
52
+ endpoint = Endpoint.new(config, ...)
53
+ endpoint.mkdir
54
+ endpoint.allow_writes
55
+ end
52
56
  end
53
57
 
54
58
  def disallow_writes(...)
55
- endpoint = Endpoint.new(config, ...)
56
- endpoint.disallow_writes
59
+ TokenWrapper.refresh(config) do
60
+ endpoint = Endpoint.new(config, ...)
61
+ endpoint.disallow_writes
62
+ end
57
63
  end
58
64
 
59
65
  # NOTE: Can't use the `...` (argument forwarding) operator here because we
60
66
  # want to route the keyword args to `Endpoint#new` and the block arg to
61
67
  # `Endpoint#list_files`
62
68
  def list_files(**keywords, &block)
63
- endpoint = Endpoint.new(config, **keywords)
64
- endpoint.list_files(&block)
69
+ TokenWrapper.refresh(config) do
70
+ endpoint = Endpoint.new(config, **keywords)
71
+ endpoint.list_files(&block)
72
+ end
65
73
  end
66
74
 
67
75
  def file_count(...)
68
- endpoint = Endpoint.new(config, ...)
69
- endpoint.list_files { |files| return files.count }
76
+ TokenWrapper.refresh(config) do
77
+ endpoint = Endpoint.new(config, ...)
78
+ endpoint.list_files { |files| return files.count }
79
+ end
70
80
  end
71
81
 
72
82
  def total_size(...)
73
- endpoint = Endpoint.new(config, ...)
74
- endpoint.list_files { |files| return files.sum(&:size) }
83
+ TokenWrapper.refresh(config) do
84
+ endpoint = Endpoint.new(config, ...)
85
+ endpoint.list_files { |files| return files.sum(&:size) }
86
+ end
75
87
  end
76
88
 
77
89
  def get_filenames(...)
78
- endpoint = Endpoint.new(config, ...)
79
- endpoint.list_files { |files| return files.map(&:name) }
90
+ TokenWrapper.refresh(config) do
91
+ endpoint = Endpoint.new(config, ...)
92
+ endpoint.list_files { |files| return files.map(&:name) }
93
+ end
80
94
  end
81
95
 
82
96
  def user_exists?(...)
83
- identity = Identity.new(config)
84
- identity.exists?(...)
97
+ TokenWrapper.refresh(config) do
98
+ identity = Identity.new(config)
99
+ identity.exists?(...)
100
+ end
85
101
  end
86
102
  end
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.7.0
4
+ version: 0.8.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-16 00:00:00.000000000 Z
13
+ date: 2023-01-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -170,6 +170,7 @@ files:
170
170
  - lib/globus_client/authenticator.rb
171
171
  - lib/globus_client/endpoint.rb
172
172
  - lib/globus_client/identity.rb
173
+ - lib/globus_client/token_wrapper.rb
173
174
  - lib/globus_client/unexpected_response.rb
174
175
  - lib/globus_client/version.rb
175
176
  homepage: https://github.com/sul-dlss/globus_client
@@ -179,7 +180,7 @@ metadata:
179
180
  source_code_uri: https://github.com/sul-dlss/globus_client
180
181
  changelog_uri: https://github.com/sul-dlss/globus_client/releases
181
182
  rubygems_mfa_required: 'true'
182
- post_install_message:
183
+ post_install_message:
183
184
  rdoc_options: []
184
185
  require_paths:
185
186
  - lib
@@ -194,8 +195,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
195
  - !ruby/object:Gem::Version
195
196
  version: '0'
196
197
  requirements: []
197
- rubygems_version: 3.3.7
198
- signing_key:
198
+ rubygems_version: 3.3.3
199
+ signing_key:
199
200
  specification_version: 4
200
201
  summary: Interface for interacting with the Globus API.
201
202
  test_files: []