tanker-core 2.29.2.alpha.2 → 2.29.2.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tanker/admin/app.rb +6 -6
- data/lib/tanker/admin/c_admin/c_app_descriptor.rb +27 -0
- data/lib/tanker/admin/c_admin/c_app_update_options.rb +42 -0
- data/lib/tanker/admin/c_admin.rb +32 -0
- data/lib/tanker/admin.rb +56 -2
- data/lib/tanker/core/session.rb +2 -2
- data/lib/tanker/core/version.rb +1 -1
- metadata +4 -4
- data/lib/tanker/admin/app_update_options.rb +0 -26
- data/lib/tanker/admin/client.rb +0 -79
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57bda3a7ea4cb2eba52188065a5fa58e080920dd40b912c8149e8a0152d406a0
|
4
|
+
data.tar.gz: d5e28a7e687903b2a80c138f79161d2b32fcc915f68f556ed0b2bfe4f6c8602d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7a51f0d79199fcffedc20dbfe7d91b23f82945985f2382ad276979b5abef591489444b0e6b8a058cead31b73c680ce5aff578a02095e3b5373324e266295f8b
|
7
|
+
data.tar.gz: 7065c8cc8661d5fb74da030b0f44d131a5f0fe8145c23c0afd221c4efd857abafe32835ec213e974adc4b362209602953ac4ba1d7bef9c33170f4efb2713d765
|
data/lib/tanker/admin/app.rb
CHANGED
@@ -4,21 +4,21 @@ module Tanker
|
|
4
4
|
class Admin
|
5
5
|
# Information from the Admin SDK concerning a Tanker application
|
6
6
|
class App
|
7
|
-
attr_reader :
|
7
|
+
attr_reader :url, :id, :auth_token, :private_key
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
@
|
9
|
+
def initialize(trustchain_url:, id:, auth_token:, private_key:)
|
10
|
+
@trustchain_url = trustchain_url
|
11
11
|
@id = id
|
12
12
|
@auth_token = auth_token
|
13
|
-
@
|
13
|
+
@private_key = private_key
|
14
14
|
end
|
15
15
|
|
16
16
|
def get_email_verification_code(email)
|
17
|
-
|
17
|
+
CAdmin.tanker_get_email_verification_code(@trustchain_url, @id, @auth_token, email).get_string
|
18
18
|
end
|
19
19
|
|
20
20
|
def get_sms_verification_code(phone_number)
|
21
|
-
|
21
|
+
CAdmin.tanker_get_sms_verification_code(@trustchain_url, @id, @auth_token, phone_number).get_string
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -0,0 +1,27 @@
|
|
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
|
@@ -0,0 +1,42 @@
|
|
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
|
@@ -0,0 +1,32 @@
|
|
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
CHANGED
@@ -1,5 +1,59 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
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'
|
4
7
|
require_relative 'admin/app'
|
5
|
-
|
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
|
data/lib/tanker/core/session.rb
CHANGED
@@ -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 +
|
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 +
|
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
|
data/lib/tanker/core/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tanker-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.29.2.
|
4
|
+
version: 2.29.2.beta.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tanker team
|
@@ -136,8 +136,9 @@ files:
|
|
136
136
|
- lib/tanker-core.rb
|
137
137
|
- lib/tanker/admin.rb
|
138
138
|
- lib/tanker/admin/app.rb
|
139
|
-
- lib/tanker/admin/
|
140
|
-
- lib/tanker/admin/
|
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
|
141
142
|
- lib/tanker/c_tanker.rb
|
142
143
|
- lib/tanker/c_tanker/c_backends.rb
|
143
144
|
- lib/tanker/c_tanker/c_device_info.rb
|
@@ -175,7 +176,6 @@ licenses:
|
|
175
176
|
metadata:
|
176
177
|
homepage_uri: https://tanker.io
|
177
178
|
source_code_uri: https://github.com/TankerHQ/sdk-ruby
|
178
|
-
rubygems_mfa_required: 'true'
|
179
179
|
post_install_message:
|
180
180
|
rdoc_options: []
|
181
181
|
require_paths:
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Tanker
|
4
|
-
class Admin
|
5
|
-
class AppUpdateOptions
|
6
|
-
attr_accessor :oidc_client_id, :oidc_client_provider, :preverified_verification, :user_enrollment
|
7
|
-
|
8
|
-
def initialize(oidc_client_id: nil, oidc_client_provider: nil,
|
9
|
-
preverified_verification: nil, user_enrollment: nil)
|
10
|
-
@oidc_client_id = oidc_client_id
|
11
|
-
@oidc_client_provider = oidc_client_provider
|
12
|
-
@preverified_verification = preverified_verification
|
13
|
-
@user_enrollment = user_enrollment
|
14
|
-
end
|
15
|
-
|
16
|
-
def as_json(_options = {})
|
17
|
-
{
|
18
|
-
oidc_client_id: @oidc_client_id,
|
19
|
-
oidc_provider: @oidc_client_provider,
|
20
|
-
preverified_verification_enabled: @preverified_verification,
|
21
|
-
enroll_users_enabled: @user_enrollment
|
22
|
-
}
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
data/lib/tanker/admin/client.rb
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'faraday'
|
4
|
-
require 'faraday_middleware'
|
5
|
-
|
6
|
-
require_relative 'app'
|
7
|
-
require_relative 'app_update_options'
|
8
|
-
|
9
|
-
module Tanker
|
10
|
-
class Admin
|
11
|
-
class Client
|
12
|
-
def self.init_conn(conn)
|
13
|
-
conn.request :json
|
14
|
-
conn.response :raise_error
|
15
|
-
## in case of verbosity need
|
16
|
-
# require 'logger'
|
17
|
-
# conn.response :logger, ::Logger.new(STDOUT), bodies: true
|
18
|
-
conn.response :json
|
19
|
-
conn.adapter :net_http
|
20
|
-
conn
|
21
|
-
end
|
22
|
-
|
23
|
-
def initialize(app_management_token:, app_management_url:, api_url:, environment_name:, trustchain_url:)
|
24
|
-
@app_management_token = app_management_token
|
25
|
-
@app_management_url = app_management_url
|
26
|
-
@api_url = api_url
|
27
|
-
@environment_name = environment_name
|
28
|
-
@trustchain_url = trustchain_url
|
29
|
-
@conn = Faraday.new(url: "#{@app_management_url}/v1/apps") do |conn|
|
30
|
-
conn.request :authorization, 'Bearer', @app_management_token
|
31
|
-
self.class.init_conn(conn)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def create_app(name)
|
36
|
-
response = @conn.post do |req|
|
37
|
-
req.body = { name: name, environment_name: @environment_name }
|
38
|
-
req.headers['Accept'] = 'application/json'
|
39
|
-
end
|
40
|
-
App.new(
|
41
|
-
admin: self,
|
42
|
-
id: response.body['app']['id'],
|
43
|
-
auth_token: response.body['app']['auth_token'],
|
44
|
-
secret: response.body['app']['secret']
|
45
|
-
)
|
46
|
-
end
|
47
|
-
|
48
|
-
def delete_app(app_id)
|
49
|
-
capp_id = Faraday::Utils.escape(app_id)
|
50
|
-
@conn.delete(capp_id)
|
51
|
-
end
|
52
|
-
|
53
|
-
def app_update(app_id, app_update_options)
|
54
|
-
capp_id = Faraday::Utils.escape(app_id)
|
55
|
-
response = @conn.patch(capp_id) do |req|
|
56
|
-
req.body = app_update_options.as_json
|
57
|
-
end
|
58
|
-
response.body
|
59
|
-
end
|
60
|
-
|
61
|
-
def get_email_verification_code(app_id, auth_token, email)
|
62
|
-
conn = Faraday.new(url: @api_url) do |f|
|
63
|
-
self.class.init_conn(f)
|
64
|
-
end
|
65
|
-
response = conn.post('/verification/email/code', { email: email, app_id: app_id, auth_token: auth_token })
|
66
|
-
response.body['verification_code']
|
67
|
-
end
|
68
|
-
|
69
|
-
def get_sms_verification_code(app_id, auth_token, phone_number)
|
70
|
-
conn = Faraday.new(url: @api_url) do |f|
|
71
|
-
self.class.init_conn(f)
|
72
|
-
end
|
73
|
-
response = conn.post('/verification/sms/code',
|
74
|
-
{ phone_number: phone_number, app_id: app_id, auth_token: auth_token })
|
75
|
-
response.body['verification_code']
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|