Class: GlobusClient::Endpoint

Inherits:
Object
  • Object
show all
Defined in:
lib/globus_client/endpoint.rb

Overview

The namespace for endpoint API operations

Defined Under Namespace

Classes: FileInfo

Constant Summary collapse

PATH_SEPARATOR =

rubocop:disable Metrics/ClassLength

'/'

Instance Method Summary collapse

Constructor Details

#initialize(client, path:, user_id:, notify_email: true) ⇒ Endpoint

Returns a new instance of Endpoint.

Parameters:

  • client (GlobusClient)

    a configured instance of the GlobusClient

  • path (String)

    the path to operate on

  • user_id (String)

    a Globus user ID (e.g., a @stanford.edu email address)

  • notify_email (Boolean) (defaults to: true)

    indicates if we should ask Globus to send emails on access change (default: true)



14
15
16
17
18
19
# File 'lib/globus_client/endpoint.rb', line 14

def initialize(client, path:, user_id:, notify_email: true)
  @client = client
  @user_id = user_id
  @path = path
  @notify_email = notify_email
end

Instance Method Details

#allow_writesObject

Assign a user read/write permissions for a directory docs.globus.org/api/transfer/acl/#rest_access_create



47
48
49
# File 'lib/globus_client/endpoint.rb', line 47

def allow_writes
  access_request(permissions: 'rw')
end

#delete_access_ruleObject

Raises:

  • (StandardError)


57
58
59
60
61
62
63
64
# File 'lib/globus_client/endpoint.rb', line 57

def delete_access_rule
  raise(StandardError, "Access rule not found for #{path}") unless access_rule_id

  client.delete(
    base_url: client.config.transfer_url,
    path: "#{access_path}/#{access_rule_id}"
  )
end

#disallow_writesObject

Assign a user read-only permissions for a directory docs.globus.org/api/transfer/acl/#rest_access_create



52
53
54
# File 'lib/globus_client/endpoint.rb', line 52

def disallow_writes
  update_access_request(permissions: 'r')
end

#has_files?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/globus_client/endpoint.rb', line 21

def has_files?
  ls_path(full_path, [], return_presence: true)
end

#list_filesObject



25
26
27
28
29
# File 'lib/globus_client/endpoint.rb', line 25

def list_files
  ls_path(full_path, []).tap do |files|
    yield files if block_given?
  end
end

#mkdirObject



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/globus_client/endpoint.rb', line 32

def mkdir
  # transfer API does not support recursive directory creation
  paths.each do |path|
    client.post(
      base_url: client.config.transfer_url,
      path: "#{transfer_path}/mkdir",
      body: { DATA_TYPE: 'mkdir', path: },
      expected_response: lambda { |resp|
                           resp.status == 502 && JSON.parse(resp.body)['code'] == 'ExternalError.MkdirFailed.Exists'
                         }
    )
  end
end