multiwoven-integrations 0.43.19 → 0.43.20

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: 6f1d04785fddebfa991dd51a59d5d0e2bf077834c124f569a94f663db3ded89b
4
- data.tar.gz: 51b1ab19b08c3861ac1ad273a12eae0be13b66650c49eca1ab5b19f769f2fa41
3
+ metadata.gz: 4231f030657418d5419eb934b7566febb75aead2a788d0285fc89ef3c34d6565
4
+ data.tar.gz: 31abffe8ded34c03a6fadbf281e5c1a8aeec23619c264c7ccdb3e0e8eb7cc42f
5
5
  SHA512:
6
- metadata.gz: df73714fa26b4a8476df6cca4b4a0946c4e3b2866c619fa61e8a576f1a7793caeee354e9c59c065ee7052d50dc0e6eebb01ea963a1bc4238e44660dd11273eb6
7
- data.tar.gz: e04c8ada1b22612fc40cfd3baa845bf1ad652e394e4f4d9f988f1b1a37b0e15ad98f389497abbd68f17ef396ceffe07c805778b3eab306107b2d0141a626df90
6
+ metadata.gz: 81a2b59d525ee8f769413e1398c29e3fd4730e6dfd12e57e03cdcc60a09fa851a0d8b5565ac0d43f5e9b36a474cc64678456d4ce26e590d83e1e70cdedb4d82a
7
+ data.tar.gz: 6b6ea6e6add4e1cd14aeb7ea3c9389aea78b930d11dd962a034ddf2db6d3d3e3c2e916010a659274f9c31803cd69e2aec31f73f9985e308ca962944c97d40b75
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ### [0.43.20]
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * Mark missing secret fields with `multiwoven_secret: true` across connector `spec.json` schemas (`token` in Microsoft Excel, `headers` in HTTP source/destination/model, AWS `access_key_id`/`access_key`/`access_id`/`external_id`, Snowflake `jdbc_url_params`, BigQuery and Google Vertex `credentials_json.private_key_id` and `client_id`)
9
+ * Stop persisting live OAuth access tokens into `connector.configuration` in `OauthClientCredentials`, Microsoft Dynamics, and OneDrive connectors; cache tokens outside connector records using per-connector, credential-hashed cache keys
10
+
3
11
  ### [0.43.19]
4
12
 
5
13
 
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Multiwoven
4
+ module Integrations::Core
5
+ module AccessTokenCache
6
+ TOKEN_EXPIRY_BUFFER_SECONDS = 300
7
+ DEFAULT_TOKEN_TTL_SECONDS = 3600
8
+
9
+ def self.key(prefix, material)
10
+ "#{prefix}:#{Digest::SHA256.hexdigest(JSON.generate(material))}"
11
+ end
12
+
13
+ def self.lifetime(expires_in)
14
+ expires_in.nil? || expires_in.to_s.strip.empty? ? DEFAULT_TOKEN_TTL_SECONDS : expires_in.to_i
15
+ end
16
+
17
+ def self.ttl(expires_in)
18
+ lifetime(expires_in) - TOKEN_EXPIRY_BUFFER_SECONDS
19
+ end
20
+
21
+ def self.connector_identifier(connector_instance)
22
+ return connector_instance.id.to_s if connector_instance.respond_to?(:id) && !connector_instance.id.nil?
23
+
24
+ "obj:#{connector_instance.object_id}"
25
+ end
26
+
27
+ private
28
+
29
+ def cached_access_token
30
+ return nil unless @connector_instance
31
+
32
+ TokenCache.store.read(access_token_cache_key)
33
+ end
34
+
35
+ def cache_access_token(token, expires_in)
36
+ return unless @connector_instance
37
+
38
+ ttl = AccessTokenCache.ttl(expires_in)
39
+ return if token.to_s.empty? || ttl <= 0
40
+
41
+ TokenCache.store.write(access_token_cache_key, token, expires_in: ttl)
42
+ end
43
+
44
+ def access_token_cache_key
45
+ AccessTokenCache.key(self.class::TOKEN_CACHE_PREFIX,
46
+ [AccessTokenCache.connector_identifier(@connector_instance), *access_token_cache_material])
47
+ end
48
+ end
49
+ end
50
+ end
@@ -6,20 +6,6 @@ require "securerandom"
6
6
 
