globus_client 0.4.0 → 0.6.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: 3a9de93796688ebf5d55d620e0cb290ed7e6b86f67ed1212e7847281ea5ac44d
4
- data.tar.gz: b298b6a3744471cb4199e9c9f4ae2c69ece63dd9a3898dc058844d6bad22279c
3
+ metadata.gz: 48a7e0a937ea5e51b5803b69237c2d03afdc95a14a26008b6df31b708b086600
4
+ data.tar.gz: 431c01307b660f6cab3240963e508f57d1d1a8412e75b3468b7c16a48fc220c6
5
5
  SHA512:
6
- metadata.gz: ad0fe7f847270e9534458577dda9a75dad2e83298f0d8232ee8ccd7eca6e127a7290db944ac4dac31cad2df7b42f3e2b7ecc4f273a75059c1c39de2cdf820b09
7
- data.tar.gz: 3488ec985fee144991bbe90c29345a7717cae4e371a843bdb0947a6042128391bf7442e522c03494340acfb1ce31b61dc23ca7a30f05bedc667fc459bcfeaea8
6
+ metadata.gz: ccb73a4b9709b88f4bcf2bfcd59775beeee645c3b79b7c9a1083cb922ea4cb014ed07141579bf92532be103eb79bf23b7a65b727f0343b8f4ecec9f294fdfd05
7
+ data.tar.gz: 4aa6ff81e7ac5109526ca7608c089e2b5a1f8f7ce4e4f9a8c4eabaf14805dc22d4c0380624aef82179dee222ef1e7997fd7a485355e152a13fd81f1f64e20425
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- globus_client (0.4.0)
4
+ globus_client (0.6.0)
5
5
  activesupport (>= 4.2, < 8)
6
6
  faraday
7
7
  zeitwerk
@@ -30,13 +30,13 @@ GEM
30
30
  hashdiff (1.0.1)
31
31
  i18n (1.12.0)
32
32
  concurrent-ruby (~> 1.0)
33
- json (2.6.2)
34
- language_server-protocol (3.17.0.1)
33
+ json (2.6.3)
34
+ language_server-protocol (3.17.0.2)
35
35
  minitest (5.16.3)
36
36
  parallel (1.22.1)
37
37
  parser (3.1.3.0)
38
38
  ast (~> 2.4.1)
39
- public_suffix (5.0.0)
39
+ public_suffix (5.0.1)
40
40
  rainbow (3.1.1)
41
41
  rake (13.0.6)
42
42
  regexp_parser (2.6.1)
@@ -50,7 +50,7 @@ GEM
50
50
  rspec-expectations (3.12.0)
51
51
  diff-lcs (>= 1.2.0, < 2.0)
52
52
  rspec-support (~> 3.12.0)
53
- rspec-mocks (3.12.0)
53
+ rspec-mocks (3.12.1)
54
54
  diff-lcs (>= 1.2.0, < 2.0)
55
55
  rspec-support (~> 3.12.0)
56
56
  rspec-support (3.12.0)
@@ -79,8 +79,8 @@ GEM
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.0)
83
- language_server-protocol (= 3.17.0.1)
82
+ standard (1.19.1)
83
+ language_server-protocol (~> 3.17.0.2)
84
84
  rubocop (= 1.39.0)
85
85
  rubocop-performance (= 1.15.1)
86
86
  tzinfo (2.0.5)
data/README.md CHANGED
@@ -31,9 +31,9 @@ client = GlobusClient.configure(
31
31
  uploads_directory: Settings.globus.uploads_directory,
32
32
  transfer_endpoint_id: Settings.globus.transfer_endpoint_id
33
33
  )
34
- client.mkdir(user_id: 'mjgiarlo', work_id: 1234, work_version: 1)
34
+ client.mkdir(user_id: 'mjgiarlo@stanford.edu', path: 'mjgiarlo/work1234/version1')
35
35
 
36
- result = client.user_exists?('mjgiarlo')
36
+ result = client.user_exists?('mjgiarlo@stanford.edu')
37
37
  ```
38
38
 
39
39
  You can also invoke methods directly on the client class, which is useful in a
@@ -53,7 +53,11 @@ GlobusClient.configure(
53
53
  # app/services/my_globus_service.rb
54
54
  # ...
55
55
  def create_user_directory
56
- GlobusClient.mkdir(user_id: 'mjgiarlo', work_id: 1234, work_version: 1)
56
+ GlobusClient.mkdir(user_id: 'mjgiarlo@stanford.edu', path: 'mjgiarlo/work1234/version1')
57
+ end
58
+
59
+ def lookup_dir_contents
60
+ GlobusClient.get_filenames(user_id: 'mjgiarlo@stanford.edu', path: 'mjgiarlo/work1234/version1')
57
61
  end
58
62
  # ...
59
63
  ```
data/api_test.rb CHANGED
@@ -11,27 +11,30 @@ GlobusClient.configure(
11
11
  transfer_endpoint_id: ENV["GLOBUS_ENDPOINT"]
12
12
  )
13
13
 
14
- user_id, work_id, work_version = *ARGV
14
+ user_id, path = *ARGV
15
15
 
16
16
  # Test public API methods here.
17
- GlobusClient.mkdir(user_id:, work_id:, work_version:)
17
+ GlobusClient.mkdir(user_id:, path:)
18
18
 
19
19
  user_exists = GlobusClient.user_exists?(user_id)
20
20
 
21
21
  # Not part of the public API but this allows us to test access changes
22
- before_permissions = GlobusClient::Endpoint.new(GlobusClient.config, user_id: user_id, work_id: work_id, work_version: work_version).send(:access_rule)["permissions"]
22
+ before_permissions = GlobusClient::Endpoint.new(GlobusClient.config, user_id:, path:).send(:access_rule)["permissions"]
23
23
 
24
- files_count = GlobusClient.file_count(user_id:, work_id:, work_version:)
24
+ files_count = GlobusClient.file_count(user_id:, path:)
25
25
 
26
- total_size = GlobusClient.total_size(user_id:, work_id:, work_version:)
26
+ total_size = GlobusClient.total_size(user_id:, path:)
27
27
 
28
- GlobusClient.disallow_writes(user_id:, work_id:, work_version:)
28
+ GlobusClient.disallow_writes(user_id:, path:)
29
+
30
+ files_list = GlobusClient.get_filenames(user_id:, path:)
29
31
 
30
32
  # Not part of the public API but this allows us to test access changes
31
- after_permissions = GlobusClient::Endpoint.new(GlobusClient.config, user_id: user_id, work_id: work_id, work_version: work_version).send(:access_rule)["permissions"]
33
+ after_permissions = GlobusClient::Endpoint.new(GlobusClient.config, user_id:, path:).send(:access_rule)["permissions"]
32
34
 
33
35
  puts "User #{user_id} exists: #{user_exists}"
34
36
  puts "Initial directory permissions: #{before_permissions}"
35
37
  puts "Number of files in directory: #{files_count}"
36
38
  puts "Total size of files in directory: #{total_size}"
39
+ puts "List of files in directory: #{files_list}"
37
40
  puts "Final directory permissions: #{after_permissions}"
@@ -3,15 +3,15 @@
3
3
  class GlobusClient
4
4
  # The namespace for endpoint API operations
5
5
  class Endpoint
6
+ PATH_SEPARATOR = "/"
7
+
6
8
  # @param config [#token, #uploads_directory, #transfer_endpoint_id, #transfer_url, #auth_url] configuration for the gem
7
- # @param user_id [String] conventionally, we use the SUNet ID, not an email address
8
- # @param work_id [#to_s] the identifier of the work (e.g., an H2 work)
9
- # @param work_version [#to_s] the version of the work (e.g., an H2 version)
10
- def initialize(config, user_id:, work_id:, work_version:)
9
+ # @param path [String] the path to operate on
10
+ # @param user_id [String] a Globus user ID (e.g., a @stanford.edu email address)
11
+ def initialize(config, path:, user_id:)
11
12
  @config = config
12
13
  @user_id = user_id
13
- @work_id = work_id
14
- @work_version = work_version
14
+ @path = path
15
15
  end
16
16
 
17
17
  def file_count
@@ -56,9 +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
+
59
63
  private
60
64
 
61
- attr_reader :config, :user_id, :work_id, :work_version
65
+ attr_reader :config, :path, :user_id
62
66
 
63
67
  def connection
64
68
  # Transfer API connection
@@ -68,17 +72,19 @@ class GlobusClient
68
72
  )
69
73
  end
70
74
 
71
- def user
75
+ def globus_identity_id
72
76
  Identity.new(config).get_identity_id(user_id)
73
77
  end
74
78
 
75
79
  # Builds up a path from a list of path elements. E.g., input would look like:
76
- # ["mjgiarlo", "work123", "version1"]
80
+ # "mjgiarlo/work123/version1"
77
81
  # And this method returns:
78
82
  # ["/uploads/mjgiarlo/", "/uploads/mjgiarlo/work123/", "/uploads/mjgiarlo/work123/version1/"]
