connectors_sdk 8.3.0.0.pre.20220414T060419Z → 8.3.0.0.pre.20220510T144908Z

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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/lib/connectors_sdk/atlassian/config.rb +27 -0
  3. data/lib/connectors_sdk/atlassian/custom_client.rb +87 -0
  4. data/lib/connectors_sdk/base/adapter.rb +7 -8
  5. data/lib/connectors_sdk/base/authorization.rb +89 -0
  6. data/lib/connectors_sdk/base/custom_client.rb +0 -1
  7. data/lib/connectors_sdk/base/extractor.rb +3 -2
  8. data/lib/connectors_sdk/base/http_call_wrapper.rb +135 -0
  9. data/lib/connectors_sdk/base/registry.rb +5 -3
  10. data/lib/connectors_sdk/confluence/adapter.rb +216 -0
  11. data/lib/connectors_sdk/confluence/custom_client.rb +143 -0
  12. data/lib/connectors_sdk/confluence/extractor.rb +270 -0
  13. data/lib/connectors_sdk/confluence_cloud/authorization.rb +64 -0
  14. data/lib/connectors_sdk/confluence_cloud/custom_client.rb +61 -0
  15. data/lib/connectors_sdk/confluence_cloud/extractor.rb +59 -0
  16. data/lib/connectors_sdk/confluence_cloud/http_call_wrapper.rb +59 -0
  17. data/lib/connectors_sdk/helpers/atlassian_time_formatter.rb +10 -0
  18. data/lib/connectors_sdk/office365/adapter.rb +7 -7
  19. data/lib/connectors_sdk/office365/config.rb +1 -0
  20. data/lib/connectors_sdk/office365/custom_client.rb +31 -9
  21. data/lib/connectors_sdk/office365/extractor.rb +8 -8
  22. data/lib/connectors_sdk/share_point/adapter.rb +12 -12
  23. data/lib/connectors_sdk/share_point/authorization.rb +14 -62
  24. data/lib/connectors_sdk/share_point/extractor.rb +2 -2
  25. data/lib/connectors_sdk/share_point/http_call_wrapper.rb +24 -83
  26. data/lib/connectors_shared/exception_tracking.rb +4 -4
  27. data/lib/connectors_shared/extraction_utils.rb +109 -0
  28. data/lib/connectors_shared/middleware/basic_auth.rb +27 -0
  29. data/lib/connectors_shared/middleware/bearer_auth.rb +27 -0
  30. data/lib/connectors_shared/middleware/restrict_hostnames.rb +73 -0
  31. data/lib/connectors_shared/monitor.rb +3 -3
  32. data/lib/stubs/enterprise_search/exception_tracking.rb +43 -0
  33. metadata +22 -10
  34. data/lib/connectors_sdk/base/.config.rb.un~ +0 -0
  35. data/lib/connectors_sdk/base/.connectors.rb.un~ +0 -0
  36. data/lib/connectors_sdk/base/.registry.rb.un~ +0 -0
  37. data/lib/connectors_sdk/share_point/.http_call_wrapper.rb.un~ +0 -0