7
7
  module Multiwoven
8
8
  module Integrations::Core
9
- # Shared OAuth2 client_credentials flows. Include in a connector client to:
10
- # * inject `Authorization: Bearer <token>` when connection_config[:auth_type]
11
- # is `oauth_client_credentials` or `oauth_private_key_jwt`
12
- # * cache the token in the connector's `configuration` JSON and refresh it
13
- # shortly before expiry
14
- #
15
- # `oauth_client_credentials` — classic client_id + client_secret.
16
- # `oauth_private_key_jwt` — client_assertion JWT signed with an RSA private
17
- # key (Epic Backend Services / SMART confidential asymmetric).
18
- #
19
- # The including class is expected to set `@connector_instance` (an object
20
- # responding to `configuration` and `update!`) before making requests that
21
- # should benefit from the cache. Without it, a fresh token is fetched every
22
- # call — safe but wasteful.
23
9
  module OauthClientCredentials
24
10
  class OauthTokenRequestError < RuntimeError; end
25
11
 
@@ -28,14 +14,13 @@ module Multiwoven
28
14
  OAUTH_AUTH_TYPES = [AUTH_TYPE_OAUTH_CLIENT_CREDENTIALS, AUTH_TYPE_PRIVATE_KEY_JWT].freeze
29
15
 
30
16
  CLIENT_ASSERTION_TYPE = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer"
31
- # Epic / SMART Backend Services require RS384; RS256 is kept for other IdPs.
32
17
  DEFAULT_JWT_ALGORITHM = "RS384"
33
18
  ALLOWED_JWT_ALGORITHMS = %w[RS384 RS256].freeze
34
19
  JWT_ASSERTION_LIFETIME_SECONDS = 300
35
- # Refresh access tokens this many seconds before their advertised expiry,
36
- # so a token that expires mid-request doesn't leave the connector.
37
- TOKEN_EXPIRY_BUFFER_SECONDS = 300
20
+ HTTP_OPEN_TIMEOUT = 10
21
+ HTTP_READ_TIMEOUT = 30
38
22
  TRANSIENT_HTTP_STATUSES = %w[408 429].freeze
23
+ TOKEN_CACHE_PREFIX = "multiwoven:oauth_client_credentials:v1"
39
24
 
40
25
  def build_headers(connection_config)
41
26
  headers = (connection_config[:headers] || {}).to_h.dup
@@ -46,7 +31,7 @@ module Multiwoven
46
31
  end
47
32
 
48
33
  def ensure_oauth_token(connection_config)
49
- cached = cached_oauth_token
34
+ cached = cached_oauth_token(connection_config)
50
35
  return cached if cached
51
36
 
52
37
  fetch_and_cache_oauth_token(connection_config)
@@ -58,14 +43,16 @@ module Multiwoven
58
43
  OAUTH_AUTH_TYPES.include?(auth_type)
59
44
  end
60
45
 
61
- def cached_oauth_token
62
- config = connector_configuration
63
- return nil unless config
46
+ def cached_oauth_token(connection_config)
47
+ return nil unless @connector_instance
64
48
 
65
- token = config["oauth_access_token"]
66
- expires_at = config["oauth_expires_at"]
67
- return nil if token.nil? || token.to_s.empty? || expires_at.nil?
68
- return nil if Time.parse(expires_at.to_s) <= Time.now + TOKEN_EXPIRY_BUFFER_SECONDS
49
+ entry = oauth_token_cache.read(oauth_token_cache_key(connection_config))
50
+ return nil unless entry.is_a?(Hash)
51
+
52
+ token = entry["access_token"]
53
+ expires_at = entry["expires_at"]
54
+ return nil if token.to_s.empty? || expires_at.nil?
55
+ return nil if Time.at(Integer(expires_at)) <= Time.now + AccessTokenCache::TOKEN_EXPIRY_BUFFER_SECONDS
69
56
 
