Class: Uplink::Access

Inherits:
Object
  • Object
show all
Defined in:
lib/uplink/access.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_result) ⇒ Access

Returns a new instance of Access.



7
8
9
# File 'lib/uplink/access.rb', line 7

def initialize(access_result)
  @access = access_result[:access]
end

Instance Attribute Details

#accessObject (readonly)

Returns the value of attribute access.



5
6
7
# File 'lib/uplink/access.rb', line 5

def access
  @access
end

Instance Method Details

#edge_register_access(config, options = nil) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/uplink/access.rb', line 97

def edge_register_access(config, options = nil)
  register_config = UplinkLib::EdgeConfig.new

  auth_service_address = FFI::MemoryPointer.from_string(config[:auth_service_address]) if config[:auth_service_address]
  certificate_pem = FFI::MemoryPointer.from_string(config[:certificate_pem]) if config[:certificate_pem]
  register_config[:auth_service_address] = auth_service_address
  register_config[:certificate_pem] = certificate_pem

  register_options = nil
  if options && !options.empty?
    register_options = UplinkLib::EdgeRegisterAccessOptions.new
    register_options[:is_public] = options[:is_public]
  end

  result = UplinkLib.edge_register_access(register_config, @access, register_options)
  ErrorUtil.handle_result_error(result)

  EdgeCredential.new(result)
ensure
  UplinkLib.edge_free_credentials_result(result) if result
end

#open_project(auto_close: true) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/uplink/access.rb', line 11

def open_project(auto_close: true)
  result = UplinkLib.uplink_open_project(@access)
  ErrorUtil.handle_result_error(result)

  project = Project.new(result)

  yield project
ensure
  project.close if auto_close && project
  UplinkLib.uplink_free_project_result(result) if result
end

#open_project_with_config(config, auto_close: true) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/uplink/access.rb', line 23

def open_project_with_config(config, auto_close: true)
  config_options = UplinkUtil.build_uplink_config(config)

  result = UplinkLib.uplink_config_open_project(config_options, @access)
  ErrorUtil.handle_result_error(result)

  project = Project.new(result)

  yield project
ensure
  project.close if auto_close && project
  UplinkLib.uplink_free_project_result(result) if result
end

#override_encryption_key(bucket, prefix, encryption_key) ⇒ Object



90
91
92
93
94
95
# File 'lib/uplink/access.rb', line 90

def override_encryption_key(bucket, prefix, encryption_key)
  error = UplinkLib.uplink_access_override_encryption_key(@access, bucket, prefix, encryption_key)
  ErrorUtil.handle_error(error)
ensure
  UplinkLib.uplink_free_error(error) if error
end

#satellite_addressObject



37
38
39
40
41
42
43
44
# File 'lib/uplink/access.rb', line 37

def satellite_address
  result = UplinkLib.uplink_access_satellite_address(@access)
  ErrorUtil.handle_result_error(result)

  result[:string]
ensure
  UplinkLib.uplink_free_string_result(result) if result
end

#serializeObject



46
47
48
49
50
51
52
53
# File 'lib/uplink/access.rb', line 46

def serialize
  result = UplinkLib.uplink_access_serialize(@access)
  ErrorUtil.handle_result_error(result)

  result[:string]
ensure
  UplinkLib.uplink_free_string_result(result) if result
end

#share(permission, prefixes) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/uplink/access.rb', line 55

def share(permission, prefixes)
  permission_options = UplinkLib::UplinkPermission.new
  if permission && !permission.empty?
    permission_options[:allow_download] = permission[:allow_download]
    permission_options[:allow_upload] = permission[:allow_upload]
    permission_options[:allow_list] = permission[:allow_list]
    permission_options[:allow_delete] = permission[:allow_delete]
    permission_options[:not_before] = permission[:not_before].to_i if permission[:not_before]
    permission_options[:not_after] = permission[:not_after].to_i if permission[:not_after]
  end

  prefixes_count = prefixes&.size || 0
  mem_prefixes = nil

  if prefixes_count.positive?
    mem_prefixes = FFI::MemoryPointer.new(UplinkLib::UplinkSharePrefix, prefixes_count)

    prefixes.each_with_index do |prefix, i|
      bucket = FFI::MemoryPointer.from_string(prefix[:bucket]) if prefix[:bucket]
      prefix_val = FFI::MemoryPointer.from_string(prefix[:prefix]) if prefix[:prefix]

      prefix_entry = UplinkLib::UplinkSharePrefix.new(mem_prefixes + (i * UplinkLib::UplinkSharePrefix.size))
      prefix_entry[:bucket] = bucket
      prefix_entry[:prefix] = prefix_val
    end
  end

  result = UplinkLib.uplink_access_share(@access, permission_options, mem_prefixes, prefixes_count)
  ErrorUtil.handle_result_error(result)

  yield Access.new(result)
ensure
  UplinkLib.uplink_free_access_result(result) if result
end