79
83
  def paths
80
84
  path_segments.map.with_index do |_segment, index|
81
- File.join(config.uploads_directory, path_segments.slice(..index)).concat("/")
85
+ File
86
+ .join(config.uploads_directory, path_segments.slice(..index))
87
+ .concat(PATH_SEPARATOR)
82
88
  end
83
89
  end
84
90
 
@@ -88,7 +94,7 @@ class GlobusClient
88
94
  end
89
95
 
90
96
  def path_segments
91
- [user_id, "work#{work_id}", "version#{work_version}"]
97
+ path.split(PATH_SEPARATOR)
92
98
  end
93
99
 
94
100
  def objects
@@ -103,6 +109,23 @@ class GlobusClient
103
109
  objects["DATA"].select { |object| object["DATA_TYPE"] == "file" }
104
110
  end
105
111
 
112
+ # @param filepath [String] an absolute path to look up contents e.g. /uploads/example/work123/version1
113
+ # @param filenames [Array<String>] a list of filenames, with absolute filepaths
114
+ def ls_path(filepath, filenames)
115
+ # List files recursively at an endpoint https://docs.globus.org/api/transfer/file_operations/#list_directory_contents
116
+ response = connection.get("#{transfer_path}/ls?path=#{filepath}")
117
+ if response.success?
118
+ data = JSON.parse(response.body)["DATA"]
119
+ data.select { |object| object["type"] == "file" }.map { |file| file["name"] }
120
+ .each { |file| filenames << "#{filepath}#{file}" }
121
+ data.select { |object| object["type"] == "dir" }.map { |dir| dir["name"] }
122
+ .each { |dir| ls_path("#{filepath}#{dir}/", filenames) }
123
+ else
124
+ UnexpectedResponse.call(response)
125
+ end
126
+ filenames
127
+ end
128
+
106
129
  def access_request(permissions:)
107
130
  response = if access_rule_id
108
131
  connection.put("#{access_path}/#{access_rule_id}") do |req|
@@ -117,16 +140,16 @@ class GlobusClient
117
140
  req.body = {
118
141
  DATA_TYPE: "access",
119
142
  principal_type: "identity",
120
- principal: user,
143
+ principal: globus_identity_id,
121
144
  path: full_path,
122
145
  permissions:,
123
- notify_email: "#{user_id}@stanford.edu"
146
+ notify_email: user_id
124
147
  }.to_json
125
148
  req.headers["Content-Type"] = "application/json"
126
149
  end
127
150
  end
128
151
 
129
- return response if response.success?
152
+ return true if response.success?
130
153
 
131
154
  UnexpectedResponse.call(response)
132
155
  end
@@ -7,8 +7,8 @@ class GlobusClient
7
7
  @config = config
8
8
  end
9
9
 
10
- def get_identity_id(sunetid)
11
- @email = "#{sunetid}@stanford.edu"
10
+ def get_identity_id(user_id)
11
+ @email = user_id
12
12
 
13
13
  response = lookup_identity
14
14
  UnexpectedResponse.call(response) unless response.success?
@@ -17,8 +17,8 @@ class GlobusClient
17
17
  extract_id(data)
18
18
  end
19
19
 
20
- def exists?(sunetid)
21
- get_identity_id(sunetid)
20
+ def exists?(user_id)
21
+ get_identity_id(user_id)
22
22
  true
23
23
  rescue
24
24
  false
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class GlobusClient
4
- VERSION = "0.4.0"
4
+ VERSION = "0.6.0"
5
5
  end
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?, to: :instance
35
+ delegate :config, :disallow_writes, :file_count, :mkdir, :total_size, :user_exists?, :get_filenames, to: :instance
36
36
 
37
37
  def default_transfer_url
38
38
  "https://transfer.api.globusonline.org"
@@ -66,6 +66,11 @@ class GlobusClient
66
66
  endpoint.total_size
67
67
  end
68
68
 
69
+ def get_filenames(...)
70
+ endpoint = Endpoint.new(config, ...)
71
+ endpoint.get_filenames
72
+ end
73
+
69
74
  def user_exists?(...)
70
75
  identity = Identity.new(config)
71
76
  identity.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.0
4
+ version: 0.6.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-07 00:00:00.000000000 Z
13
+ date: 2022-12-14 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.7
198
- signing_key:
197
+ rubygems_version: 3.3.3
198
+ signing_key:
199
199
  specification_version: 4
200
200
  summary: Interface for interacting with the Globus API.
201
201
  test_files: []