tanker-core 2.30.0 → 2.31.0.beta.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: 3f4f72b76b69cec6b590fb140b06e8d7ae2a1a80bf5460683ea4adb4fcba8ea6
4
- data.tar.gz: d2e0dda686b6d71ae27714c7a1dd904f65e2a78c76622511e52033fc278fd213
3
+ metadata.gz: 3e052ab81cc7efc4ff4c223486bf8c92500d14120c16362eee5745bb0d990a58
4
+ data.tar.gz: b9bc2facb9a7f2290cbe4e579c0b900a7b9ad95f853979fc62813f2975d4648f
5
5
  SHA512:
6
- metadata.gz: 26082b813a8874586abd5e149dc2f60db53b96b3ddaf5d426b21865d6457e23155fa35ea757723127678e3075dddc27dbd883829153e34f8b25ccaf5c6760c43
7
- data.tar.gz: 585fff8b0fa829e199747f3bbfe4b9110d5c2171fda2029d628f3ee306789d4991d28c3309912a778851cc614d961345f3d31082d95a8b09b36e76b1dde2b7d3
6
+ metadata.gz: 5a561e723d259795bec3a01cc1d05efcaee57f42357e1fbd9dfdf8e5301156d214a1e1fa46413e383e503c373d10bb525f33abad80f9327ed54b1d1ba949d14b
7
+ data.tar.gz: 02c800022efc4505a95393bcc2e1c43a988df20a7966ba34834a948b68c6c50e41e99edbc5432141c36b2fdfac8c3e15d3874eeb967b67672c0653a222d16d67
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'ffi'
4
- require 'tanker/core/verification'
5
- require 'tanker/c_tanker/c_string'
6
4
 
7
5
  module Tanker
8
6
  module CTanker
@@ -15,11 +13,5 @@ module Tanker
15
13
  :put_cache_values, :pointer,
16
14
  :find_cache_values, :pointer
17
15
  end
18
-
19
- class CHttpOptions < FFI::Struct
20
- layout :send_request, :pointer,
21
- :cancel_request, :pointer,
22
- :data, :pointer
23
- end
24
16
  end
25
17
  end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ffi'
4
+
5
+ module Tanker
6
+ module CTanker
7
+ extend FFI::Library
8
+
9
+ class CHttpRequest < FFI::Struct
10
+ layout :method, :string,
11
+ :url, :string,
12
+ :instance_id, :string,
13
+ :authorization, :string,
14
+ :body, :pointer,
15
+ :body_size, :int32
16
+ end
17
+
18
+ class CHttpResponse < FFI::Struct
19
+ def self.new_ok(status_code:, content_type:, body:)
20
+ new nil, status_code, content_type, body
21
+ end
22
+
23
+ def self.new_error(msg)
24
+ new msg, nil, nil, nil
25
+ end
26
+
27
+ def initialize(error_msg, status_code, content_type, body)
28
+ super()
29
+
30
+ if error_msg
31
+ @error_msg = CTanker.new_cstring(error_msg)
32
+ self[:error_msg] = @error_msg
33
+ else
34
+ @content_type = CTanker.new_cstring content_type
35
+ @body = FFI::MemoryPointer.from_string(body)
36
+
37
+ self[:error_msg] = nil
38
+ self[:content_type] = @content_type
39
+ self[:body] = @body
40
+ self[:body_size] = body.bytesize
41
+ self[:status_code] = status_code
42
+ end
43
+ end
44
+
45
+ layout :error_msg, :pointer,
46
+ :content_type, :pointer,
47
+ :body, :pointer,
48
+ :body_size, :int64,
49
+ :status_code, :int32
50
+ end
51
+
52
+ typedef :pointer, :http_request_handle
53
+
54
+ callback :http_send_request, [CHttpRequest, :pointer], :http_request_handle
55
+ callback :http_cancel_request, [CHttpRequest, :http_request_handle, :pointer], :void
56
+
57
+ class CHttpOptions < FFI::Struct
58
+ layout :send_request, :http_send_request,
59
+ :cancel_request, :http_cancel_request,
60
+ :data, :pointer
61
+
62
+ def initialize(send_request, cancel_request)
63
+ super()
64
+
65
+ self[:send_request] = send_request
66
+ self[:cancel_request] = cancel_request
67
+ self[:data] = nil
68
+ end
69
+ end
70
+ end
71
+ end
@@ -1,10 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'ffi'
3
4
  require 'ffi/platform'
4
5
 
5
- module Tanker::CTanker
6
- def self.get_path(name)
7
- File.expand_path "../../../vendor/tanker/#{FFI::Platform::OS}-#{FFI::Platform::ARCH}/"\
8
- "#{FFI::Platform::LIBPREFIX}#{name}.#{FFI::Platform::LIBSUFFIX}", __dir__
6
+ module FFI::Library
7
+ # Marking a function blocking releases the global Ruby lock.
8
+ # This is required for every function that could invoke a callback (including log handler) in another thread
9
+ def blocking_attach_function(func, args, returns = nil)
10
+ attach_function func, args, returns, blocking: true
11
+ end
12
+ end
13
+
14
+ module Tanker
15
+ module CTanker
16
+ def self.get_path(name)
17
+ File.expand_path "../../../vendor/tanker/#{FFI::Platform::OS}-#{FFI::Platform::ARCH}/"\
18
+ "#{FFI::Platform::LIBPREFIX}#{name}.#{FFI::Platform::LIBSUFFIX}", __dir__
19
+ end
20
+
21
+ extend FFI::Library
22
+ ffi_lib get_path('ctanker')
9
23
  end
10
24
  end
@@ -1,30 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'ffi'
4
+ require_relative 'c_tanker/c_lib'
4
5
  require_relative 'core/options'
5
6
  require_relative 'sharing_options'
6
7
  require_relative 'encryption_options'
7
8
  require_relative 'verification_options'
8
- require_relative 'c_tanker/c_lib'
9
9
  require_relative 'c_tanker/c_future'
10
10
  require_relative 'c_tanker/c_verification'
11
11
  require_relative 'c_tanker/c_verification_method'
12
12
  require_relative 'c_tanker/c_log_record'
13
13
  require_relative 'c_tanker/c_device_info'
14
14
 
15
- module FFI::Library
16
- # Marking a function blocking releases the global Ruby lock.
17
- # This is required for every function that could invoke a callback (including log handler) in another thread
18
- def blocking_attach_function(func, args, returns = nil)
19
- attach_function func, args, returns, blocking: true
20
- end
21
- end
22
-
23
15
  module Tanker
24
16
  module CTanker
25
- extend FFI::Library
26
- ffi_lib get_path('ctanker')
27
-
28
17
  typedef :pointer, :session_pointer
29
18
  typedef :pointer, :enc_sess_pointer
30
19
  typedef :pointer, :stream_pointer
@@ -99,6 +88,8 @@ module Tanker
99
88
 
100
89
  blocking_attach_function :tanker_set_log_handler, [:log_handler_callback], :void
101
90
 
91
+ blocking_attach_function :tanker_http_handle_response, [CHttpRequest, CHttpResponse], :void
92
+
102
93
  blocking_attach_function :tanker_prehash_password, [:string], CFuture
103
94
 
104
95
  blocking_attach_function :tanker_free_buffer, [:pointer], :void
@@ -0,0 +1,160 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+
5
+ module Tanker
6
+ module Http
7
+ class HttpRequest
8
+ @@mutex = Mutex.new # rubocop:disable Style/ClassVars I have no idea why you don't like class vars
9
+ @@current_request_id = 0 # rubocop:disable Style/ClassVars
10
+ # Hash(id => request)
11
+ @@running_requests = {} # rubocop:disable Style/ClassVars
12
+
13
+ attr_reader :id
14
+ attr_reader :method
15
+ attr_reader :url
16
+ attr_reader :instance_id
17
+ attr_reader :authorization
18
+ attr_reader :body
19
+ attr_reader :crequest
20
+
21
+ def self.method_str_to_symbol(method)
22
+ case method
23
+ when 'GET' then :get
24
+ when 'POST' then :post
25
+ when 'PATCH' then :patch
26
+ when 'PUT' then :put
27
+ when 'DELETE' then :delete
28
+ else raise "unknown HTTP method #{method}"
29
+ end
30
+ end
31
+
32
+ def initialize(crequest:)
33
+ @@mutex.synchronize do
34
+ @@current_request_id += 1 # rubocop:disable Style/ClassVars
35
+ @id = @@current_request_id
36
+ @@running_requests[@id] = self
37
+ end
38
+
39
+ @method = self.class.method_str_to_symbol crequest[:method]
40
+ @url = crequest[:url]
41
+ @instance_id = crequest[:instance_id]
42
+ @authorization = crequest[:authorization]
43
+ @body = crequest[:body].read_string_length(crequest[:body_size])
44
+
45
+ # Keep the crequest because we need its address to answer to Tanker
46
+ @crequest = crequest
47
+ end
48
+
49
+ # Since Ruby's HTTP libraries are not asynchronous, they do not support cancelation either.
50
+ # When a request is canceled, we let it run until the end, and then we discard its result.
51
+ def self.cancel(id)
52
+ @@mutex.synchronize do
53
+ @@running_requests.delete id
54
+ end
55
+ end
56
+
57
+ def complete_if_not_canceled(&block)
58
+ @@mutex.synchronize do
59
+ unless @@running_requests.delete @id
60
+ # Request has been canceled, don't call Tanker back
61
+ return
62
+ end
63
+
64
+ block.call
65
+ end
66
+ end
67
+ end
68
+
69
+ module ThreadPool
70
+ THREAD_POOL_SIZE = 4
71
+
72
+ def self.thread_loop
73
+ loop do
74
+ work = @queue.pop
75
+ work.call
76
+ end
77
+ end
78
+
79
+ def self.push(proc)
80
+ @queue << proc
81
+ end
82
+
83
+ # Queue is a concurrent queue in Ruby
84
+ @queue = Queue.new
85
+ @http_thread_pool = THREAD_POOL_SIZE.times do
86
+ Thread.new do
87
+ thread_loop
88
+ end
89
+ end
90
+ end
91
+
92
+ class Client
93
+ attr_reader :tanker_http_options
94
+
95
+ def initialize(sdk_type, sdk_version, faraday_adapter)
96
+ @sdk_type = sdk_type
97
+ @sdk_version = sdk_version
98
+ @conn = Faraday.new do |conn|
99
+ conn.adapter faraday_adapter || Faraday.default_adapter
100
+ end
101
+
102
+ # This could be a proc, but for some reason, ffi gives the wrong type
103
+ # for crequest if we don't specify it explicitly here
104
+ @c_send_request = FFI::Function.new(:pointer, [CTanker::CHttpRequest.by_ref, :pointer]) do |crequest, cdata|
105
+ next send_request crequest, cdata
106
+ rescue Exception => e # rubocop:disable Lint/RescueException I do want to rescue all exceptions
107
+ cresponse = CTanker::CHttpResponse.new_error e.message
108
+ CTanker.tanker_http_handle_response(crequest, cresponse)
109
+ end
110
+ @c_cancel_request = proc do |crequest, request_id, cdata|
111
+ cancel_request crequest, request_id, cdata
112
+ rescue Exception => e # rubocop:disable Lint/RescueException I do want to rescue all exceptions
113
+ # This is not recoverable and won't be logged by FFI, let's do our best and log it here just before we crash
114
+ puts "fatal error when canceling HTTP request:\n#{e.full_message}"
115
+ raise
116
+ end
117
+
118
+ @tanker_http_options = CTanker::CHttpOptions.new @c_send_request, @c_cancel_request
119
+ end
120
+
121
+ def process_request(request)
122
+ fresponse = Faraday.run_request(request.method, request.url, request.body, {
123
+ 'X-Tanker-SdkType' => @sdk_type,
124
+ 'X-Tanker-SdkVersion' => @sdk_version,
125
+ 'Authorization' => request.authorization,
126
+ 'X-Tanker-Instanceid' => request.instance_id,
127
+ # net-http really wants a Content-Type
128
+ 'Content-Type' => 'application/data'
129
+ }.compact)
130
+
131
+ request.complete_if_not_canceled do
132
+ cresponse = CTanker::CHttpResponse.new_ok status_code: fresponse.status,
133
+ content_type: fresponse.headers['content-type'],
134
+ body: fresponse.body
135
+ CTanker.tanker_http_handle_response(request.crequest, cresponse)
136
+ end
137
+ rescue Exception => e # rubocop:disable Lint/RescueException I do want to rescue all exceptions
138
+ # NOTE: when debugging, you might want to uncomment this to print a full backtrace
139
+ # puts "HTTP request error:\n#{e.full_message}"
140
+ cresponse = CTanker::CHttpResponse.new_error e.message
141
+ CTanker.tanker_http_handle_response(request.crequest, cresponse)
142
+ end
143
+
144
+ def send_request(crequest, _cdata)
145
+ request = HttpRequest.new crequest: crequest
146
+ ThreadPool.push(proc do
147
+ process_request request
148
+ end)
149
+ FFI::Pointer.new :void, request.id
150
+ end
151
+
152
+ def cancel_request(_crequest, prequest_id, _cdata)
153
+ request_id = prequest_id.to_i
154
+ HttpRequest.cancel(request_id)
155
+ end
156
+ end
157
+ end
158
+
159
+ private_constant :Http
160
+ end
@@ -31,6 +31,9 @@ module Tanker
31
31
  # Do not spam the console of our users.
32
32
  self.class.set_log_handler { |_| } unless self.class.test_and_set_log_handler == 1 # rubocop:disable Lint/EmptyBlock
33
33
 
34
+ @http_client = Http::Client.new options.sdk_type, VERSION, options.faraday_adapter
35
+ options[:http_options] = @http_client.tanker_http_options
36
+
34
37
  @ctanker = CTanker.tanker_create(options).get
35
38
  @freed = false
36
39
  ctanker_addr = @ctanker.address
@@ -2,7 +2,8 @@
2
2
 
3
3
  require 'ffi'
4
4
  require 'tanker/c_tanker/c_string'
5
- require 'tanker/c_tanker/c_backends'
5
+ require 'tanker/c_tanker/c_datastore'
6
+ require 'tanker/c_tanker/c_http'
6
7
 
7
8
  module Tanker
8
9
  # Options that can be given when opening a Tanker session
@@ -20,22 +21,27 @@ module Tanker
20
21
  SDK_TYPE = 'client-ruby'
21
22
  SDK_VERSION = CTanker.new_cstring Core::VERSION
22
23
 
23
- def initialize(app_id:, url: nil, sdk_type: SDK_TYPE, persistent_path: nil, cache_path: nil)
24
+ attr_reader :sdk_type
25
+ attr_reader :faraday_adapter
26
+
27
+ def initialize(app_id:, url: nil, sdk_type: SDK_TYPE, persistent_path: nil, cache_path: nil, faraday_adapter: nil) # rubocop:disable Metrics/ParameterLists
24
28
  super()
25
29
 
26
30
  # NOTE: Instance variables are required to keep the CStrings alive
27
- @app_id = CTanker.new_cstring app_id
28
- @url = CTanker.new_cstring url
29
- @persistent_path = CTanker.new_cstring persistent_path
30
- @cache_path = CTanker.new_cstring cache_path
31
- @sdk_type = CTanker.new_cstring sdk_type
31
+ @c_app_id = CTanker.new_cstring app_id
32
+ @c_url = CTanker.new_cstring url
33
+ @c_persistent_path = CTanker.new_cstring persistent_path
34
+ @c_cache_path = CTanker.new_cstring cache_path
35
+ @sdk_type = sdk_type
36
+ @c_sdk_type = CTanker.new_cstring sdk_type
37
+ @faraday_adapter = faraday_adapter
32
38
 
33
39
  self[:version] = 4
34
- self[:app_id] = @app_id
35
- self[:url] = @url
36
- self[:persistent_path] = @persistent_path
37
- self[:cache_path] = @cache_path
38
- self[:sdk_type] = @sdk_type
40
+ self[:app_id] = @c_app_id
41
+ self[:url] = @c_url
42
+ self[:persistent_path] = @c_persistent_path
43
+ self[:cache_path] = @c_cache_path
44
+ self[:sdk_type] = @c_sdk_type
39
45
  self[:sdk_version] = SDK_VERSION
40
46
  end
41
47
  end
@@ -41,7 +41,7 @@ module Tanker
41
41
 
42
42
  method_base_addr = method_list_ptr.read_pointer
43
43
  method_list = count.times.map do |i|
44
- method_ptr = method_base_addr + i * CTanker::CVerificationMethod.size
44
+ method_ptr = method_base_addr + (i * CTanker::CVerificationMethod.size)
45
45
  CTanker::CVerificationMethod.new(method_ptr).to_verification_method
46
46
  end
47
47
  CTanker.tanker_free_verification_method_list method_list_ptr
@@ -58,7 +58,7 @@ module Tanker
58
58
 
59
59
  method_base_addr = device_list_ptr.read_pointer
60
60
  device_info_list = count.times.map do |i|
61
- method_ptr = method_base_addr + i * CTanker::CDeviceInfo.size
61
+ method_ptr = method_base_addr + (i * CTanker::CDeviceInfo.size)
62
62
  CTanker::CDeviceInfo.new(method_ptr)
63
63
  end
64
64
  CTanker.tanker_free_device_list device_list_ptr
@@ -166,7 +166,7 @@ module Tanker
166
166
  buffer.put_bytes(0, rbbuf)
167
167
  CTanker.tanker_stream_read_operation_finish(operation, rbbuf.size)
168
168
  end
169
- rescue StandardError => e
169
+ rescue Exception => e # rubocop:disable Lint/RescueException I do want to rescue all exceptions
170
170
  @mutex.synchronize do
171
171
  return if @closed
172
172
 
@@ -227,7 +227,7 @@ module Tanker
227
227
 
228
228
  @write.write(ffibuf.read_string(nb_read))
229
229
  end
230
- rescue StandardError => e
230
+ rescue Exception => e # rubocop:disable Lint/RescueException I do want to rescue all exceptions
231
231
  @error = @substream.error || e
232
232
  ensure
233
233
  @write.close
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Tanker
4
4
  class Core
5
- VERSION = '2.30.0'
5
+ VERSION = '2.31.0.beta.1'
6
6
 
7
7
  def self.native_version
8
8
  CTanker.tanker_version_string
data/lib/tanker/core.rb CHANGED
@@ -5,6 +5,7 @@ require 'set'
5
5
  require_relative 'core/version'
6
6
  require_relative 'c_tanker'
7
7
  require_relative 'error'
8
+ require_relative 'core/http'
8
9
  require_relative 'core/session'
9
10
  require_relative 'core/verification'
10
11
  require_relative 'core/encryption'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tanker-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.30.0
4
+ version: 2.31.0.beta.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tanker team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-03 00:00:00.000000000 Z
11
+ date: 2022-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -134,15 +134,11 @@ files:
134
134
  - LICENSE
135
135
  - README.rst
136
136
  - lib/tanker-core.rb
137
- - lib/tanker/admin.rb
138
- - lib/tanker/admin/app.rb
139
- - lib/tanker/admin/c_admin.rb
140
- - lib/tanker/admin/c_admin/c_app_descriptor.rb
141
- - lib/tanker/admin/c_admin/c_app_update_options.rb
142
137
  - lib/tanker/c_tanker.rb
143
- - lib/tanker/c_tanker/c_backends.rb
138
+ - lib/tanker/c_tanker/c_datastore.rb
144
139
  - lib/tanker/c_tanker/c_device_info.rb
145
140
  - lib/tanker/c_tanker/c_future.rb
141
+ - lib/tanker/c_tanker/c_http.rb
146
142
  - lib/tanker/c_tanker/c_lib.rb
147
143
  - lib/tanker/c_tanker/c_log_record.rb
148
144
  - lib/tanker/c_tanker/c_string.rb
@@ -154,6 +150,7 @@ files:
154
150
  - lib/tanker/core/encryption.rb
155
151
  - lib/tanker/core/encryption_session.rb
156
152
  - lib/tanker/core/group.rb
153
+ - lib/tanker/core/http.rb
157
154
  - lib/tanker/core/init.rb
158
155
  - lib/tanker/core/log_record.rb
159
156
  - lib/tanker/core/options.rb
@@ -176,6 +173,7 @@ licenses:
176
173
  metadata:
177
174
  homepage_uri: https://tanker.io
178
175
  source_code_uri: https://github.com/TankerHQ/sdk-ruby
176
+ rubygems_mfa_required: 'true'
179
177
  post_install_message:
180
178
  rdoc_options: []
181
179
  require_paths:
@@ -187,9 +185,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
187
185
  version: 2.6.0
188
186
  required_rubygems_version: !ruby/object:Gem::Requirement
189
187
  requirements:
190
- - - ">="
188
+ - - ">"
191
189
  - !ruby/object:Gem::Version
192
- version: '0'
190
+ version: 1.3.1
193
191
  requirements: []
194
192
  rubygems_version: 3.3.7
195
193
  signing_key:
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Tanker
4
- class Admin
5
- # Information from the Admin SDK concerning a Tanker application
6
- class App
7
- attr_reader :url, :id, :auth_token, :private_key
8
-
9
- def initialize(trustchain_url:, id:, auth_token:, private_key:)
10
- @trustchain_url = trustchain_url
11
- @id = id
12
- @auth_token = auth_token
13
- @private_key = private_key
14
- end
15
-
16
- def get_email_verification_code(email)
17
- CAdmin.tanker_get_email_verification_code(@trustchain_url, @id, @auth_token, email).get_string
18
- end
19
-
20
- def get_sms_verification_code(phone_number)
21
- CAdmin.tanker_get_sms_verification_code(@trustchain_url, @id, @auth_token, phone_number).get_string
22
- end
23
- end
24
- end
25
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'ffi'
4
-
5
- module Tanker
6
- class Admin
7
- class CAdmin::CAppDescriptor < FFI::ManagedStruct
8
- layout :name, :string,
9
- :id, :string,
10
- :auth_token, :string,
11
- :private_key, :string,
12
- :public_key, :string
13
-
14
- def get_email_verification_code(email)
15
- CTanker.tanker_get_email_verification_code(email).get
16
- end
17
-
18
- def get_sms_verification_code(phone_number)
19
- CTanker.tanker_get_sms_verification_code(phone_number).get
20
- end
21
-
22
- def self.release(ptr)
23
- CAdmin.tanker_admin_app_descriptor_free ptr
24
- end
25
- end
26
- end
27
- end
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'ffi'
4
- require 'tanker/c_tanker/c_string'
5
-
6
- module Tanker
7
- class Admin
8
- class AppUpdateOptions < FFI::Struct
9
- def initialize(oidc_client_id: nil, oidc_client_provider: nil,
10
- preverified_verification: nil, user_enrollment: nil)
11
- super()
12
- self[:version] = 4
13
- unless oidc_client_id.nil?
14
- @oidc_client_id = CTanker.new_cstring oidc_client_id
15
- self[:oidc_client_id] = @oidc_client_id
16
- end
17
- unless oidc_client_provider.nil?
18
- @oidc_client_provider = CTanker.new_cstring oidc_client_provider
19
- self[:oidc_client_provider] = @oidc_client_provider
20
- end
21
- unless preverified_verification.nil?
22
- boolptr = FFI::MemoryPointer.new(:bool, 1)
23
- boolptr.put(:bool, 0, preverified_verification)
24
- @preverified_verification = boolptr
25
- self[:preverified_verification] = @preverified_verification
26
- end
27
- unless user_enrollment.nil? # rubocop:disable Style/GuardClause no different than the other parameters
28
- boolptr = FFI::MemoryPointer.new(:bool, 1)
29
- boolptr.put(:bool, 0, user_enrollment)
30
- @user_enrollment = boolptr
31
- self[:user_enrollment] = @user_enrollment
32
- end
33
- end
34
-
35
- layout :version, :uint8,
36
- :oidc_client_id, :pointer,
37
- :oidc_client_provider, :pointer,
38
- :preverified_verification, :pointer,
39
- :user_enrollment, :pointer
40
- end
41
- end
42
- end
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'ffi'
4
- require 'tanker/c_tanker/c_future'
5
- require 'tanker/c_tanker/c_lib'
6
- require_relative 'c_admin/c_app_update_options'
7
-
8
- module Tanker
9
- class Admin
10
- module CAdmin
11
- extend FFI::Library
12
-
13
- ffi_lib Tanker::CTanker.get_path('tanker_admin-c')
14
- typedef :pointer, :admin_pointer
15
-
16
- # NOTE: We use those CFutures with the tanker_future_* functions exposed by CTanker,
17
- # this is safe because we only do simple synchronous blocking calls, without using tanker_future_then.
18
-
19
- attach_function :tanker_admin_connect, [:string, :string, :string], CTanker::CFuture
20
- attach_function :tanker_admin_create_app, [:admin_pointer, :string], CTanker::CFuture
21
- attach_function :tanker_admin_delete_app, [:admin_pointer, :string], CTanker::CFuture
22
- attach_function :tanker_admin_destroy, [:admin_pointer], CTanker::CFuture
23
- attach_function :tanker_admin_app_descriptor_free, [:pointer], :void
24
- attach_function :tanker_admin_app_update, [:admin_pointer, :string,
25
- Tanker::Admin::AppUpdateOptions], CTanker::CFuture
26
- attach_function :tanker_get_email_verification_code, [:string, :string, :string, :string], CTanker::CFuture
27
- attach_function :tanker_get_sms_verification_code, [:string, :string, :string, :string], CTanker::CFuture
28
- end
29
-
30
- private_constant :CAdmin
31
- end
32
- end
data/lib/tanker/admin.rb DELETED
@@ -1,59 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'ffi'
4
- require_relative 'admin/c_admin'
5
- require_relative 'admin/c_admin/c_app_descriptor'
6
- require_relative 'admin/c_admin/c_app_update_options'
7
- require_relative 'admin/app'
8
-
9
- module Tanker
10
- class Admin
11
- def initialize(app_management_token:, app_management_url:, api_url:, environment_name:, trustchain_url:)
12
- @app_management_token = app_management_token
13
- @app_management_url = app_management_url
14
- @api_url = api_url
15
- @environment_name = environment_name
16
- @trustchain_url = trustchain_url
17
- end
18
-
19
- # Authenticate to the Tanker admin server API
20
- # This must be called before doing any other operation
21
- def connect
22
- @cadmin = CAdmin.tanker_admin_connect(@app_management_url, @app_management_token, @environment_name).get
23
- cadmin_addr = @cadmin.address
24
- ObjectSpace.define_finalizer(@cadmin) do |_|
25
- CAdmin.tanker_admin_destroy(FFI::Pointer.new(:void, cadmin_addr)).get
26
- end
27
- end
28
-
29
- def create_app(name)
30
- assert_connected
31
- descriptor_ptr = CAdmin.tanker_admin_create_app(@cadmin, name).get
32
- descriptor = CAdmin::CAppDescriptor.new(descriptor_ptr)
33
- App.new(
34
- trustchain_url: @trustchain_url,
35
- id: descriptor[:id],
36
- auth_token: descriptor[:auth_token],
37
- private_key: descriptor[:private_key]
38
- )
39
- end
40
-
41
- def delete_app(app_id)
42
- assert_connected
43
- CAdmin.tanker_admin_delete_app(@cadmin, app_id).get
44
- end
45
-
46
- def app_update(app_id, app_update_options)
47
- assert_connected
48
- CAdmin.tanker_admin_app_update(@cadmin, app_id, app_update_options).get
49
- end
50
-
51
- private
52
-
53
- def assert_connected
54
- raise 'You need to connect() before using the admin API!' if @cadmin.nil?
55
- end
56
- end
57
-
58
- private_constant :Admin
59
- end