70
57
  token
71
58
  rescue ArgumentError, TypeError
@@ -85,8 +72,7 @@ module Multiwoven
85
72
  access_token = body["access_token"]
86
73
  raise "OAuth token response missing 'access_token'" if access_token.to_s.empty?
87
74
 
88
- expires_in = (body["expires_in"] || 3600).to_i
89
- persist_oauth_token(access_token, Time.now + expires_in)
75
+ cache_oauth_token(connection_config, access_token, body["expires_in"])
90
76
  access_token
91
77
  end
92
78
 
@@ -223,6 +209,8 @@ module Multiwoven
223
209
  http = Net::HTTP.new(uri.host, uri.port)
224
210
  http.ipaddr = pinned_address if pinned_address
225
211
  http.use_ssl = (uri.scheme == "https")
212
+ http.open_timeout = HTTP_OPEN_TIMEOUT
213
+ http.read_timeout = HTTP_READ_TIMEOUT
226
214
 
227
215
  request = Net::HTTP::Post.new(uri)
228
216
  request["Content-Type"] = "application/x-www-form-urlencoded"
@@ -230,22 +218,30 @@ module Multiwoven
230
218
  http.request(request)
231
219
  end
232
220
 
233
- def persist_oauth_token(access_token, expires_at)
234
- return unless @connector_instance.respond_to?(:update!)
221
+ def cache_oauth_token(connection_config, access_token, expires_in)
222
+ return unless @connector_instance
223
+
224
+ lifetime = AccessTokenCache.lifetime(expires_in)
225
+ ttl = lifetime - AccessTokenCache::TOKEN_EXPIRY_BUFFER_SECONDS
226
+ return if access_token.to_s.empty? || ttl <= 0
235
227
 
236
- base = connector_configuration || {}
237
- new_config = base.merge(
238
- "oauth_access_token" => access_token,
239
- "oauth_expires_at" => expires_at.iso8601
228
+ oauth_token_cache.write(
229
+ oauth_token_cache_key(connection_config),
230
+ { "access_token" => access_token, "expires_at" => Time.now.to_i + lifetime },
231
+ expires_in: ttl
240
232
  )
241
- @connector_instance.update!(configuration: new_config)
242
233
  end
243
234
 
244
- def connector_configuration
245
- return nil unless @connector_instance.respond_to?(:configuration)
235
+ def oauth_token_cache
236
+ TokenCache.store
237
+ end
246
238
 
247
- cfg = @connector_instance.configuration
248
- cfg.is_a?(Hash) ? cfg : nil
239
+ def oauth_token_cache_key(connection_config)
240
+ AccessTokenCache.key(TOKEN_CACHE_PREFIX, [
241
+ AccessTokenCache.connector_identifier(@connector_instance),
242
+ *connection_config.values_at(:auth_type, :token_url, :client_id, :client_secret,
243
+ :private_key, :kid, :algorithm, :audience, :scope).map(&:to_s)
244
+ ])
249
245
  end
250
246
  end
251
247
  end
@@ -9,6 +9,7 @@
9
9
  "access_key_id": {
10
10
  "description": "The AWS Access Key ID to use for authentication.",
11
11
  "type": "string",
12
+ "multiwoven_secret": true,
12
13
  "title": "Personal Access Key",
13
14
  "order": 0
14
15
  },
@@ -22,6 +22,7 @@
22
22
  },