@@ -0,0 +1,73 @@
1
+ #
2
+ # Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ # or more contributor license agreements. Licensed under the Elastic License;
4
+ # you may not use this file except in compliance with the Elastic License.
5
+ #
6
+
7
+ # frozen_string_literal: true
8
+
9
+ require 'faraday/middleware'
10
+ require 'resolv'
11
+
12
+ require 'connectors_shared/errors'
13
+ require 'connectors_shared/logger'
14
+
15
+ module ConnectorsShared
16
+ module Middleware
17
+ class RestrictHostnames < Faraday::Middleware
18
+ class AddressNotAllowed < ConnectorsShared::ClientError; end
19
+ URL_PATTERN = /\Ahttp/
20
+
21
+ attr_reader :allowed_hosts, :allowed_ips
22
+
23
+ def initialize(app = nil, options = {})
24
+ super(app)
25
+ @allowed_hosts = options[:allowed_hosts]
26
+ @allowed_ips = ips_from_hosts(@allowed_hosts)
27
+ end
28
+
29
+ def call(env)
30
+ raise AddressNotAllowed.new("Address not allowed for #{env[:url]}") if denied?(env)
31
+ @app.call(env)
32
+ end
33
+
34
+ private
35
+
36
+ def ips_from_hosts(hosts)
37
+ hosts&.flat_map do |host|
38
+ if URL_PATTERN.match(host)
39
+ lookup_ips(URI.parse(host).host)
40
+ elsif Resolv::IPv4::Regex.match(host) || Resolv::IPv6::Regex.match(host)
41
+ IPAddr.new(host)
42
+ else
43
+ lookup_ips(host)
44
+ end
45
+ end || []
46
+ end
47
+
48
+ def denied?(env)
49
+ requested_ips = lookup_ips(env[:url].hostname)
50
+ no_match = requested_ips.all? { |ip| !@allowed_ips.include?(ip) }
51
+ return false unless no_match
52
+ ConnectorsShared::Logger.warn("Requested url #{env[:url]} with resolved ip addresses #{requested_ips} does not match " \
53
+ "allowed hosts #{@allowed_hosts} with resolved ip addresses #{@allowed_ips}. Retrying.")
54
+ @allowed_ips = ips_from_hosts(@allowed_hosts) # maybe the IP has changed for an allowed host. Re-do allowed_hosts DNS lookup
55
+ no_match = requested_ips.all? { |ip| !@allowed_ips.include?(ip) }
56
+ ConnectorsShared::Logger.error("Requested url #{env[:url]} with resolved ip addresses #{requested_ips} does not match " \
57
+ "allowed hosts #{@allowed_hosts} with resolved ip addresses #{@allowed_ips}") if no_match
58
+ no_match
59
+ end
60
+
61
+ def lookup_ips(hostname)
62
+ addr_infos(hostname).map { |a| IPAddr.new(a.ip_address) }
63
+ end
64
+
65
+ def addr_infos(hostname)
66
+ Addrinfo.getaddrinfo(hostname, nil, :UNSPEC, :STREAM)
67
+ rescue SocketError
68
+ # In case of invalid hostname, return an empty list of addresses
69
+ []
70
+ end
71
+ end
72
+ end
73
+ end
@@ -8,7 +8,7 @@
8
8
 
9
9
  require 'connectors_shared/errors'
10
10
  require 'stubs/app_config' unless defined?(Rails)
11
- require 'stubs/swiftype/exception_tracking' unless defined?(Rails)
11
+ require 'stubs/enterprise_search/exception_tracking' unless defined?(Rails)
12
12
 
13
13
  module ConnectorsShared
14
14
  class Monitor
@@ -44,8 +44,8 @@ module ConnectorsShared
44
44
  end
45
45
 
46
46
  def note_error(error, id: Time.now.to_i)
47
- stack_trace = Swiftype::ExceptionTracking.generate_stack_trace(error)
48
- error_message = Swiftype::ExceptionTracking.generate_error_message(error, nil, nil)
47
+ stack_trace = EnterpriseSearch::ExceptionTracking.generate_stack_trace(error)
48
+ error_message = EnterpriseSearch::ExceptionTracking.generate_error_message(error, nil, nil)
49
49
  @connector.log_debug("Message id: #{id} - #{error_message}\n#{stack_trace}")
50
50
  @total_error_count += 1
51
51
  @consecutive_error_count += 1
@@ -0,0 +1,43 @@
1
+ #
2
+ # Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ # or more contributor license agreements. Licensed under the Elastic License;
4
+ # you may not use this file except in compliance with the Elastic License.
5
+ #
6
+
7
+ module EnterpriseSearch
8
+ class ExceptionTracking
9
+ def self.capture_message(message, context = {})
10
+ AppConfig.connectors_logger.error { "Error: #{message}. Context: #{context.inspect}" }
11
+
12
+ # When the method is called from a rescue block, our return value may leak outside of its
13
+ # intended scope, so let's explicitly return nil here to be safe.
14
+ nil
15
+ end
16
+
17
+ def self.log_exception(exception, message = nil, context: nil, logger: AppConfig.connectors_logger)
18
+ logger.error { message } if message
19
+ logger.error { generate_stack_trace(exception) }
20
+ logger.error { "Context: #{context.inspect}" } if context
21
+ end
22
+
23
+ def self.generate_error_message(exception, message, context)
24
+ context = { :message_id => exception.id }.merge(context || {}) if exception.respond_to?(:id)
25
+ context_message = context && "Context: #{context.inspect}"
26
+ ['Exception', message, exception.class.to_s, exception.message, context_message]
27
+ .compact
28
+ .map { |part| part.to_s.dup.force_encoding('UTF-8') }
29
+ .join(': ')
30
+ end
31
+
32
+ def self.generate_stack_trace(exception)
33
+ full_message = exception.full_message
34
+
35
+ cause = exception
36
+ while cause.cause != cause && (cause = cause.cause)
37
+ full_message << "Cause:\n#{cause.full_message}"
38
+ end
39
+
40
+ full_message.dup.force_encoding('UTF-8')
41
+ end
42
+ end
43
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: connectors_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.3.0.0.pre.20220414T060419Z
4
+ version: 8.3.0.0.pre.20220510T144908Z
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-14 00:00:00.000000000 Z
11
+ date: 2022-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -61,19 +61,27 @@ files:
61
61
  - LICENSE
