workato-connector-sdk 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +5 -5
  2. data/lib/workato/cli/edit_command.rb +4 -3
  3. data/lib/workato/cli/exec_command.rb +24 -35
  4. data/lib/workato/cli/generate_command.rb +1 -0
  5. data/lib/workato/cli/generators/connector_generator.rb +1 -0
  6. data/lib/workato/cli/generators/master_key_generator.rb +1 -0
  7. data/lib/workato/cli/main.rb +1 -0
  8. data/lib/workato/cli/oauth2_command.rb +6 -5
  9. data/lib/workato/cli/push_command.rb +5 -4
  10. data/lib/workato/cli/schema_command.rb +4 -3
  11. data/lib/workato/connector/sdk/account_properties.rb +1 -0
  12. data/lib/workato/connector/sdk/action.rb +78 -20
  13. data/lib/workato/connector/sdk/block_invocation_refinements.rb +1 -0
  14. data/lib/workato/connector/sdk/connection.rb +202 -44
  15. data/lib/workato/connector/sdk/connector.rb +200 -65
  16. data/lib/workato/connector/sdk/dsl/account_property.rb +1 -0
  17. data/lib/workato/connector/sdk/dsl/aws.rb +23 -27
  18. data/lib/workato/connector/sdk/dsl/call.rb +1 -0
  19. data/lib/workato/connector/sdk/dsl/error.rb +1 -0
  20. data/lib/workato/connector/sdk/dsl/http.rb +2 -7
  21. data/lib/workato/connector/sdk/dsl/lookup_table.rb +1 -0
  22. data/lib/workato/connector/sdk/dsl/time.rb +6 -0
  23. data/lib/workato/connector/sdk/dsl/workato_code_lib.rb +38 -0
  24. data/lib/workato/connector/sdk/dsl/workato_schema.rb +1 -0
  25. data/lib/workato/connector/sdk/dsl.rb +19 -4
  26. data/lib/workato/connector/sdk/errors.rb +4 -3
  27. data/lib/workato/connector/sdk/lookup_tables.rb +1 -0
  28. data/lib/workato/connector/sdk/object_definitions.rb +7 -8
  29. data/lib/workato/connector/sdk/operation.rb +127 -88
  30. data/lib/workato/connector/sdk/request.rb +45 -17
  31. data/lib/workato/connector/sdk/schema/field/array.rb +1 -0
  32. data/lib/workato/connector/sdk/schema/field/convertors.rb +1 -0
  33. data/lib/workato/connector/sdk/schema/field/date.rb +1 -0
  34. data/lib/workato/connector/sdk/schema/field/date_time.rb +1 -0
  35. data/lib/workato/connector/sdk/schema/field/integer.rb +1 -0
  36. data/lib/workato/connector/sdk/schema/field/number.rb +1 -0
  37. data/lib/workato/connector/sdk/schema/field/object.rb +1 -0
  38. data/lib/workato/connector/sdk/schema/field/string.rb +1 -0
  39. data/lib/workato/connector/sdk/schema/type/time.rb +1 -0
  40. data/lib/workato/connector/sdk/schema/type/unicode_string.rb +1 -0
  41. data/lib/workato/connector/sdk/schema.rb +1 -0
  42. data/lib/workato/connector/sdk/settings.rb +9 -4
  43. data/lib/workato/connector/sdk/summarize.rb +3 -2
  44. data/lib/workato/connector/sdk/trigger.rb +81 -7
  45. data/lib/workato/connector/sdk/version.rb +2 -1
  46. data/lib/workato/connector/sdk/workato_schemas.rb +1 -0
  47. data/lib/workato/connector/sdk/xml.rb +1 -0
  48. data/lib/workato/connector/sdk.rb +4 -0
  49. data/lib/workato/extension/array.rb +1 -0
  50. data/lib/workato/extension/case_sensitive_headers.rb +1 -0
  51. data/lib/workato/extension/currency.rb +1 -0
  52. data/lib/workato/extension/date.rb +1 -0
  53. data/lib/workato/extension/enumerable.rb +1 -0
  54. data/lib/workato/extension/extra_chain_cert.rb +1 -0
  55. data/lib/workato/extension/hash.rb +1 -0
  56. data/lib/workato/extension/integer.rb +1 -0
  57. data/lib/workato/extension/nil_class.rb +1 -0
  58. data/lib/workato/extension/object.rb +1 -0
  59. data/lib/workato/extension/phone.rb +1 -0
  60. data/lib/workato/extension/string.rb +2 -1
  61. data/lib/workato/extension/symbol.rb +1 -0
  62. data/lib/workato/extension/time.rb +1 -0
  63. data/lib/workato/testing/vcr_encrypted_cassette_serializer.rb +5 -0
  64. data/lib/workato/testing/vcr_multipart_body_matcher.rb +1 -0
  65. data/lib/workato/web/app.rb +1 -0
  66. data/lib/workato-connector-sdk.rb +1 -0
  67. metadata +64 -7