23
23
  "headers": {
24
24
  "title": "Http Headers",
25
+ "multiwoven_secret": true,
25
26
  "order": 1,
26
27
  "additionalProperties": {
27
28
  "type": "string"
@@ -11,6 +11,7 @@
11
11
  "token": {
12
12
  "description": "Token from Microsoft Graph.",
13
13
  "type": "string",
14
+ "multiwoven_secret": true,
14
15
  "title": "Token",
15
16
  "order": 0
16
17
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Multiwoven
4
4
  module Integrations
5
- VERSION = "0.43.19"
5
+ VERSION = "0.43.20"
6
6
 
7
7
  ENABLED_SOURCES = %w[
8
8
  Snowflake
@@ -67,11 +67,13 @@
67
67
  "type": "string",
68
68
  "title": "External Id",
69
69
  "description": "Unique ID that allows handshake between AWS accounts.",
70
+ "multiwoven_secret": true,
70
71
  "order": 2
71
72
  },
72
73
  "access_id": {
73
74
  "type": "string",
74
75
  "title": "Access Id",
76
+ "multiwoven_secret": true,
75
77
  "order": 3
76
78
  },
77
79
  "secret_access": {
@@ -12,6 +12,7 @@
12
12
  "description": "The AWS Access Key ID to use for authentication.",
13
13
  "examples": ["AWSATHENAACCESS"],
14
14
  "type": "string",
15
+ "multiwoven_secret": true,
15
16
  "title": "Personal Access Key",
16
17
  "order": 0
17
18
  },
@@ -13,6 +13,7 @@
13
13
  "access_key": {
14
14
  "description": "The AWS Access Key ID to use for authentication",
15
15
  "type": "string",
16
+ "multiwoven_secret": true,
16
17
  "title": "Personal Access Key",
17
18
  "order": 0
18
19
  },
@@ -11,6 +11,7 @@
11
11
  "access_key": {
12
12
  "description": "The AWS Access Key ID to use for authentication",
13
13
  "type": "string",
14
+ "multiwoven_secret": true,
14
15
  "title": "Personal Access Key",
15
16
  "order": 0
16
17
  },
@@ -31,7 +31,8 @@
31
31
  "type": "string"
32
32
  },
33
33
  "private_key_id": {
34
- "type": "string"
34
+ "type": "string",
35
+ "multiwoven_secret": true
35
36
  },
36
37
  "private_key": {
37
38
  "type": "string",
@@ -42,7 +43,8 @@
42
43
  "format": "email"
43
44
  },
44
45
  "client_id": {
45
- "type": "string"
46
+ "type": "string",
47
+ "multiwoven_secret": true
46
48
  },
47
49
  "auth_uri": {
48
50
  "type": "string",
@@ -53,7 +53,8 @@
53
53
  "type": "string"
54
54
  },
55
55
  "private_key_id": {
56
- "type": "string"
56
+ "type": "string",
57
+ "multiwoven_secret": true
57
58
  },
58
59
  "private_key": {
59
60
  "type": "string",
@@ -64,7 +65,8 @@
64
65
  "format": "email"
65
66
  },
66
67
  "client_id": {
67
- "type": "string"
68
+ "type": "string",
69
+ "multiwoven_secret": true
68
70
  },
69
71
  "auth_uri": {
70
72
  "type": "string",
@@ -44,6 +44,7 @@
44
44
  "headers": {
45
45
  "title": "HTTP Headers",
46
46
  "description": "Custom headers to include in the HTTP request. Useful for authentication, content type specifications, and other request metadata.",
47
+ "multiwoven_secret": true,
47
48
  "order": 4,
48
49
  "additionalProperties": {
49
50
  "type": "string"
@@ -29,6 +29,7 @@
29
29
  "headers": {
30
30
  "title": "HTTP Headers",
31
31
  "description": "Custom headers to include in the HTTP request. Useful for authentication, content type specifications, and other request metadata.",
32
+ "multiwoven_secret": true,
32
33
  "order": 3,
33
34
  "additionalProperties": {
34
35
  "type": "string"
@@ -17,8 +17,13 @@ module Multiwoven::Integrations::Source
17
17
  }.freeze
18
18
 
19
19
  class Client < SourceConnector
20
+ include Multiwoven::Integrations::Core::AccessTokenCache
21
+
22
+ TOKEN_CACHE_PREFIX = "multiwoven:source:microsoft_dynamics:v1"
23
+
20
24
  def check_connection(connection_config)
21
25
  connection_config = connection_config.with_indifferent_access
26
+ @connector_instance = nil
22
27
  create_connection(connection_config)
23
28
  response = dynamics_request(whoami_url)
24
29
  response_body = JSON.parse(response.body)
@@ -38,6 +43,7 @@ module Multiwoven::Integrations::Source
38
43
 
39
44
  def discover(connection_config)
40
45
  connection_config = connection_config.with_indifferent_access
46
+ @connector_instance = nil
41
47
  create_connection(connection_config)
42
48
 
43
49
  streams = DYNAMICS_OBJECTS.filter_map do |entity|
@@ -86,22 +92,17 @@ module Multiwoven::Integrations::Source
86
92
  @client_id = connection_config[:application_id]
87
93
  @instance_url = connection_config[:instance_url]
88
94
  @client_secret = connection_config[:client_secret]
89
- stored_token = @connector_instance&.configuration&.dig("access_token")
90
- @access_token = stored_token.presence || refresh_access_token
95
+ @access_token = cached_access_token.presence || refresh_access_token
91
96
  end
92
97
 
93
98
  def refresh_access_token
94
99
  @access_token = fetch_access_token
95
- persist_access_token(@access_token)
100
+ cache_access_token(@access_token, @token_expires_in)
96
101
  @access_token
97
102
  end
98
103
 
99
- def persist_access_token(token)
100
- return unless @connector_instance&.configuration
101
-
102
- config = @connector_instance.configuration
103
- config = {} unless config.is_a?(Hash)
104
- @connector_instance.update!(configuration: config.merge("access_token" => token))
104
+ def access_token_cache_material
105
+ [@instance_url.to_s, @tenant_id.to_s, @client_id.to_s, @client_secret.to_s]
105
106
  end
106
107
 
107
108
  def fetch_access_token
@@ -120,7 +121,9 @@ module Multiwoven::Integrations::Source
120
121
  )
121
122
  raise dynamics_api_error(response.body) unless success?(response)
122
123
 
123
- JSON.parse(response.body)["access_token"]
124
+ parsed = JSON.parse(response.body)
125
+ @token_expires_in = parsed["expires_in"]
126
+ parsed["access_token"]
124
127
  end
125
128
 
126
129
  def query(_connection, sql_query)
@@ -4,15 +4,17 @@ module Multiwoven::Integrations::Source
4
4
  module OneDrive
5
5
  include Multiwoven::Integrations::Core
6
6
  class Client < UnstructuredSourceConnector
7
+ include Multiwoven::Integrations::Core::AccessTokenCache
8
+
7
9
  EXCEL_EXTENSIONS = %w[.xlsx .xls .xlsm].freeze
8
10
  SPREADSHEET_EXTENSIONS = [".csv", *EXCEL_EXTENSIONS].freeze
9
11
  EXPIRED_ACCESS_TOKEN_ERROR_CODE = "InvalidAuthenticationToken"
10
- # Matches list_files / SHOW TABLES with optional LIMIT/OFFSET appended by
11
- # Connector#execute_query or SourceConnector#batched_query.
12
+ TOKEN_CACHE_PREFIX = "multiwoven:source:one_drive:v1"
12
13
  LIST_TABLES_QUERY = /\A\s*(?:list_files|show\s+tables)\s*(?:limit\s+(\d+))?\s*(?:offset\s+(\d+))?\s*;?\s*\z/i.freeze
13
14
 
14
15
  def check_connection(connection_config)
15
16
  connection_config = connection_config.with_indifferent_access
17
+ @connector_instance = nil
16
18
  create_connection(connection_config)
17
19
  if unstructured_data?(connection_config)
18
20
  fetch_list_items
@@ -35,6 +37,7 @@ module Multiwoven::Integrations::Source
35
37
 
36
38
  def discover(connection_config)
37
39
  connection_config = connection_config.with_indifferent_access
40
+ @connector_instance = nil
38
41
 
39
42
  streams = if unstructured_data?(connection_config)
40
43
  [create_unstructured_stream]
@@ -86,8 +89,7 @@ module Multiwoven::Integrations::Source
86
89
  @file_name = connection_config[:file_name]
87
90
  @share_url = connection_config[:share_url]
88
91
  @is_recursive = [true, "true"].include?(connection_config[:is_recursive])
89
- stored_token = @connector_instance&.configuration&.dig("access_token")
90
- @access_token = stored_token.presence || refresh_access_token
92
+ @access_token = cached_access_token.presence || refresh_access_token
91
93
  end
92
94
 
93
95
  def create_connection(connection_config)
@@ -109,16 +111,12 @@ module Multiwoven::Integrations::Source
109
111
 
110
112
  def refresh_access_token
111
113
  @access_token = fetch_access_token
112
- persist_access_token(@access_token)
114
+ cache_access_token(@access_token, @token_expires_in)
113
115
  @access_token
114
116
  end
115
117
 
116
- def persist_access_token(token)
117
- return unless @connector_instance&.configuration
118
-
119
- config = @connector_instance.configuration
120
- config = {} unless config.is_a?(Hash)
121
- @connector_instance.update!(configuration: config.merge("access_token" => token))
118
+ def access_token_cache_material
119
+ [@tenant_id.to_s, @client_id.to_s, @client_secret.to_s]
122
120
  end
123
121
 
124
122
  def microsoft_graph_request(url)
@@ -153,7 +151,9 @@ module Multiwoven::Integrations::Source
153
151
  )
154
152
  raise graph_api_error(response.body) unless success?(response)
155
153
 
156
- JSON.parse(response.body)["access_token"]
154
+ parsed = JSON.parse(response.body)
155
+ @token_expires_in = parsed["expires_in"]
156
+ parsed["access_token"]
157
157
  end
158
158
 
159
159
  def handle_unstructured_data(sync_config)
@@ -75,6 +75,7 @@
75
75
  "description": "Additional properties to pass to the JDBC URL string when connecting to the database formatted as 'key=value' pairs separated by the symbol '&'. (example: key1=value1&key2=value2&key3=value3).",
76
76
  "title": "JDBC URL Params",
77
77
  "type": "string",
78
+ "multiwoven_secret": true,
78
79
  "order": 6
79
80
  }
80
81
  }
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "json"
4
4
  require "digest"
5
+ require "time"
5
6
  require "dry-struct"
6
7
  require "dry-schema"
7
8
  require "dry-types"
@@ -72,8 +73,9 @@ require_relative "integrations/core/http_helper"
72
73
  require_relative "integrations/core/http_client"
73
74
  require_relative "integrations/core/pinecone_client"
74
75
  require_relative "integrations/core/open_router_catalog"
75
- require_relative "integrations/core/oauth_client_credentials"
76
76
  require_relative "integrations/core/token_cache"
77
+ require_relative "integrations/core/access_token_cache"
78
+ require_relative "integrations/core/oauth_client_credentials"
77
79
  require_relative "integrations/core/streaming_http_client"
78
80
  require_relative "integrations/core/query_builder"
79
81
  require_relative "integrations/core/unstructured_source_connector"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multiwoven-integrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.43.19
4
+ version: 0.43.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Subin T P
@@ -630,6 +630,7 @@ files:
630
630
  - Rakefile
631
631
  - lib/multiwoven/integrations.rb
632
632
  - lib/multiwoven/integrations/config.rb
633
+ - lib/multiwoven/integrations/core/access_token_cache.rb
633
634
  - lib/multiwoven/integrations/core/base_connector.rb
634
635
  - lib/multiwoven/integrations/core/connection_check_errors.rb
635
636
  - lib/multiwoven/integrations/core/constants.rb