62
62
  - NOTICE.txt
63
63
  - lib/connectors_sdk.rb
64
- - lib/connectors_sdk/base/.config.rb.un~
65
- - lib/connectors_sdk/base/.connectors.rb.un~
66
- - lib/connectors_sdk/base/.registry.rb.un~
64
+ - lib/connectors_sdk/atlassian/config.rb
65
+ - lib/connectors_sdk/atlassian/custom_client.rb
67
66
  - lib/connectors_sdk/base/adapter.rb
67
+ - lib/connectors_sdk/base/authorization.rb
68
68
  - lib/connectors_sdk/base/config.rb
69
69
  - lib/connectors_sdk/base/custom_client.rb
70
70
  - lib/connectors_sdk/base/extractor.rb
71
+ - lib/connectors_sdk/base/http_call_wrapper.rb
71
72
  - lib/connectors_sdk/base/registry.rb
73
+ - lib/connectors_sdk/confluence/adapter.rb
74
+ - lib/connectors_sdk/confluence/custom_client.rb
75
+ - lib/connectors_sdk/confluence/extractor.rb
76
+ - lib/connectors_sdk/confluence_cloud/authorization.rb
77
+ - lib/connectors_sdk/confluence_cloud/custom_client.rb
78
+ - lib/connectors_sdk/confluence_cloud/extractor.rb
79
+ - lib/connectors_sdk/confluence_cloud/http_call_wrapper.rb
80
+ - lib/connectors_sdk/helpers/atlassian_time_formatter.rb
72
81
  - lib/connectors_sdk/office365/adapter.rb
73
82
  - lib/connectors_sdk/office365/config.rb
74
83
  - lib/connectors_sdk/office365/custom_client.rb
75
84
  - lib/connectors_sdk/office365/extractor.rb
76
- - lib/connectors_sdk/share_point/.http_call_wrapper.rb.un~
77
85
  - lib/connectors_sdk/share_point/adapter.rb
78
86
  - lib/connectors_sdk/share_point/authorization.rb
79
87
  - lib/connectors_sdk/share_point/extractor.rb
@@ -83,14 +91,19 @@ files:
83
91
  - lib/connectors_shared/errors.rb
84
92
  - lib/connectors_shared/exception_tracking.rb
85
93
  - lib/connectors_shared/extension_mapping_util.rb
94
+ - lib/connectors_shared/extraction_utils.rb
86
95
  - lib/connectors_shared/logger.rb
96
+ - lib/connectors_shared/middleware/basic_auth.rb
97
+ - lib/connectors_shared/middleware/bearer_auth.rb
98
+ - lib/connectors_shared/middleware/restrict_hostnames.rb
87
99
  - lib/connectors_shared/monitor.rb
100
+ - lib/stubs/enterprise_search/exception_tracking.rb
88
101
  homepage: https://github.com/elastic/connectors
89
102
  licenses:
90
103
  - Elastic-2.0
91
104
  metadata:
92
- revision: 427fad57fc69a8107c127ecbf99c6a5e803ea90c
93
- repository: https://github.com/elastic/connectors.git
105
+ revision: fb1187beef857b555633e1804eef3ed5e586091d
106
+ repository: git@github.com:elastic/connectors.git
94
107
  post_install_message:
95
108
  rdoc_options: []
96
109
  require_paths:
@@ -106,8 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
119
  - !ruby/object:Gem::Version
107
120
  version: 1.3.1
108
121
  requirements: []
109
- rubyforge_project:
110
- rubygems_version: 2.7.7
122
+ rubygems_version: 3.0.3.1
111
123
  signing_key:
112
124
  specification_version: 4
113
125
  summary: Gem containing apis used by Enterprise Search and implementations of Connectors
Binary file