globus_client 0.4.0 → 0.5.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: 23d56c1a01cd643aafec353ff36adf2ad15b4792ebbd3091745415d5fcce68eb
4
+ data.tar.gz: 0d6acdff1f5a627b6a9030bf1e5154c4efef845bab052c27d4d84206ee04c822
5
5
  SHA512:
6
- metadata.gz: ad0fe7f847270e9534458577dda9a75dad2e83298f0d8232ee8ccd7eca6e127a7290db944ac4dac31cad2df7b42f3e2b7ecc4f273a75059c1c39de2cdf820b09
7
- data.tar.gz: 3488ec985fee144991bbe90c29345a7717cae4e371a843bdb0947a6042128391bf7442e522c03494340acfb1ce31b61dc23ca7a30f05bedc667fc459bcfeaea8
6
+ metadata.gz: 6c6ea6b0df9c20fddb7157cd5c7a0dc3270308ce11805f1fbaebb35f704647e7bc4d097ab5a89edc68c1c87274d3adaa52abd6928d9c5d89a214eb99cf7193ac
7
+ data.tar.gz: e25b26ab750b5b176279e26de6887bafc9fc25cce8b406d2aabec931978858580d26f816e9c2c6e92e3b7cca81afaf1cee6aa84490f88c152a65c2d35ee8c3ec
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.5.0)
5
5
  activesupport (>= 4.2, < 8)
6
6
  faraday
7
7
  zeitwerk
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,7 @@ 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
57
  end
58
58
  # ...
59
59
  ```
data/api_test.rb CHANGED
@@ -11,24 +11,24 @@ 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
29
 
30
30
  # 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"]
31
+ after_permissions = GlobusClient::Endpoint.new(GlobusClient.config, user_id:, path:).send(:access_rule)["permissions"]
32
32
 
33
33
  puts "User #{user_id} exists: #{user_exists}"
34
34
  puts "Initial directory permissions: #{before_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
@@ -58,7 +58,7 @@ class GlobusClient
58
58
 
59
59
  private
60
60
 
61
- attr_reader :config, :user_id, :work_id, :work_version
61
+ attr_reader :config, :path, :user_id
62
62
 
63
63
  def connection
64
64
  # Transfer API connection
@@ -68,17 +68,19 @@ class GlobusClient
68
68
  )
69
69
  end
70
70
 
71
- def user
71
+ def globus_identity_id
72
72
  Identity.new(config).get_identity_id(user_id)
73
73
  end
74
74
 
75
75
  # Builds up a path from a list of path elements. E.g., input would look like:
76
- # ["mjgiarlo", "work123", "version1"]
76
+ # "mjgiarlo/work123/version1"
77
77
  # And this method returns:
78
78
  # ["/uploads/mjgiarlo/", "/uploads/mjgiarlo/work123/", "/uploads/mjgiarlo/work123/version1/"]
79
79
  def paths
80
80
  path_segments.map.with_index do |_segment, index|
81
- File.join(config.uploads_directory, path_segments.slice(..index)).concat("/")
81
+ File
82
+ .join(config.uploads_directory, path_segments.slice(..index))
83
+ .concat(PATH_SEPARATOR)
82
84
  end
83
85
  end
84
86
 
@@ -88,7 +90,7 @@ class GlobusClient
88
90
  end
89
91
 
90
92
  def path_segments
91
- [user_id, "work#{work_id}", "version#{work_version}"]
93
+ path.split(PATH_SEPARATOR)
92
94
  end
93
95
 
94
96
  def objects
@@ -117,16 +119,16 @@ class GlobusClient
117
119
  req.body = {
118
120
  DATA_TYPE: "access",
119
121
  principal_type: "identity",
120
- principal: user,
122
+ principal: globus_identity_id,
121
123
  path: full_path,
122
124
  permissions:,
123
- notify_email: "#{user_id}@stanford.edu"
125
+ notify_email: user_id
124
126
  }.to_json
125
127
  req.headers["Content-Type"] = "application/json"
126
128
  end
127
129
  end
128
130
 
129
- return response if response.success?
131
+ return true if response.success?
130
132
 
131
133
  UnexpectedResponse.call(response)
132
134
  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.5.0"
5
5
  end
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.0
4
+ version: 0.5.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: 2022-12-07 00:00:00.000000000 Z
13
+ date: 2022-12-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport