globus_client 0.2.0 → 0.2.1

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: 77e44f70f4c6ee02299ac4718e8ed5d1c2c88d58c71a4ba2c3bfbe970e2bb5df
4
- data.tar.gz: b74fbc9c11f7b9c9fdadac074fe8709711f0065d03ab01fcecb159374446bb9b
3
+ metadata.gz: 5271ee3e081c58ef2e33f088d5c1f1357e6a685b77c9f57169b4feac40b21e72
4
+ data.tar.gz: 1e397fed8f4d17109eadbc3dda819ba1cd5a2a9b23b7429d81be64e06a9dc847
5
5
  SHA512:
6
- metadata.gz: 26d0923724fc1301b344b190d347abd25a1c6e17c57214f424df46d3739fc64ead270e9ae8eb3eddecdfc6700d6c52bc935cda654aef8109a01b45a5d187ca39
7
- data.tar.gz: a5c9e21ec3917f8c560ed34eaefb38af1253cddd582223e1986a78d165301443b689875a20a96f24ef1eb514aca19fbc7994af52c1f441b5db60d9428592cd0b
6
+ metadata.gz: 8bb0215d1af474ce96b479ac54238398cc348a0b8c488a0214ad6d82a5a43ef63727da2bf1319d4a240f4940008ebfbe7a521295ec9ed197e5466d8a5f5245f7
7
+ data.tar.gz: fb40e668a9ecb83aeaeac4098a37ea8b6915ea2315c6a625d7c99bdce0639776c0db78679f096a59579f5d38ecea44585159e0a0c1ab98da3e20756e049488e7
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- globus_client (0.1.0)
4
+ globus_client (0.2.1)
5
5
  activesupport (>= 4.2, < 8)
6
6
  faraday
7
7
  zeitwerk
@@ -106,4 +106,4 @@ DEPENDENCIES
106
106
  webmock
107
107
 
108
108
  BUNDLED WITH
109
- 2.3.19
109
+ 2.3.26
@@ -15,7 +15,7 @@ module Globus
15
15
  @work_version = work_version
16
16
  end
17
17
 
18
- # This is a temporary method to show parsing of data returned.
18
+ # NOTE: This is a temporary method to show parsing of data returned.
19
19
  def length
20
20
  objects["total"]
21
21
  end
@@ -24,13 +24,20 @@ module Globus
24
24
  def mkdir
25
25
  # transfer API does not support recursive directory creation
26
26
  paths.each do |path|
27
- response = call_mkdir(path)
27
+ response = connection.post("#{transfer_path}/mkdir") do |req|
28
+ req.headers["Content-Type"] = "application/json"
29
+ req.body = {
30
+ DATA_TYPE: "mkdir",
31
+ path:
32
+ }.to_json
33
+ end
34
+
28
35
  next if response.success?
29
36
 
30
- # if directory already exists
37
+ # Ignore error if directory already exists
31
38
  if response.status == 502
32
39
  error = JSON.parse(response.body)
33
- next if error["code"] == "ExternalError.MkdirFailedExists"
40
+ next if error["code"] == "ExternalError.MkdirFailed.Exists"
34
41
  end
35
42
 
36
43
  UnexpectedResponse.call(response)
@@ -39,10 +46,27 @@ module Globus
39
46
 
40
47
  # Assign a user read/write permissions for a directory https://docs.globus.org/api/transfer/acl/#rest_access_create
41
48
  def set_permissions
42
- path = "#{config.uploads_directory}/#{user_id}/work#{work_id}/version#{work_version}/"
43
- identity = Globus::Client::Identity.new(config)
44
- id = identity.get_identity_id(user_id)
45
- call_access(path:, id:, user_id:)
49
+ response = connection.post(access_path) do |req|
50
+ req.body = {
51
+ DATA_TYPE: "access",
52
+ principal_type: "identity",
53
+ principal: identity.get_identity_id(user_id),
54
+ path: paths.last,
55
+ permissions: "rw",
56
+ notify_email: "#{user_id}@stanford.edu"
57
+ }.to_json
58
+ req.headers["Content-Type"] = "application/json"
59
+ end
60
+
61
+ return response if response.success?
62
+
63
+ # Ignore error if permissions already set for identity
64
+ if response.status == 409
65
+ error = JSON.parse(response.body)
66
+ return if error["code"] == "Exists"
67
+ end
68
+
69
+ UnexpectedResponse.call(response)
46
70
  end
47
71
 
48
72
  private
@@ -57,6 +81,10 @@ module Globus
57
81
  )
58
82
  end
59
83
 
84
+ def identity
85
+ Globus::Client::Identity.new(config)
86
+ end
87
+
60
88
  # Builds up a path from a list of path elements. E.g., input would look like:
61
89
  # ["mjgiarlo", "work123", "version1"]
62
90
  # And this method returns:
@@ -71,48 +99,20 @@ module Globus
71
99
  [user_id, "work#{work_id}", "version#{work_version}"]
72
100
  end
73
101
 
74
- def endpoint
75
- "/v0.10/operation/endpoint/#{config.transfer_endpoint_id}"
76
- end
102
+ def objects
103
+ # List files at an endpoint https://docs.globus.org/api/transfer/file_operations/#list_directory_contents
104
+ response = connection.get("#{transfer_path}/ls")
105
+ return JSON.parse(response.body) if response.success?
77
106
 
78
- # @return [Faraday::Response]
79
- def call_mkdir(path)
80
- connection.post("#{endpoint}/mkdir") do |req|
81
- req.headers["Content-Type"] = "application/json"
82
- req.body = {
83
- DATA_TYPE: "mkdir",
84
- path:
85
- }.to_json
86
- end
107
+ UnexpectedResponse.call(response)
87
108
  end
88
109
 
89
- # Makes the API call to Globus to set permissions
90
- # @param path [String] the directory on the globus endpoint
91
- # @param id [String] globus identifier associated with the user_id email
92
- # @param user_id [String] user_id, not email address
93
- # @return [Faraday::Response]
94
- def call_access(path:, id:, user_id:)
95
- response = connection.post("#{endpoint}/access") do |req|
96
- req.body = {
97
- DATA_TYPE: "access",
98
- principal_type: "identity",
99
- principal: id,
100
- path:,
101
- permissions: "rw",
102
- notify_email: "#{user_id}@stanford.edu"
103
- }.to_json
104
- req.headers["Content-Type"] = "application/json"
105
- end
106
- UnexpectedResponse.call(response) unless response.success?
107
-
108
- response
110
+ def transfer_path
111
+ "/v0.10/operation/endpoint/#{config.transfer_endpoint_id}"
109
112
  end
110
113
 
111
- def objects
112
- # List files at an endpoint https://docs.globus.org/api/transfer/file_operations/#list_directory_contents
113
- response = connection.get("#{endpoint}/ls")
114
- UnexpectedResponse.call(response) unless response.success?
115
- JSON.parse(response.body)
114
+ def access_path
115
+ "/v0.10/endpoint/#{config.transfer_endpoint_id}/access"
116
116
  end
117
117
  end
118
118
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Globus
4
4
  class Client
5
- VERSION = "0.2.0"
5
+ VERSION = "0.2.1"
6
6
  end
7
7
  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.2.0
4
+ version: 0.2.1
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-11-21 00:00:00.000000000 Z
13
+ date: 2022-11-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport