workato-connector-sdk 1.1.0 → 1.3.0
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 +4 -4
- data/README.md +3 -2
- data/VERSION +1 -0
- data/lib/workato/cli/edit_command.rb +3 -1
- data/lib/workato/cli/exec_command.rb +103 -17
- data/lib/workato/cli/generate_command.rb +2 -2
- data/lib/workato/cli/main.rb +17 -10
- data/lib/workato/cli/multi_auth_selected_fallback.rb +33 -0
- data/lib/workato/cli/oauth2_command.rb +50 -12
- data/lib/workato/cli/push_command.rb +2 -2
- data/lib/workato/cli/schema_command.rb +2 -2
- data/lib/workato/connector/sdk/account_properties.rb +2 -2
- data/lib/workato/connector/sdk/action.rb +20 -70
- data/lib/workato/connector/sdk/block_invocation_refinements.rb +2 -10
- data/lib/workato/connector/sdk/connection.rb +115 -30
- data/lib/workato/connector/sdk/connector.rb +71 -81
- data/lib/workato/connector/sdk/core.rb +62 -0
- data/lib/workato/connector/sdk/dsl/aws.rb +8 -5
- data/lib/workato/connector/sdk/dsl/call.rb +1 -1
- data/lib/workato/connector/sdk/dsl/csv_package.rb +133 -0
- data/lib/workato/connector/sdk/dsl/execution_context.rb +45 -0
- data/lib/workato/connector/sdk/dsl/http.rb +1 -1
- data/lib/workato/connector/sdk/dsl/reinvoke_after.rb +84 -0
- data/lib/workato/connector/sdk/dsl/stream_package.rb +65 -0
- data/lib/workato/connector/sdk/dsl/time.rb +0 -14
- data/lib/workato/connector/sdk/dsl/workato_package.rb +146 -0
- data/lib/workato/connector/sdk/dsl.rb +64 -10
- data/lib/workato/connector/sdk/errors.rb +37 -9
- data/lib/workato/connector/sdk/lookup_tables.rb +3 -1
- data/lib/workato/connector/sdk/operation.rb +33 -10
- data/lib/workato/connector/sdk/request.rb +149 -69
- data/lib/workato/connector/sdk/schema/field/convertors.rb +2 -2
- data/lib/workato/connector/sdk/schema/type/unicode_string.rb +1 -1
- data/lib/workato/connector/sdk/schema.rb +12 -8
- data/lib/workato/connector/sdk/settings.rb +14 -3
- data/lib/workato/connector/sdk/stream.rb +243 -0
- data/lib/workato/connector/sdk/streams.rb +71 -0
- data/lib/workato/connector/sdk/summarize.rb +2 -2
- data/lib/workato/connector/sdk/trigger.rb +23 -15
- data/lib/workato/connector/sdk/version.rb +1 -1
- data/lib/workato/connector/sdk.rb +21 -47
- data/lib/workato/extension/array.rb +2 -0
- data/lib/workato/extension/case_sensitive_headers.rb +0 -26
- data/lib/workato/extension/content_encoding_decoder.rb +69 -0
- data/lib/workato/extension/currency/countries.rb +79 -0
- data/lib/workato/extension/currency/countries.yml +18433 -0
- data/lib/workato/extension/currency/currencies.rb +55 -0
- data/lib/workato/extension/currency/currencies.yml +479 -0
- data/lib/workato/extension/currency.rb +73 -5
- data/lib/workato/extension/enumerable.rb +2 -2
- data/lib/workato/extension/extra_chain_cert.rb +0 -14
- data/lib/workato/extension/hash_with_indifferent_access.rb +19 -0
- data/lib/workato/extension/metadata_fix_wrap_kw_args.rb +11 -0
- data/lib/workato/extension/string.rb +16 -112
- data/lib/workato/testing/vcr_encrypted_cassette_serializer.rb +2 -0
- data/lib/workato/types/binary.rb +55 -0
- data/lib/workato/{connector/sdk → utilities}/xml.rb +4 -4
- metadata +61 -64
- data/lib/workato/connector/sdk/dsl/workato_code_lib.rb +0 -160
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e0a739fc6bc5fe15228d209dc24ac4858c3815b4252b5f6d9abd9ae0644b15d
|
4
|
+
data.tar.gz: d4089c8dc7f6c8f9bd171730797a7b82eeb3192883d4b5883a5998985a20001a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6a00086288382c03c024f351e69ca79749d6ef41a833141140274926bec885a7382ce505e9b4981c05a465efa2f1c97cb30697906b8ba6c63d02709dedc9de7
|
7
|
+
data.tar.gz: b5b289bf86ac5970420e20762609256a6280f00a76ae604fcff206f65f40abb517f22c2207f93f1d439b250e4d725e4a5a91865904bf32c93459c52c932e70b3
|
data/README.md
CHANGED
@@ -13,9 +13,10 @@ This guide below showcases how you can do the following things:
|
|
13
13
|
|
14
14
|
## Prerequisites
|
15
15
|
1. Install [RVM ("Ruby Version Manager")](http://rvm.io/) or a Ruby manager of your choice. You can find more at [here](https://www.ruby-lang.org/en/documentation/installation/)
|
16
|
-
2. Choose between Ruby versions `2.
|
16
|
+
2. Choose between Ruby versions `2.7.X`, `3.0.X`, `3.1.X`. Our preferred version is `2.7.6`.
|
17
17
|
3. Verify you're running a valid ruby version. Do this by running either `ruby -v` or the commands within your version manager. i.e., `rvm current` if you have installed RVM.
|
18
18
|
4. For Windows you need tzinfo-data gem installed as well. `gem install tzinfo-data`
|
19
|
+
5. SDK depends on `charlock_holmes` gem. Check [gem's documentation](https://github.com/brianmario/charlock_holmes#installing) if you have troubles when install this dependency. Additional [details for Windows](https://github.com/brianmario/charlock_holmes/issues/84#issuecomment-652877605)
|
19
20
|
|
20
21
|
```bash
|
21
22
|
ruby -v
|
@@ -1123,7 +1124,7 @@ jobs:
|
|
1123
1124
|
runs-on: ubuntu-latest
|
1124
1125
|
strategy:
|
1125
1126
|
matrix:
|
1126
|
-
ruby-version: ['2.
|
1127
|
+
ruby-version: ['2.7', '3.0', '3.1']
|
1127
1128
|
|
1128
1129
|
steps:
|
1129
1130
|
- uses: actions/checkout@v2
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.3.0
|
@@ -3,6 +3,8 @@
|
|
3
3
|
|
4
4
|
require 'active_support/encrypted_configuration'
|
5
5
|
|
6
|
+
require_relative '../extension/metadata_fix_wrap_kw_args'
|
7
|
+
|
6
8
|
module Workato
|
7
9
|
module CLI
|
8
10
|
class EditCommand
|
@@ -23,7 +25,7 @@ module Workato
|
|
23
25
|
|
24
26
|
catch_editing_exceptions do
|
25
27
|
encrypted_config.change do |tmp_path|
|
26
|
-
system("#{ENV
|
28
|
+
system("#{ENV.fetch('EDITOR', nil)} #{tmp_path}")
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
@@ -1,12 +1,17 @@
|
|
1
|
-
# typed:
|
1
|
+
# typed: true
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'thor'
|
5
|
+
require 'active_support/json'
|
6
|
+
require_relative './multi_auth_selected_fallback'
|
7
|
+
|
8
|
+
Method.prepend(T::CompatibilityPatches::MethodExtensions)
|
5
9
|
|
6
10
|
module Workato
|
7
11
|
module CLI
|
8
12
|
class ExecCommand
|
9
13
|
include Thor::Shell
|
14
|
+
include MultiAuthSelectedFallback
|
10
15
|
|
11
16
|
DebugExceptionError = Class.new(StandardError)
|
12
17
|
|
@@ -19,7 +24,7 @@ module Workato
|
|
19
24
|
load_from_default_files
|
20
25
|
inspect_params(params)
|
21
26
|
output = with_progress { execute_path }
|
22
|
-
show_output(output)
|
27
|
+
show_output(output.as_json)
|
23
28
|
output
|
24
29
|
end
|
25
30
|
|
@@ -63,8 +68,12 @@ module Workato
|
|
63
68
|
oauth2_code: options[:oauth2_code],
|
64
69
|
redirect_url: options[:redirect_url],
|
65
70
|
refresh_token: options[:refresh_token],
|
66
|
-
|
67
|
-
|
71
|
+
from: options[:from].to_i,
|
72
|
+
frame_size: options[:frame_size]&.to_i || Workato::Connector::Sdk::Stream::DEFAULT_FRAME_SIZE,
|
73
|
+
recipe_id: Workato::Connector::Sdk::Operation.recipe_id!
|
74
|
+
}.tap do |h|
|
75
|
+
h[:to] = h[:from] + h[:frame_size] - 1
|
76
|
+
end
|
68
77
|
end
|
69
78
|
|
70
79
|
def connector
|
@@ -84,25 +93,30 @@ module Workato
|
|
84
93
|
)
|
85
94
|
@settings = settings_store.read
|
86
95
|
|
87
|
-
Workato::Connector::Sdk::Connection.
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
96
|
+
Workato::Connector::Sdk::Connection.multi_auth_selected_fallback = lambda do |options|
|
97
|
+
next @selected_auth_type if @selected_auth_type
|
98
|
+
|
99
|
+
with_user_interaction do
|
100
|
+
@selected_auth_type = multi_auth_selected_fallback(options)
|
101
|
+
end
|
102
|
+
end
|
92
103
|
|
93
|
-
|
94
|
-
|
104
|
+
Workato::Connector::Sdk::Connection.on_settings_update = lambda do |message, _settings_before, refresher|
|
105
|
+
new_settings = refresher.call
|
106
|
+
break unless new_settings
|
107
|
+
break new_settings if @settings == new_settings
|
95
108
|
|
109
|
+
with_user_interaction do
|
96
110
|
loop do
|
111
|
+
say(message)
|
97
112
|
answer = ask('Updated settings file with new connection attributes? (Yes or No)').to_s.downcase
|
98
113
|
break new_settings if %w[n no].include?(answer)
|
99
114
|
next unless %w[y yes].include?(answer)
|
100
115
|
|
116
|
+
@settings.merge!(new_settings)
|
101
117
|
settings_store.update(new_settings)
|
102
118
|
break new_settings
|
103
119
|
end
|
104
|
-
ensure
|
105
|
-
$stdout.resume if verbose?
|
106
120
|
end
|
107
121
|
end
|
108
122
|
|
@@ -130,7 +144,12 @@ module Workato
|
|
130
144
|
end
|
131
145
|
|
132
146
|
def execute_path
|
133
|
-
|
147
|
+
InvokePath.new(path: path, connector: connector, params: params).call
|
148
|
+
rescue Workato::Connector::Sdk::InvalidMultiAuthDefinition => e
|
149
|
+
raise "#{e.message}. Please ensure:\n" \
|
150
|
+
"- 'selected' block is defined and returns value from 'options' list\n" \
|
151
|
+
"- settings file contains value expected by 'selected' block\n\n" \
|
152
|
+
'See more: https://docs.workato.com/developing-connectors/sdk/guides/authentication/multi_auth.html'
|
134
153
|
rescue Exception => e # rubocop:disable Lint/RescueException
|
135
154
|
raise DebugExceptionError, e if options[:debug]
|
136
155
|
|
@@ -139,9 +158,7 @@ module Workato
|
|
139
158
|
|
140
159
|
def show_output(output)
|
141
160
|
if options[:output].present?
|
142
|
-
File.
|
143
|
-
f.write(JSON.dump(output))
|
144
|
-
end
|
161
|
+
File.write(options[:output], JSON.dump(output))
|
145
162
|
elsif options[:output].nil?
|
146
163
|
say('OUTPUT') if verbose?
|
147
164
|
jj output
|
@@ -181,6 +198,16 @@ module Workato
|
|
181
198
|
output
|
182
199
|
end
|
183
200
|
|
201
|
+
def with_user_interaction
|
202
|
+
$stdout.pause if verbose?
|
203
|
+
say('')
|
204
|
+
|
205
|
+
yield
|
206
|
+
ensure
|
207
|
+
say('')
|
208
|
+
$stdout.resume if verbose?
|
209
|
+
end
|
210
|
+
|
184
211
|
class ProgressLogger < SimpleDelegator
|
185
212
|
def initialize(progress)
|
186
213
|
super($stdout)
|
@@ -194,6 +221,65 @@ module Workato
|
|
194
221
|
alias puts log
|
195
222
|
alias print log
|
196
223
|
end
|
224
|
+
|
225
|
+
class InvokePath
|
226
|
+
extend T::Sig
|
227
|
+
|
228
|
+
sig do
|
229
|
+
params(
|
230
|
+
path: String,
|
231
|
+
connector: Workato::Connector::Sdk::Connector,
|
232
|
+
params: T::Hash[Symbol, T.untyped]
|
233
|
+
).void
|
234
|
+
end
|
235
|
+
def initialize(path:, connector:, params:)
|
236
|
+
@path = T.let(path, String)
|
237
|
+
@connector = T.let(connector, Workato::Connector::Sdk::Connector)
|
238
|
+
@params = T.let(params, T::Hash[Symbol, T.untyped])
|
239
|
+
end
|
240
|
+
|
241
|
+
sig { returns(T.untyped) }
|
242
|
+
def call
|
243
|
+
invoke_path
|
244
|
+
end
|
245
|
+
|
246
|
+
private
|
247
|
+
|
248
|
+
sig { returns(String) }
|
249
|
+
attr_reader :path
|
250
|
+
|
251
|
+
sig { returns(Workato::Connector::Sdk::Connector) }
|
252
|
+
attr_reader :connector
|
253
|
+
|
254
|
+
sig { returns(T::Hash[Symbol, T.untyped]) }
|
255
|
+
attr_reader :params
|
256
|
+
|
257
|
+
sig { returns(T.untyped) }
|
258
|
+
def invoke_path
|
259
|
+
methods = path.split('.')
|
260
|
+
method = methods.pop
|
261
|
+
raise ArgumentError, 'path is not found' unless method
|
262
|
+
|
263
|
+
object = methods.inject(connector) { |obj, m| obj.public_send(m) }
|
264
|
+
output = invoke_method(object, method)
|
265
|
+
if output.respond_to?(:invoke)
|
266
|
+
invoke_method(output, :invoke)
|
267
|
+
else
|
268
|
+
output
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
sig { params(object: T.untyped, method: T.any(Symbol, String)).returns(T.untyped) }
|
273
|
+
def invoke_method(object, method)
|
274
|
+
parameters = object.method(method).parameters.reject { |p| p[0] == :block }.map(&:second)
|
275
|
+
args = params.values_at(*parameters)
|
276
|
+
if parameters.last == :args
|
277
|
+
args = args.take(args.length - 1) + Array.wrap(args.last).flatten(1)
|
278
|
+
end
|
279
|
+
object.public_send(method, *args)
|
280
|
+
end
|
281
|
+
end
|
282
|
+
private_constant :InvokePath
|
197
283
|
end
|
198
284
|
end
|
199
285
|
end
|
@@ -51,7 +51,7 @@ module Workato
|
|
51
51
|
default: 'comma'
|
52
52
|
method_option :api_email,
|
53
53
|
type: :string,
|
54
|
-
desc: 'Email for accessing Workato API or '\
|
54
|
+
desc: 'Email for accessing Workato API or ' \
|
55
55
|
"set #{Workato::Connector::Sdk::WORKATO_API_EMAIL_ENV} environment variable"
|
56
56
|
method_option :api_token,
|
57
57
|
type: :string,
|
@@ -125,7 +125,7 @@ module Workato
|
|
125
125
|
end
|
126
126
|
|
127
127
|
def sanitized_filename(name)
|
128
|
-
name.downcase.gsub(/[^0-9A-z
|
128
|
+
name.downcase.gsub(/[^0-9A-z.-]/, '_')
|
129
129
|
end
|
130
130
|
end
|
131
131
|
end
|
data/lib/workato/cli/main.rb
CHANGED
@@ -34,14 +34,14 @@ module Workato
|
|
34
34
|
method_option :connector, type: :string, aliases: '-c', desc: 'Path to connector source code',
|
35
35
|
lazy_default: Workato::Connector::Sdk::DEFAULT_CONNECTOR_PATH
|
36
36
|
method_option :settings, type: :string, aliases: '-s',
|
37
|
-
desc: 'Path to plain or encrypted file with connection configs, '\
|
37
|
+
desc: 'Path to plain or encrypted file with connection configs, ' \
|
38
38
|
'passwords, tokens, secrets etc',
|
39
39
|
lazy_default: Workato::Connector::Sdk::DEFAULT_ENCRYPTED_SETTINGS_PATH
|
40
40
|
method_option :connection, type: :string, aliases: '-n',
|
41
41
|
desc: 'Connection name if settings file contains multiple settings'
|
42
42
|
method_option :key, type: :string, aliases: '-k',
|
43
43
|
lazy_default: Workato::Connector::Sdk::DEFAULT_MASTER_KEY_PATH,
|
44
|
-
desc: "Path to file with encrypt/decrypt key.\n"\
|
44
|
+
desc: "Path to file with encrypt/decrypt key.\n" \
|
45
45
|
"NOTE: key from #{Workato::Connector::Sdk::DEFAULT_MASTER_KEY_ENV} has higher priority"
|
46
46
|
method_option :input, type: :string, aliases: '-i', desc: 'Path to file with input JSON'
|
47
47
|
method_option :closure, type: :string, desc: 'Path to file with next poll closure JSON'
|
@@ -61,6 +61,8 @@ module Workato
|
|
61
61
|
method_option :oauth2_code, type: :string, desc: 'OAuth2 code exchange to tokens pair'
|
62
62
|
method_option :redirect_url, type: :string, desc: 'OAuth2 callback url'
|
63
63
|
method_option :refresh_token, type: :string, desc: 'OAuth2 refresh token'
|
64
|
+
method_option :from, type: :numeric, desc: 'Stream byte offset to read from'
|
65
|
+
method_option :frame_size, type: :numeric, desc: 'Stream chunk read size in bytes. Should be positive'
|
64
66
|
|
65
67
|
method_option :debug, type: :boolean
|
66
68
|
|
@@ -75,7 +77,7 @@ module Workato
|
|
75
77
|
|
76
78
|
method_option :key, type: :string, aliases: '-k',
|
77
79
|
lazy_default: Workato::Connector::Sdk::DEFAULT_MASTER_KEY_PATH,
|
78
|
-
desc: "Path to file with encrypt/decrypt key.\n"\
|
80
|
+
desc: "Path to file with encrypt/decrypt key.\n" \
|
79
81
|
"NOTE: key from #{Workato::Connector::Sdk::DEFAULT_MASTER_KEY_ENV} has higher priority"
|
80
82
|
|
81
83
|
def edit(path)
|
@@ -127,19 +129,19 @@ module Workato
|
|
127
129
|
lazy_default: Workato::Connector::Sdk::DEFAULT_CONNECTOR_PATH
|
128
130
|
method_option :api_email,
|
129
131
|
type: :string,
|
130
|
-
desc: "Email for accessing Workato API.\n"\
|
131
|
-
"If present overrides value from #{Workato::Connector::Sdk::WORKATO_API_EMAIL_ENV} "\
|
132
|
+
desc: "Email for accessing Workato API.\n" \
|
133
|
+
"If present overrides value from #{Workato::Connector::Sdk::WORKATO_API_EMAIL_ENV} " \
|
132
134
|
'environment variable.'
|
133
135
|
method_option :api_token,
|
134
136
|
type: :string,
|
135
137
|
desc: "Token for accessing Workato API.\n" \
|
136
|
-
"If present overrides value from #{Workato::Connector::Sdk::WORKATO_API_TOKEN_ENV} "\
|
138
|
+
"If present overrides value from #{Workato::Connector::Sdk::WORKATO_API_TOKEN_ENV} " \
|
137
139
|
'environment variable.'
|
138
140
|
method_option :environment,
|
139
141
|
type: :string,
|
140
|
-
desc: "Data center specific URL to push connector code.\n"\
|
141
|
-
"If present overrides value from #{Workato::Connector::Sdk::WORKATO_BASE_URL_ENV} "\
|
142
|
-
"environment variable.\n"\
|
142
|
+
desc: "Data center specific URL to push connector code.\n" \
|
143
|
+
"If present overrides value from #{Workato::Connector::Sdk::WORKATO_BASE_URL_ENV} " \
|
144
|
+
"environment variable.\n" \
|
143
145
|
"Examples: 'https://app.workato.com', 'https://app.eu.workato.com'"
|
144
146
|
method_option :folder,
|
145
147
|
type: :string,
|
@@ -171,7 +173,7 @@ module Workato
|
|
171
173
|
type: :string,
|
172
174
|
aliases: '-k',
|
173
175
|
lazy_default: Workato::Connector::Sdk::DEFAULT_MASTER_KEY_PATH,
|
174
|
-
desc: "Path to file with encrypt/decrypt key.\n"\
|
176
|
+
desc: "Path to file with encrypt/decrypt key.\n" \
|
175
177
|
"NOTE: key from #{Workato::Connector::Sdk::DEFAULT_MASTER_KEY_ENV} has higher priority"
|
176
178
|
method_option :port,
|
177
179
|
type: :string,
|
@@ -191,6 +193,11 @@ module Workato
|
|
191
193
|
).call
|
192
194
|
end
|
193
195
|
|
196
|
+
desc 'version', 'Shows gem version'
|
197
|
+
def version
|
198
|
+
puts Workato::Connector::Sdk::VERSION
|
199
|
+
end
|
200
|
+
|
194
201
|
class << self
|
195
202
|
def print_options(shell, options, group_name = nil)
|
196
203
|
return if options.empty?
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Workato
|
4
|
+
module CLI
|
5
|
+
module MultiAuthSelectedFallback
|
6
|
+
private
|
7
|
+
|
8
|
+
def multi_auth_selected_fallback(options)
|
9
|
+
say('Please select current auth type for multi-auth connector:')
|
10
|
+
options = options.keys
|
11
|
+
options.each_with_index do |option, idx|
|
12
|
+
say "[#{idx + 1}] #{option}"
|
13
|
+
end
|
14
|
+
say '[q] <exit>'
|
15
|
+
say('')
|
16
|
+
|
17
|
+
multi_auth_selected_fallback = loop do
|
18
|
+
answer = ask('Your choice:').to_s.downcase
|
19
|
+
break if answer == 'q'
|
20
|
+
next unless /\d+/ =~ answer && options[answer.to_i - 1]
|
21
|
+
|
22
|
+
break options[answer.to_i - 1]
|
23
|
+
end
|
24
|
+
return unless multi_auth_selected_fallback
|
25
|
+
|
26
|
+
say('')
|
27
|
+
say('Put selected auth type in your settings file to avoid this message in future')
|
28
|
+
|
29
|
+
multi_auth_selected_fallback
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -3,11 +3,13 @@
|
|
3
3
|
|
4
4
|
require 'securerandom'
|
5
5
|
require 'workato/web/app'
|
6
|
+
require_relative './multi_auth_selected_fallback'
|
6
7
|
|
7
8
|
module Workato
|
8
9
|
module CLI
|
9
10
|
class OAuth2Command
|
10
11
|
include Thor::Shell
|
12
|
+
include MultiAuthSelectedFallback
|
11
13
|
|
12
14
|
AWAIT_CODE_TIMEOUT_INTERVAL = 180 # seconds
|
13
15
|
AWAIT_CODE_SLEEP_INTERVAL = 5 # seconds
|
@@ -24,6 +26,7 @@ module Workato
|
|
24
26
|
end
|
25
27
|
|
26
28
|
def call
|
29
|
+
ensure_oauth2_type
|
27
30
|
require_gems
|
28
31
|
start_webrick
|
29
32
|
|
@@ -94,16 +97,31 @@ module Workato
|
|
94
97
|
end
|
95
98
|
|
96
99
|
def stop_webrick
|
100
|
+
return unless @thread
|
101
|
+
|
97
102
|
Rack::Handler::WEBrick.shutdown
|
98
103
|
@thread.exit
|
99
104
|
end
|
100
105
|
|
106
|
+
def ensure_oauth2_type
|
107
|
+
unless connector.connection.authorization.oauth2?
|
108
|
+
raise 'Authorization type is not OAuth2. ' \
|
109
|
+
'For multi-auth connector ensure correct auth type was used. ' \
|
110
|
+
"Expected: 'oauth2', got: '#{connector.connection.authorization.type}''"
|
111
|
+
end
|
112
|
+
rescue Workato::Connector::Sdk::InvalidMultiAuthDefinition => e
|
113
|
+
raise "#{e.message}. Please ensure:\n" \
|
114
|
+
"- 'selected' block is defined and returns value from 'options' list\n" \
|
115
|
+
"- settings file contains value expected by 'selected' block\n\n" \
|
116
|
+
'See more: https://docs.workato.com/developing-connectors/sdk/guides/authentication/multi_auth.html'
|
117
|
+
end
|
118
|
+
|
101
119
|
def client
|
102
120
|
@client ||= OAuth2::Client.new(
|
103
|
-
connector.connection.authorization.client_id
|
104
|
-
connector.connection.authorization.client_secret
|
105
|
-
site: connector.connection.base_uri
|
106
|
-
token_url: connector.connection.authorization.token_url
|
121
|
+
connector.connection.authorization.client_id,
|
122
|
+
connector.connection.authorization.client_secret,
|
123
|
+
site: connector.connection.base_uri,
|
124
|
+
token_url: connector.connection.authorization.token_url,
|
107
125
|
redirect_uri: redirect_url
|
108
126
|
)
|
109
127
|
end
|
@@ -112,14 +130,14 @@ module Workato
|
|
112
130
|
return @authorize_url if defined?(@authorize_url)
|
113
131
|
|
114
132
|
@authorize_url =
|
115
|
-
if (authorization_url = connector.connection.authorization.authorization_url
|
133
|
+
if (authorization_url = connector.connection.authorization.authorization_url)
|
116
134
|
params = {
|
117
135
|
state: SecureRandom.hex(8),
|
118
|
-
client_id: connector.connection.authorization.client_id
|
136
|
+
client_id: connector.connection.authorization.client_id,
|
119
137
|
redirect_uri: redirect_url
|
120
|
-
}
|
138
|
+
}.with_indifferent_access
|
121
139
|
uri = URI(authorization_url)
|
122
|
-
uri.query = params.
|
140
|
+
uri.query = params.merge(Rack::Utils.parse_nested_query(uri.query || '')).to_param
|
123
141
|
uri.to_s
|
124
142
|
end
|
125
143
|
end
|
@@ -133,12 +151,25 @@ module Workato
|
|
133
151
|
end
|
134
152
|
|
135
153
|
def settings
|
136
|
-
@settings
|
154
|
+
return @settings if defined?(@settings)
|
155
|
+
|
156
|
+
@settings = settings_store.read
|
157
|
+
|
158
|
+
Workato::Connector::Sdk::Connection.multi_auth_selected_fallback = lambda do |options|
|
159
|
+
next @selected_auth_type if @selected_auth_type
|
160
|
+
|
161
|
+
with_user_interaction do
|
162
|
+
@selected_auth_type = multi_auth_selected_fallback(options)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
@settings
|
137
167
|
end
|
138
168
|
|
139
169
|
def connector
|
140
170
|
@connector ||= Workato::Connector::Sdk::Connector.from_file(
|
141
|
-
options[:connector] || Workato::Connector::Sdk::DEFAULT_CONNECTOR_PATH
|
171
|
+
options[:connector] || Workato::Connector::Sdk::DEFAULT_CONNECTOR_PATH,
|
172
|
+
settings
|
142
173
|
)
|
143
174
|
end
|
144
175
|
|
@@ -156,8 +187,8 @@ module Workato
|
|
156
187
|
end
|
157
188
|
|
158
189
|
def acquire_token(code)
|
159
|
-
if connector.
|
160
|
-
tokens, _, extra_settings = connector.connection.authorization.acquire(
|
190
|
+
if connector.connection.authorization.source[:acquire]
|
191
|
+
tokens, _, extra_settings = connector.connection.authorization.acquire(nil, code, redirect_url)
|
161
192
|
tokens ||= {}
|
162
193
|
extra_settings ||= {}
|
163
194
|
extra_settings.merge(tokens)
|
@@ -178,6 +209,13 @@ module Workato
|
|
178
209
|
response = http.request(request)
|
179
210
|
response.body
|
180
211
|
end
|
212
|
+
|
213
|
+
def with_user_interaction
|
214
|
+
say('')
|
215
|
+
yield
|
216
|
+
ensure
|
217
|
+
say('')
|
218
|
+
end
|
181
219
|
end
|
182
220
|
end
|
183
221
|
end
|
@@ -35,8 +35,8 @@ module Workato
|
|
35
35
|
@api_base_url = ENVIRONMENTS.fetch(options[:environment]) do
|
36
36
|
options[:environment].presence || Workato::Connector::Sdk::WORKATO_BASE_URL
|
37
37
|
end
|
38
|
-
@api_email = options[:api_email] || ENV
|
39
|
-
@api_token = options[:api_token] || ENV
|
38
|
+
@api_email = options[:api_email] || ENV.fetch(Workato::Connector::Sdk::WORKATO_API_EMAIL_ENV, nil)
|
39
|
+
@api_token = options[:api_token] || ENV.fetch(Workato::Connector::Sdk::WORKATO_API_TOKEN_ENV, nil)
|
40
40
|
@folder_id = options[:folder]
|
41
41
|
end
|
42
42
|
|
@@ -12,8 +12,8 @@ module Workato
|
|
12
12
|
API_GENERATE_SCHEMA_PATH = '/api/sdk/generate_schema'
|
13
13
|
|
14
14
|
def initialize(options:)
|
15
|
-
@api_email = options[:api_email] || ENV
|
16
|
-
@api_token = options[:api_token] || ENV
|
15
|
+
@api_email = options[:api_email] || ENV.fetch(Workato::Connector::Sdk::WORKATO_API_EMAIL_ENV, nil)
|
16
|
+
@api_token = options[:api_token] || ENV.fetch(Workato::Connector::Sdk::WORKATO_API_TOKEN_ENV, nil)
|
17
17
|
@options = options
|
18
18
|
end
|
19
19
|
|
@@ -29,9 +29,9 @@ module Workato
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def self.from_csv(path = './account_properties.csv')
|
32
|
-
props = CSV.foreach(path, headers: true, return_headers: false).
|
32
|
+
props = CSV.foreach(path, headers: true, return_headers: false).to_h do |row|
|
33
33
|
[row[0], row[1]]
|
34
|
-
end
|
34
|
+
end
|
35
35
|
instance.load_data(props)
|
36
36
|
end
|
37
37
|
|