@@ -1,84 +1,109 @@
1
+ # typed: strict
1
2
  # frozen_string_literal: true
2
3
 
3
4
  module Workato
4
5
  module Connector
5
6
  module Sdk
7
+ module SorbetTypes
8
+ SourceHash = T.type_alias { T.any(HashWithIndifferentAccess, T::Hash[T.any(Symbol, String), T.untyped]) }
9
+ end
10
+
6
11
  class Connector
12
+ extend T::Sig
13
+
14
+ sig { returns(HashWithIndifferentAccess) }
7
15
  attr_reader :source
8
16
 
17
+ sig { params(path_to_source_code: String, settings: SorbetTypes::SettingsHash).returns(Connector) }
9
18
  def self.from_file(path_to_source_code = DEFAULT_CONNECTOR_PATH, settings = {})
10
19
  new(eval(File.read(path_to_source_code), binding, path_to_source_code), settings) # rubocop:disable Security/Eval
11
20
  end
12
21
 
22
+ sig { params(definition: SorbetTypes::SourceHash, settings: SorbetTypes::SettingsHash).void }
13
23
  def initialize(definition, settings = {})
14
- @source = definition.with_indifferent_access
15
- @settings = settings.with_indifferent_access
16
- @connection_source = @source[:connection] || {}
17
- @methods_source = @source[:methods] || {}
24
+ @source = T.let(definition.with_indifferent_access, HashWithIndifferentAccess)
25
+ @settings = T.let(settings.with_indifferent_access, HashWithIndifferentAccess)
26
+ @connection_source = T.let(@source[:connection] || {}.with_indifferent_access, HashWithIndifferentAccess)
27
+ @methods_source = T.let(@source[:methods] || {}.with_indifferent_access, HashWithIndifferentAccess)
18
28
  end
19
29
 
30
+ sig { params(path: String, params: T::Hash[Symbol, T.untyped]).returns(T.untyped) }
31
+ def invoke(path, params = {})
32
+ InvokePath.new(path: path, connector: self, params: params).call
33
+ end
34
+
35
+ sig { returns(T.nilable(String)) }
20
36
  def title
21
37
  @source[:title]
22
38
  end
23
39
 
40
+ sig { returns(ActionsProxy) }
24
41
  def actions
42
+ @actions = T.let(@actions, T.nilable(ActionsProxy))
25
43
  @actions ||= ActionsProxy.new(
26
44
  actions: source[:actions].presence || {},
27
45
  methods: methods_source,
28
46
  object_definitions: object_definitions,
29
- connection: connection,
30
- settings: settings
47
+ connection: connection
31
48
  )
32
49
  end
33
50
 
51
+ sig { returns(MethodsProxy) }
34
52
  def methods
53
+ @methods = T.let(@methods, T.nilable(MethodsProxy))
35
54
  @methods ||= MethodsProxy.new(
36
55
  methods: methods_source,
37
- connection: connection,
38
- settings: settings
56
+ connection: connection
39
57
  )
40
58
  end
41
59
 
60
+ sig { params(settings: T.nilable(SorbetTypes::SettingsHash)).returns(T.untyped) }
42
61
  def test(settings = nil)
62
+ @test = T.let(@test, T.nilable(Action))
43
63
  @test ||= Action.new(
44
64
  action: {
45
65
  execute: source[:test]
46
66
  },
47
67
  methods: methods_source,
48
- connection: connection,
49
- settings: send(:settings)
50
- ).execute(settings)
68
+ connection: connection
69
+ )
70
+ @test.execute(settings)
51
71
  end
52
72
 
73
+ sig { returns(TriggersProxy) }
53
74
  def triggers
75
+ @triggers = T.let(@triggers, T.nilable(TriggersProxy))
54
76
  @triggers ||= TriggersProxy.new(
55
77
  triggers: source[:triggers].presence || {},
56
78
  methods: methods_source,
57
79
  connection: connection,
58
- object_definitions: object_definitions,
59
- settings: settings
80
+ object_definitions: object_definitions
60
81
  )
61
82
  end
62
83
 
84
+ sig { returns(ObjectDefinitions) }
63
85
  def object_definitions
86
+ @object_definitions = T.let(@object_definitions, T.nilable(ObjectDefinitions))
64
87
  @object_definitions ||= ObjectDefinitions.new(
65
88
  object_definitions: source[:object_definitions].presence || {},
66
89
  methods: methods_source,
67
- connection: connection,
68
- settings: settings
90
+ connection: connection
69
91
  )
70
92
  end
71
93
 
94
+ sig { returns(PickListsProxy) }
72
95
  def pick_lists
96
+ @pick_lists = T.let(@pick_lists, T.nilable(PickListsProxy))
73
97
  @pick_lists ||= PickListsProxy.new(
74
98
  pick_lists: source[:pick_lists].presence || {},
75
99
  methods: methods_source,
76
- connection: connection,
77
- settings: settings
100
+ connection: connection
78
101
  )
79
102
  end
80
103
 
104
+ sig { returns(Connection) }
81
105
  def connection
106
+ @connection = T.let(@connection, T.nilable(Connection))
82
107
  @connection ||= Connection.new(
83
108
  methods: methods_source,
84
109
  connection: connection_source,
@@ -88,100 +113,139 @@ module Workato
88
113
 
89
114
  private
90
115
 
91
- attr_reader :methods_source,
92
- :connection_source,
93
- :settings
116
+ sig { returns(HashWithIndifferentAccess) }
117
+ attr_reader :methods_source
118
+
119
+ sig { returns(HashWithIndifferentAccess) }
120
+ attr_reader :connection_source
121
+
122
+ sig { returns(SorbetTypes::SettingsHash) }
123
+ attr_reader :settings
94
124
  end
95
125
 
96
126
  class ActionsProxy
97
- def initialize(actions:, object_definitions:, methods:, connection:, settings:)
127
+ extend T::Sig
128
+
129
+ sig do
130
+ params(
131
+ actions: HashWithIndifferentAccess,
132
+ object_definitions: ObjectDefinitions,
133
+ methods: HashWithIndifferentAccess,
134
+ connection: Connection
135
+ ).void
136
+ end
137
+ def initialize(actions:, object_definitions:, methods:, connection:)
98
138
  @methods = methods
99
139
  @connection = connection
100
140
  @object_definitions = object_definitions
101
- @settings = settings
141
+ @actions = T.let({}, T::Hash[T.any(Symbol, String), Action])
102
142
  define_action_methods(actions)
103
143
  end
104
144
 
145
+ sig { params(action: T.any(Symbol, String)).returns(T.untyped) }
105
146
  def [](action)
106
147
  public_send(action)
107
148
  end
108
149
 
109
150
  private
110
151
 
111
- attr_reader :methods,
112
- :connection,
113
- :object_definitions,
114
- :settings
152
+ sig { returns(HashWithIndifferentAccess) }
153
+ attr_reader :methods
154
+
155
+ sig { returns(Connection) }
156
+ attr_reader :connection
157
+
158
+ sig { returns(ObjectDefinitions) }
159
+ attr_reader :object_definitions
115
160
 
116
- def define_action_methods(actions)
117
- actions.each do |action, definition|
161
+ sig { params(actions_source: HashWithIndifferentAccess).void }
162
+ def define_action_methods(actions_source)
163
+ actions_source.each do |action, definition|
118
164
  define_singleton_method(action) do |input_ = nil|
119
- @actions ||= {}
120
165
  @actions[action] ||= Action.new(
121
166
  action: definition,
122
167
  object_definitions: object_definitions,
123
168
  methods: methods,
124
- connection: connection,
125
- settings: settings
169
+ connection: connection
126
170
  )
127
171
  return @actions[action] if input_.nil?
128
172
 
129
- @actions[action].invoke(input_)
173
+ T.must(@actions[action]).invoke(input_)
130
174
  end
131
175
  end
132
176
  end
133
177
  end
134
178
 
135
179
  class MethodsProxy
136
- def initialize(methods:, connection:, settings:)
180
+ extend T::Sig
181
+
182
+ sig do
183
+ params(
184
+ methods: HashWithIndifferentAccess,
185
+ connection: Connection
186
+ ).void
187
+ end
188
+ def initialize(methods:, connection:)
137
189
  @methods = methods
138
190
  @connection = connection
139
- @settings = settings
191
+ @actions = T.let({}, T::Hash[T.any(Symbol, String), Action])
140
192
  define_action_methods
141
193
  end
142
194
 
143
195
  private
144
196
 
145
- attr_reader :methods,
146
- :connection,
147
- :settings
197
+ sig { returns(HashWithIndifferentAccess) }
198
+ attr_reader :methods
199
+
200
+ sig { returns(Connection) }
201
+ attr_reader :connection
148
202
 
203
+ sig { void }
149
204
  def define_action_methods
150
205
  methods.each do |method, _definition|
151
206
  define_singleton_method(method) do |*args|
152
- @actions ||= {}
153
207
  @actions[method] ||= Action.new(
154
208
  action: {
155
- execute: -> { call(method, *args) }
209
+ execute: -> { T.unsafe(self).call(method, *args) }
156
210
  },
157
211
  methods: methods,
158
- connection: connection,
159
- settings: settings
212
+ connection: connection
160
213
  )
161
- @actions[method].execute
214
+ T.must(@actions[method]).execute
162
215
  end
163
216
  end
164
217
  end
165
218
  end
166
219
 
167
220
  class PickListsProxy
168
- def initialize(pick_lists:, methods:, connection:, settings:)
221
+ extend T::Sig
222
+
223
+ sig do
224
+ params(
225
+ pick_lists: HashWithIndifferentAccess,
226
+ methods: HashWithIndifferentAccess,
227
+ connection: Connection
228
+ ).void
229
+ end
230
+ def initialize(pick_lists:, methods:, connection:)
169
231
  @methods = methods
170
232
  @connection = connection
171
- @settings = settings
233
+ @actions = T.let({}, T::Hash[T.any(Symbol, String), Action])
172
234
  define_action_methods(pick_lists)
173
235
  end
174
236
 
175
237
  private
176
238
 
177
- attr_reader :methods,
178
- :connection,
179
- :settings
239
+ sig { returns(HashWithIndifferentAccess) }
240
+ attr_reader :methods
241
+
242
+ sig { returns(Connection) }
243
+ attr_reader :connection
180
244
 
181
- def define_action_methods(pick_lists)
182
- pick_lists.each do |pick_list, pick_list_proc|
245
+ sig { params(pick_lists_source: HashWithIndifferentAccess).void }
246
+ def define_action_methods(pick_lists_source)
247
+ pick_lists_source.each do |pick_list, pick_list_proc|
183
248
  define_singleton_method(pick_list) do |settings = nil, args = {}|
184
- @actions ||= {}
185
249
  @actions[pick_list] ||= Action.new(
186
250
  action: {
187
251
  execute: lambda do |connection, input|
@@ -196,50 +260,121 @@ module Workato
196
260
  end
197
261
  },
198
262
  methods: methods,
199
- connection: connection,
200
- settings: send(:settings)
263
+ connection: connection
201
264
  )
202
- @actions[pick_list].execute(settings, args)
265
+ T.must(@actions[pick_list]).execute(settings, args)
203
266
  end
204
267
  end
205
268
  end
206
269
  end
207
270
 
208
271
  class TriggersProxy
209
- def initialize(triggers:, object_definitions:, methods:, connection:, settings:)
272
+ extend T::Sig
273
+
274
+ sig do
275
+ params(
276
+ triggers: HashWithIndifferentAccess,
277
+ object_definitions: ObjectDefinitions,
278
+ methods: HashWithIndifferentAccess,
279
+ connection: Connection
280
+ ).void
281
+ end
282
+ def initialize(triggers:, object_definitions:, methods:, connection:)
210
283
  @methods = methods
211
284
  @connection = connection
212
285
  @object_definitions = object_definitions
213
- @settings = settings
214
- @triggers = {}
286
+ @triggers = T.let({}, T::Hash[T.any(Symbol, String), Trigger])
215
287
  define_trigger_methods(triggers)
216
288
  end
217
289
 
218
290
  private
219
291
 
220
- attr_reader :methods,
221
- :connection,
222
- :object_definitions,
223
- :settings
292
+ sig { returns(HashWithIndifferentAccess) }
293
+ attr_reader :methods
224
294
 
225
- def define_trigger_methods(triggers)
226
- triggers.each do |trigger, definition|
295
+ sig { returns(Connection) }
296
+ attr_reader :connection
297
+
298
+ sig { returns(ObjectDefinitions) }
299
+ attr_reader :object_definitions
300
+
301
+ sig { params(triggers_source: HashWithIndifferentAccess).void }
302
+ def define_trigger_methods(triggers_source)
303
+ triggers_source.each do |trigger, definition|
227
304
  define_singleton_method(trigger) do |input_ = nil, payload = {}, headers = {}, params = {}|
228
305
  @triggers[trigger] ||= Trigger.new(
229
306
  trigger: definition,
230
307
  object_definitions: object_definitions,
231
308
  methods: methods,
232
- connection: connection,
233
- settings: settings
309
+ connection: connection
234
310
  )
235
311
 
236
312
  return @triggers[trigger] if input_.nil?
237
313
 
238
- @triggers[trigger].invoke(input_, payload, headers, params)
314
+ T.must(@triggers[trigger]).invoke(input_, payload, headers, params)
239
315
  end
240
316
  end
241
317
  end
242
318
  end
319
+
320
+ class InvokePath
321
+ extend T::Sig
322
+
323
+ sig do
324
+ params(
325
+ path: String,
326
+ connector: Connector,
327
+ params: T::Hash[Symbol, T.untyped]
328
+ ).void
329
+ end
330
+ def initialize(path:, connector:, params:)
331
+ @path = T.let(path, String)
332
+ @connector = T.let(connector, Connector)
333
+ @params = T.let(params, T::Hash[Symbol, T.untyped])
334
+ end
335
+
336
+ sig { returns(T.untyped) }
337
+ def call
338
+ invoke_path
339
+ end
340
+
341
+ private
342
+
343
+ sig { returns(String) }
344
+ attr_reader :path
345
+
346
+ sig { returns(Connector) }
347
+ attr_reader :connector
348
+
349
+ sig { returns(T::Hash[Symbol, T.untyped]) }
350
+ attr_reader :params
351
+
352
+ sig { returns(T.untyped) }
353
+ def invoke_path
354
+ methods = path.split('.')
355
+ method = methods.pop
356
+ raise ArgumentError, 'path is not found' unless method
357
+
358
+ object = methods.inject(connector) { |obj, m| obj.public_send(m) }
359
+ output = invoke_method(object, method)
360
+ if output.respond_to?(:invoke)
361
+ invoke_method(output, :invoke)
362
+ else
363
+ output
364
+ end
365
+ end
366
+
367
+ sig { params(object: T.untyped, method: T.any(Symbol, String)).returns(T.untyped) }
368
+ def invoke_method(object, method)
369
+ parameters = object.method(method).parameters.reject { |p| p[0] == :block }.map(&:second)
370
+ args = params.values_at(*parameters)
371
+ if parameters.last == :args
372
+ args = args.take(args.length - 1) + Array.wrap(args.last).flatten(1)
373
+ end
374
+ object.public_send(method, *args)
375
+ end
376
+ end
377
+ private_constant :InvokePath
243
378
  end
244
379
  end
245
380
  end
@@ -1,3 +1,4 @@
1
+ # typed: true
1
2
  # frozen_string_literal: true
2
3
 
3
4
  module Workato
@@ -1,3 +1,4 @@
1
+ # typed: false
1
2
  # frozen_string_literal: true
2
3
 
3
4
  require 'aws-sigv4'
@@ -19,10 +20,14 @@ module Workato
19
20
  WWW_FORM_CONTENT_TYPE = 'application/x-www-form-urlencoded; charset=utf-8'
20
21
 
21
22
  def aws
22
- AWS
23
+ @aws ||= Private.new(connection: connection)
23
24
  end
24
25
 
25
- class << self
26
+ class Private
27
+ def initialize(connection:)
28
+ @connection = connection
29
+ end
30
+
26
31
  def generate_signature(connection:,
27
32
  service:,
28
33
  region:,
@@ -61,27 +66,25 @@ module Workato
61
66
  end
62
67
 
63
68
  def iam_external_id
64
- settings[:aws_external_id] || DUMMY_AWS_IAM_EXTERNAL_ID
69
+ @connection.settings[:aws_external_id] || DUMMY_AWS_IAM_EXTERNAL_ID
65
70
  end
66
71
 
67
72
  def workato_account_id
68
- settings[:aws_workato_account_id] || AMAZON_ROLE_CLIENT_ID || DUMMY_AWS_WORKATO_ACCOUNT_ID
73
+ @connection.settings[:aws_workato_account_id] || AMAZON_ROLE_CLIENT_ID || DUMMY_AWS_WORKATO_ACCOUNT_ID
69
74
  end
70
75
 
71
76
  private
72
77
 
73
- def on_settings_updated
74
- Workato::Connector::Sdk::Operation.on_settings_updated
75
- end
76
-
77
78
  def role_based_auth(settings:)
78
- settings[:aws_external_id] ||= iam_external_id
79
- temp_credentials = settings[:temp_credentials] || {}
79
+ temp_credentials = settings[:temp_credentials] || @connection.settings[:temp_credentials] || {}
80
80
 
81
81
  # Refresh temp token that will expire within 60 seconds.
82
82
  expiration = temp_credentials[:expiration]&.to_time(:utc)
83
83
  if !expiration || expiration <= TEMP_CREDENTIALS_REFRESH_TIMEOUT.seconds.from_now
84
- temp_credentials = refresh_temp_credentials(settings)
84
+ @connection.update_settings!('Refresh AWS temporary credentials') do
85
+ { temp_credentials: refresh_temp_credentials(settings) }
86
+ end
87
+ temp_credentials = @connection.settings[:temp_credentials]
85
88
  end
86
89
  {
87
90
  access_key_id: temp_credentials[:api_key],
@@ -91,6 +94,7 @@ module Workato
91
94
  end
92
95
 
93
96
  def refresh_temp_credentials(settings)
97
+ aws_external_id = settings[:aws_external_id] || iam_external_id
94
98
  sts_credentials = {
95
99
  access_key_id: amazon_role_client_key(settings),
96
100
  secret_access_key: amazon_role_client_secret(settings)
@@ -101,7 +105,7 @@ module Workato
101
105
  'Action' => 'AssumeRole',
102
106
  'RoleSessionName' => 'workato',
103
107
  'RoleArn' => settings[:aws_assume_role],
104
- 'ExternalId' => settings[:aws_external_id].presence
108
+ 'ExternalId' => aws_external_id.presence
105
109
  }.compact
106
110
 
107
111
  sts_auth_url, sts_auth_headers = create_signature(
@@ -116,24 +120,14 @@ module Workato
116
120
  }
117
121
  )
118
122
 
119
- request_temp_credentials(url: sts_auth_url, headers: sts_auth_headers).tap do |temp_credentials|
120
- update_settings(settings, temp_credentials)
121
- end
123
+ request_temp_credentials(url: sts_auth_url, headers: sts_auth_headers)
122
124
  rescue StandardError => e
123
- raise e if settings[:aws_external_id].blank?
125
+ raise e if aws_external_id.blank?
124
126
 
125
- settings[:aws_external_id] = nil
127
+ aws_external_id = nil
126
128
  retry
127
129
  end
128
130
 
129
- def update_settings(settings, temp_credentials)
130
- settings.merge!(temp_credentials: temp_credentials)
131
- Workato::Connector::Sdk::Operation.on_settings_updated&.call(
132
- 'Refresh AWS temporary credentials',
133
- settings
134
- )
135
- end
136
-
137
131
  def request_temp_credentials(url:, headers:)
138
132
  response = RestClient::Request.execute(
139
133
  url: url,
@@ -213,13 +207,15 @@ module Workato
213
207
  end
214
208
 
215
209
  def amazon_role_client_key(settings)
216
- settings[:access_key_id] || AMAZON_ROLE_CLIENT_KEY
210
+ settings[:access_key_id] || @connection.settings[:access_key_id] || AMAZON_ROLE_CLIENT_KEY
217
211
  end
218
212
 
219
213
  def amazon_role_client_secret(settings)
220
- settings[:secret_access_key] || AMAZON_ROLE_CLIENT_SECRET
214
+ settings[:secret_access_key] || @connection.settings[:access_key_id] || AMAZON_ROLE_CLIENT_SECRET
221
215
  end
222
216
  end
217
+
218
+ private_constant :Private
223
219
  end
224
220
  end
225
221
  end
@@ -1,3 +1,4 @@
1
+ # typed: false
1
2
  # frozen_string_literal: true
2
3
 
3
4
  module Workato
@@ -1,3 +1,4 @@
1
+ # typed: false
1
2
  # frozen_string_literal: true
2
3
 
3
4
  module Workato
@@ -1,3 +1,4 @@
1
+ # typed: false
1
2
  # frozen_string_literal: true
2
3
 
3
4
  module Workato
@@ -64,13 +65,7 @@ module Workato
64
65
  private
65
66
 
66
67
  def http_request(url, method:)
67
- Request.new(
68
- url,
69
- method: method,
70
- connection: connection,
71
- settings: settings,
72
- action: self
73
- )
68
+ Request.new(url, method: method, connection: connection, action: self)
74
69
  end
75
70
  end
76
71
  end
@@ -1,3 +1,4 @@
1
+ # typed: false
1
2
  # frozen_string_literal: true
2
3
 
3
4
  module Workato
@@ -1,3 +1,4 @@
1
+ # typed: true
1
2
  # frozen_string_literal: true
2
3
 
3
4
  module Workato
@@ -19,6 +20,11 @@ module Workato
19
20
  end
20
21
 
21
22
  begin
23
+ if ENV['TZ'].present? && ENV['TZ'] != 'UTC'
24
+ warn "WARNING: TZ environment variable is set to '#{ENV['TZ']}'. Set TZ=UTC for consistency with Workato platform'"
25
+ else
26
+ ENV['TZ'] = 'UTC'
27
+ end
22
28
  ::Time.zone = Workato::Connector::Sdk::DEFAULT_TIME_ZONE
23
29
  rescue TZInfo::DataSourceNotFound
24
30
  puts ''
@@ -1,3 +1,4 @@
1
+ # typed: true
1
2
  # frozen_string_literal: true
2
3
 
3
4
  require 'jwt'
@@ -20,6 +21,43 @@ module Workato
20
21
  WorkatoCodeLib.parse_json(source)
21
22
  end
22
23
 
24
+ def uuid
25
+ WorkatoCodeLib.uuid
26
+ end
27
+
28
+ def encrypt(text, key)
29
+ ::Kernel.require('ruby_rncryptor')
30
+
31
+ enc_text = ::RubyRNCryptor.encrypt(text, key)
32
+ ::Base64.strict_encode64(enc_text)
33
+ end
34
+
35
+ def decrypt(text, key)
36
+ ::Kernel.require('ruby_rncryptor')
37
+
38
+ text = ::Base64.decode64(text)
39
+ dec_text = ::RubyRNCryptor.decrypt(text, key)
40
+ Workato::Extension::Binary.new(dec_text)
41
+ rescue Exception => e # rubocop:disable Lint/RescueException
42
+ message = e.message.to_s
43
+ case message
44
+ when /Password may be incorrect/
45
+ ::Kernel.raise 'invalid/corrupt input or key'
46
+ when /RubyRNCryptor only decrypts version/
47
+ ::Kernel.raise 'invalid/corrupt input'
48
+ else
49
+ ::Kernel.raise
50
+ end
51
+ end
52
+
53
+ def blank; end
54
+
55
+ def clear; end
56
+
57
+ def null; end
58
+
59
+ def skip; end
60
+
23
61
  class << self
24
62
  def jwt_encode_rs256(payload, key, header_fields = {})
25
63
  jwt_encode(payload, key, 'RS256', header_fields)
@@ -1,3 +1,4 @@
1
+ # typed: true
1
2
  # frozen_string_literal: true
2
3
 
3
4
  module Workato