connectors_sdk 8.3.0.0.pre.20220517T144653Z → 8.3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/connectors_sdk/base/{http_call_wrapper.rb → connector.rb} +41 -10
- data/lib/connectors_sdk/base/extractor.rb +3 -0
- data/lib/connectors_sdk/base/registry.rb +7 -4
- data/lib/connectors_sdk/confluence/extractor.rb +1 -1
- data/lib/connectors_sdk/confluence_cloud/{http_call_wrapper.rb → connector.rb} +31 -6
- data/lib/connectors_sdk/share_point/{http_call_wrapper.rb → connector.rb} +30 -6
- data/lib/connectors_sdk/stub_connector/connector.rb +62 -0
- data/lib/connectors_shared/constants.rb +12 -0
- data/lib/connectors_shared/middleware/restrict_hostnames.rb +1 -1
- metadata +12 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21bd11a44ed7c45fa04b218346fda20d946b97ec8f7025c2cfb8c8f92321d6a3
|
4
|
+
data.tar.gz: b388f972974f32c59d719b809975229125e293045dd35559546fefe5485e1fc3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88aa76506d6f2af049ea2a2ff54797270cef692319dd9ca647d33903a9fb3bb8bb274d9d99a3f94fe4d54cfce1722b31d63203cd157b627ccf3b2ca541b63523
|
7
|
+
data.tar.gz: 3faf8e16b18c0abd4f13fa988de8a6bb03e95bce5738389f132748fc17a230a9e516eb8b9f898d60aeb8a869f1ad1dadbb8606178e01be7d9ccc63ca98dcf681
|
@@ -10,13 +10,25 @@ require 'bson'
|
|
10
10
|
|
11
11
|
module ConnectorsSdk
|
12
12
|
module Base
|
13
|
-
class
|
13
|
+
class Connector
|
14
14
|
def extractor(params)
|
15
|
+
content_source_id = params.fetch(:content_source_id)
|
16
|
+
secret_storage = params[:secret_storage]
|
17
|
+
|
15
18
|
extractor_class.new(
|
16
|
-
content_source_id:
|
19
|
+
content_source_id: content_source_id || "GENERATED-#{BSON::ObjectId.new}",
|
17
20
|
service_type: service_type,
|
18
|
-
authorization_data_proc: proc
|
19
|
-
|
21
|
+
authorization_data_proc: proc do
|
22
|
+
secret = secret_storage.fetch_secret(content_source_id)
|
23
|
+
{
|
24
|
+
access_token: secret[:access_token]
|
25
|
+
}
|
26
|
+
end,
|
27
|
+
client_proc: proc {
|
28
|
+
secret = secret_storage.fetch_secret(content_source_id)
|
29
|
+
params[:access_token] = secret[:access_token]
|
30
|
+
client(params)
|
31
|
+
},
|
20
32
|
config: config(params),
|
21
33
|
features: params.fetch(:features, {}) || {}
|
22
34
|
)
|
@@ -68,6 +80,10 @@ module ConnectorsSdk
|
|
68
80
|
end
|
69
81
|
end
|
70
82
|
|
83
|
+
def download(params)
|
84
|
+
extractor(params).download(params[:meta])
|
85
|
+
end
|
86
|
+
|
71
87
|
def authorization_uri(params)
|
72
88
|
authorization.authorization_uri(params)
|
73
89
|
end
|
@@ -80,18 +96,18 @@ module ConnectorsSdk
|
|
80
96
|
authorization.refresh(params)
|
81
97
|
end
|
82
98
|
|
83
|
-
def download(params)
|
84
|
-
extractor(params).download(params[:meta])
|
85
|
-
end
|
86
|
-
|
87
99
|
def source_status(params)
|
88
100
|
health_check(params)
|
89
|
-
{ :status => 'OK', :statusCode => 200, :message => "Connected to #{
|
101
|
+
{ :status => 'OK', :statusCode => 200, :message => "Connected to #{display_name}" }
|
90
102
|
rescue StandardError => e
|
91
103
|
{ :status => 'FAILURE', :statusCode => e.is_a?(custom_client_error) ? e.status_code : 500, :message => e.message }
|
92
104
|
end
|
93
105
|
|
94
|
-
def
|
106
|
+
def compare_secrets(*)
|
107
|
+
raise 'Not implemented for this connector'
|
108
|
+
end
|
109
|
+
|
110
|
+
def display_name
|
95
111
|
raise 'Not implemented for this connector'
|
96
112
|
end
|
97
113
|
|
@@ -99,6 +115,14 @@ module ConnectorsSdk
|
|
99
115
|
self.class::SERVICE_TYPE
|
100
116
|
end
|
101
117
|
|
118
|
+
def connection_requires_redirect
|
119
|
+
false
|
120
|
+
end
|
121
|
+
|
122
|
+
def configurable_fields
|
123
|
+
[]
|
124
|
+
end
|
125
|
+
|
102
126
|
private
|
103
127
|
|
104
128
|
def convert_third_party_errors
|
@@ -130,6 +154,13 @@ module ConnectorsSdk
|
|
130
154
|
def health_check(*)
|
131
155
|
raise 'Not implemented for this connector'
|
132
156
|
end
|
157
|
+
|
158
|
+
def missing_secrets?(params)
|
159
|
+
missing = %w[secret other_secret].select { |field| params[field.to_sym].nil? }
|
160
|
+
unless missing.blank?
|
161
|
+
raise ConnectorsShared::ClientError.new("Missing required fields: #{missing.join(', ')}")
|
162
|
+
end
|
163
|
+
end
|
133
164
|
end
|
134
165
|
end
|
135
166
|
end
|
@@ -188,16 +188,19 @@ module ConnectorsSdk
|
|
188
188
|
end
|
189
189
|
|
190
190
|
def permissions(source_user_id, &block)
|
191
|
+
result = []
|
191
192
|
Connectors::Stats.measure("extractor.#{Connectors::Stats.class_key(self.class)}.permissions") do
|
192
193
|
with_auth_tokens_and_retry do
|
193
194
|
Connectors::Stats.measure("extractor.#{Connectors::Stats.class_key(self.class)}.yield_permissions") do
|
194
195
|
yield_permissions(source_user_id) do |permissions|
|
195
196
|
log_info("Extracted #{permissions.size} permissions for source user #{source_user_id}")
|
197
|
+
result = permissions
|
196
198
|
block.call(permissions) if block_given?
|
197
199
|
end
|
198
200
|
end
|
199
201
|
end
|
200
202
|
end
|
203
|
+
result.each
|
201
204
|
end
|
202
205
|
|
203
206
|
ConnectorsShared::Logger::SUPPORTED_LOG_LEVELS.each do |log_level|
|
@@ -24,11 +24,14 @@ module ConnectorsSdk
|
|
24
24
|
|
25
25
|
REGISTRY = Factory.new
|
26
26
|
|
27
|
+
require_relative '../stub_connector/connector'
|
28
|
+
REGISTRY.register(ConnectorsSdk::StubConnector::Connector::SERVICE_TYPE, ConnectorsSdk::StubConnector::Connector)
|
29
|
+
|
27
30
|
# loading plugins (might replace this with a directory scan and conventions on names)
|
28
|
-
require_relative '../share_point/
|
29
|
-
require_relative '../confluence_cloud
|
31
|
+
require_relative '../share_point/connector'
|
32
|
+
require_relative '../confluence_cloud/connector'
|
30
33
|
|
31
|
-
REGISTRY.register(ConnectorsSdk::SharePoint::
|
32
|
-
REGISTRY.register(ConnectorsSdk::ConfluenceCloud::
|
34
|
+
REGISTRY.register(ConnectorsSdk::SharePoint::Connector::SERVICE_TYPE, ConnectorsSdk::SharePoint::Connector)
|
35
|
+
REGISTRY.register(ConnectorsSdk::ConfluenceCloud::Connector::SERVICE_TYPE, ConnectorsSdk::ConfluenceCloud::Connector)
|
33
36
|
end
|
34
37
|
end
|
@@ -10,19 +10,44 @@ require 'connectors_sdk/atlassian/config'
|
|
10
10
|
require 'connectors_sdk/confluence_cloud/extractor'
|
11
11
|
require 'connectors_sdk/confluence_cloud/authorization'
|
12
12
|
require 'connectors_sdk/confluence_cloud/custom_client'
|
13
|
-
require 'connectors_sdk/base/
|
13
|
+
require 'connectors_sdk/base/connector'
|
14
14
|
|
15
15
|
module ConnectorsSdk
|
16
16
|
module ConfluenceCloud
|
17
|
-
class
|
17
|
+
class Connector < ConnectorsSdk::Base::Connector
|
18
18
|
SERVICE_TYPE = 'confluence_cloud'
|
19
19
|
|
20
|
-
def
|
20
|
+
def compare_secrets(params)
|
21
|
+
missing_secrets?(params)
|
22
|
+
|
23
|
+
{
|
24
|
+
:equivalent => params[:secret] == params[:other_secret]
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def display_name
|
21
29
|
'Confluence Cloud'
|
22
30
|
end
|
23
31
|
|
24
|
-
def
|
25
|
-
|
32
|
+
def connection_requires_redirect
|
33
|
+
true
|
34
|
+
end
|
35
|
+
|
36
|
+
def configurable_fields
|
37
|
+
[
|
38
|
+
{
|
39
|
+
'key' => 'base_url',
|
40
|
+
'label' => 'Base URL'
|
41
|
+
},
|
42
|
+
{
|
43
|
+
'key' => 'client_id',
|
44
|
+
'label' => 'Client ID'
|
45
|
+
},
|
46
|
+
{
|
47
|
+
'key' => 'client_secret',
|
48
|
+
'label' => 'Client Secret'
|
49
|
+
},
|
50
|
+
]
|
26
51
|
end
|
27
52
|
|
28
53
|
private
|
@@ -44,7 +69,7 @@ module ConnectorsSdk
|
|
44
69
|
end
|
45
70
|
|
46
71
|
def config(params)
|
47
|
-
ConnectorsSdk::Atlassian::Config.new(:base_url =>
|
72
|
+
ConnectorsSdk::Atlassian::Config.new(:base_url => "#{params[:external_connector_base_url]}/wiki", :cursors => params.fetch(:cursors, {}) || {})
|
48
73
|
end
|
49
74
|
|
50
75
|
def health_check(params)
|
@@ -6,22 +6,46 @@
|
|
6
6
|
|
7
7
|
# frozen_string_literal: true
|
8
8
|
|
9
|
+
require 'connectors_sdk/base/connector'
|
9
10
|
require 'connectors_sdk/office365/config'
|
10
11
|
require 'connectors_sdk/share_point/extractor'
|
11
12
|
require 'connectors_sdk/share_point/authorization'
|
12
|
-
require 'connectors_sdk/base/http_call_wrapper'
|
13
13
|
|
14
14
|
module ConnectorsSdk
|
15
15
|
module SharePoint
|
16
|
-
class
|
16
|
+
class Connector < ConnectorsSdk::Base::Connector
|
17
17
|
SERVICE_TYPE = 'share_point'
|
18
18
|
|
19
|
-
def
|
20
|
-
|
19
|
+
def compare_secrets(params)
|
20
|
+
missing_secrets?(params)
|
21
|
+
|
22
|
+
previous_user = client(:access_token => params[:other_secret][:access_token]).me
|
23
|
+
equivalent = previous_user.nil? ? false : previous_user.id == client(:access_token => params[:secret][:access_token]).me&.id
|
24
|
+
|
25
|
+
{
|
26
|
+
:equivalent => equivalent
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def display_name
|
31
|
+
'SharePoint Online'
|
32
|
+
end
|
33
|
+
|
34
|
+
def connection_requires_redirect
|
35
|
+
true
|
21
36
|
end
|
22
37
|
|
23
|
-
def
|
24
|
-
|
38
|
+
def configurable_fields
|
39
|
+
[
|
40
|
+
{
|
41
|
+
'key' => 'client_id',
|
42
|
+
'label' => 'Client ID'
|
43
|
+
},
|
44
|
+
{
|
45
|
+
'key' => 'client_secret',
|
46
|
+
'label' => 'Client Secret'
|
47
|
+
},
|
48
|
+
]
|
25
49
|
end
|
26
50
|
|
27
51
|
private
|
@@ -0,0 +1,62 @@
|
|
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 'connectors_sdk/base/connector'
|
10
|
+
|
11
|
+
module ConnectorsSdk
|
12
|
+
module StubConnector
|
13
|
+
class Connector < ConnectorsSdk::Base::Connector
|
14
|
+
SERVICE_TYPE = 'stub_connector'
|
15
|
+
|
16
|
+
def display_name
|
17
|
+
'Stub Connector'
|
18
|
+
end
|
19
|
+
|
20
|
+
def configurable_fields
|
21
|
+
[
|
22
|
+
{
|
23
|
+
'key' => 'third_party_url',
|
24
|
+
'label' => 'Third Party URL'
|
25
|
+
},
|
26
|
+
{
|
27
|
+
'key' => 'third_party_api_key',
|
28
|
+
'label' => 'Third Party API Key'
|
29
|
+
}
|
30
|
+
]
|
31
|
+
end
|
32
|
+
|
33
|
+
def health_check(_params)
|
34
|
+
true
|
35
|
+
end
|
36
|
+
|
37
|
+
def document_batch(_params)
|
38
|
+
results = 30.times.map do |i|
|
39
|
+
{
|
40
|
+
:action => :create_or_update,
|
41
|
+
:document => {
|
42
|
+
:id => "document_#{i}",
|
43
|
+
:type => 'document',
|
44
|
+
:body => "contents for document number: #{i}"
|
45
|
+
},
|
46
|
+
:download => nil
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
[results, {}, true]
|
51
|
+
end
|
52
|
+
|
53
|
+
def deleted(_params)
|
54
|
+
[]
|
55
|
+
end
|
56
|
+
|
57
|
+
def permissions(_params)
|
58
|
+
[]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -10,5 +10,17 @@ module ConnectorsShared
|
|
10
10
|
SUBEXTRACTOR_RESERVED_FIELDS = %w[_subextracted_as_of _subextracted_version].freeze
|
11
11
|
ALLOW_FIELD = '_allow_permissions'.freeze
|
12
12
|
DENY_FIELD = '_deny_permissions'.freeze
|
13
|
+
|
14
|
+
# The following section reads as following:
|
15
|
+
# The job will extract documents until the job queue size will reach
|
16
|
+
# JOB_QUEUE_SIZE_IDLE_THRESHOLD items. After that, the job will attempt to sleep
|
17
|
+
# for IDLE_SLEEP_TIME seconds and check the queue size again. If the queue is still
|
18
|
+
# full, it will sleep for maximum MAX_IDDLE_ATTEMPTS times, and if the queue is still
|
19
|
+
# full, then job will be terminated.
|
20
|
+
JOB_QUEUE_SIZE_IDLE_THRESHOLD = 500 # How many documents the job queue stores until it sleeps
|
21
|
+
IDLE_SLEEP_TIME = 10 # For how long job queue will sleep before checking the queue size again
|
22
|
+
MAX_IDLE_ATTEMPTS = 30 # How many consecutive times job will try to sleep until it's destroyed
|
23
|
+
|
24
|
+
STALE_JOB_TIMEOUT = 60 * 30 # Time in seconds after which the job will be cleaned up if the job is considered stuck
|
13
25
|
end
|
14
26
|
end
|
@@ -36,7 +36,7 @@ module ConnectorsShared
|
|
36
36
|
def ips_from_hosts(hosts)
|
37
37
|
hosts&.flat_map do |host|
|
38
38
|
if URL_PATTERN.match(host)
|
39
|
-
lookup_ips(URI.parse(host).
|
39
|
+
lookup_ips(Addressable::URI.parse(host).hostname)
|
40
40
|
elsif Resolv::IPv4::Regex.match(host) || Resolv::IPv6::Regex.match(host)
|
41
41
|
IPAddr.new(host)
|
42
42
|
else
|
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
|
4
|
+
version: 8.3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-05-
|
11
|
+
date: 2022-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -66,17 +66,17 @@ files:
|
|
66
66
|
- lib/connectors_sdk/base/adapter.rb
|
67
67
|
- lib/connectors_sdk/base/authorization.rb
|
68
68
|
- lib/connectors_sdk/base/config.rb
|
69
|
+
- lib/connectors_sdk/base/connector.rb
|
69
70
|
- lib/connectors_sdk/base/custom_client.rb
|
70
71
|
- lib/connectors_sdk/base/extractor.rb
|
71
|
-
- lib/connectors_sdk/base/http_call_wrapper.rb
|
72
72
|
- lib/connectors_sdk/base/registry.rb
|
73
73
|
- lib/connectors_sdk/confluence/adapter.rb
|
74
74
|
- lib/connectors_sdk/confluence/custom_client.rb
|
75
75
|
- lib/connectors_sdk/confluence/extractor.rb
|
76
76
|
- lib/connectors_sdk/confluence_cloud/authorization.rb
|
77
|
+
- lib/connectors_sdk/confluence_cloud/connector.rb
|
77
78
|
- lib/connectors_sdk/confluence_cloud/custom_client.rb
|
78
79
|
- lib/connectors_sdk/confluence_cloud/extractor.rb
|
79
|
-
- lib/connectors_sdk/confluence_cloud/http_call_wrapper.rb
|
80
80
|
- lib/connectors_sdk/helpers/atlassian_time_formatter.rb
|
81
81
|
- lib/connectors_sdk/office365/adapter.rb
|
82
82
|
- lib/connectors_sdk/office365/config.rb
|
@@ -84,8 +84,9 @@ files:
|
|
84
84
|
- lib/connectors_sdk/office365/extractor.rb
|
85
85
|
- lib/connectors_sdk/share_point/adapter.rb
|
86
86
|
- lib/connectors_sdk/share_point/authorization.rb
|
87
|
+
- lib/connectors_sdk/share_point/connector.rb
|
87
88
|
- lib/connectors_sdk/share_point/extractor.rb
|
88
|
-
- lib/connectors_sdk/
|
89
|
+
- lib/connectors_sdk/stub_connector/connector.rb
|
89
90
|
- lib/connectors_shared.rb
|
90
91
|
- lib/connectors_shared/constants.rb
|
91
92
|
- lib/connectors_shared/errors.rb
|
@@ -103,9 +104,9 @@ homepage: https://github.com/elastic/connectors
|
|
103
104
|
licenses:
|
104
105
|
- Elastic-2.0
|
105
106
|
metadata:
|
106
|
-
revision:
|
107
|
+
revision: 8fe65b05c8d8c89d62d73e7d717238a5393d42f5
|
107
108
|
repository: git@github.com:elastic/connectors.git
|
108
|
-
post_install_message:
|
109
|
+
post_install_message:
|
109
110
|
rdoc_options: []
|
110
111
|
require_paths:
|
111
112
|
- lib
|
@@ -116,12 +117,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
117
|
version: '0'
|
117
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
119
|
requirements:
|
119
|
-
- - "
|
120
|
+
- - ">="
|
120
121
|
- !ruby/object:Gem::Version
|
121
|
-
version:
|
122
|
+
version: '0'
|
122
123
|
requirements: []
|
123
124
|
rubygems_version: 3.0.3.1
|
124
|
-
signing_key:
|
125
|
+
signing_key:
|
125
126
|
specification_version: 4
|
126
127
|
summary: Gem containing apis used by Enterprise Search and implementations of Connectors
|
127
128
|
test_files: []
|