Class: Uplink::Access
- Inherits:
-
Object
- Object
- Uplink::Access
- Defined in:
- lib/uplink/access.rb
Instance Attribute Summary collapse
-
#access ⇒ Object
readonly
Returns the value of attribute access.
Instance Method Summary collapse
- #edge_register_access(config, options = nil) ⇒ Object
-
#initialize(access_result) ⇒ Access
constructor
A new instance of Access.
- #open_project(auto_close: true) ⇒ Object
- #open_project_with_config(config, auto_close: true) ⇒ Object
- #override_encryption_key(bucket, prefix, encryption_key) ⇒ Object
- #satellite_address ⇒ Object
- #serialize ⇒ Object
- #share(permission, prefixes) ⇒ Object
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
#access ⇒ Object (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, = 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 = nil if && !.empty? = UplinkLib::EdgeRegisterAccessOptions.new [:is_public] = [:is_public] end result = UplinkLib.edge_register_access(register_config, @access, ) 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) = UplinkUtil.build_uplink_config(config) result = UplinkLib.uplink_config_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 |
#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_address ⇒ Object
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 |
#serialize ⇒ Object
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(, prefixes) = UplinkLib::UplinkPermission.new if && !.empty? [:allow_download] = [:allow_download] [:allow_upload] = [:allow_upload] [:allow_list] = [:allow_list] [:allow_delete] = [:allow_delete] [:not_before] = [:not_before].to_i if [:not_before] [:not_after] = [:not_after].to_i if [: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, , mem_prefixes, prefixes_count) ErrorUtil.handle_result_error(result) yield Access.new(result) ensure UplinkLib.uplink_free_access_result(result) if result end |