connectors_sdk 8.3.0.0.pre.20220414T060419Z → 8.3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) 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/connector.rb +166 -0
  7. data/lib/connectors_sdk/base/custom_client.rb +1 -2
  8. data/lib/connectors_sdk/base/extractor.rb +6 -2
  9. data/lib/connectors_sdk/base/registry.rb +9 -4
  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 +265 -0
  13. data/lib/connectors_sdk/confluence_cloud/authorization.rb +64 -0
  14. data/lib/connectors_sdk/confluence_cloud/connector.rb +84 -0
  15. data/lib/connectors_sdk/confluence_cloud/custom_client.rb +61 -0
  16. data/lib/connectors_sdk/confluence_cloud/extractor.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 +20 -39
  21. data/lib/connectors_sdk/office365/extractor.rb +18 -34
  22. data/lib/connectors_sdk/share_point/adapter.rb +24 -12
  23. data/lib/connectors_sdk/share_point/authorization.rb +14 -62
  24. data/lib/connectors_sdk/share_point/connector.rb +82 -0
  25. data/lib/connectors_sdk/share_point/extractor.rb +2 -2
  26. data/lib/connectors_sdk/stub_connector/connector.rb +62 -0
  27. data/lib/connectors_shared/constants.rb +12 -0
  28. data/lib/connectors_shared/exception_tracking.rb +4 -4
  29. data/lib/connectors_shared/extraction_utils.rb +109 -0
  30. data/lib/connectors_shared/job_status.rb +18 -0
  31. data/lib/connectors_shared/middleware/basic_auth.rb +27 -0
  32. data/lib/connectors_shared/middleware/bearer_auth.rb +27 -0
  33. data/lib/connectors_shared/middleware/restrict_hostnames.rb +73 -0
  34. data/lib/connectors_shared/monitor.rb +3 -3
  35. data/lib/connectors_shared.rb +1 -0
  36. data/lib/stubs/enterprise_search/exception_tracking.rb +43 -0
  37. metadata +30 -16
  38. data/lib/connectors_sdk/base/.config.rb.un~ +0 -0
  39. data/lib/connectors_sdk/base/.connectors.rb.un~ +0 -0
  40. data/lib/connectors_sdk/base/.registry.rb.un~ +0 -0
  41. data/lib/connectors_sdk/share_point/.http_call_wrapper.rb.un~ +0 -0
  42. data/lib/connectors_sdk/share_point/http_call_wrapper.rb +0 -117
@@ -0,0 +1,84 @@
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/atlassian/config'
10
+ require 'connectors_sdk/confluence_cloud/extractor'
11
+ require 'connectors_sdk/confluence_cloud/authorization'
12
+ require 'connectors_sdk/confluence_cloud/custom_client'
13
+ require 'connectors_sdk/base/connector'
14
+
15
+ module ConnectorsSdk
16
+ module ConfluenceCloud
17
+ class Connector < ConnectorsSdk::Base::Connector
18
+ SERVICE_TYPE = 'confluence_cloud'
19
+
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
29
+ 'Confluence Cloud'
30
+ end
31
+
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
+ ]
51
+ end
52
+
53
+ private
54
+
55
+ def extractor_class
56
+ ConnectorsSdk::ConfluenceCloud::Extractor
57
+ end
58
+
59
+ def authorization
60
+ ConnectorsSdk::ConfluenceCloud::Authorization
61
+ end
62
+
63
+ def client(params)
64
+ ConnectorsSdk::ConfluenceCloud::CustomClient.new(:base_url => base_url(params[:cloud_id]), :access_token => params[:access_token])
65
+ end
66
+
67
+ def custom_client_error
68
+ ConnectorsSdk::Atlassian::CustomClient::ClientError
69
+ end
70
+
71
+ def config(params)
72
+ ConnectorsSdk::Atlassian::Config.new(:base_url => "#{params[:external_connector_base_url]}/wiki", :cursors => params.fetch(:cursors, {}) || {})
73
+ end
74
+
75
+ def health_check(params)
76
+ client(params).me
77
+ end
78
+
79
+ def base_url(cloud_id)
80
+ "https://api.atlassian.com/ex/confluence/#{cloud_id}"
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,61 @@
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/confluence/custom_client'
10
+
11
+ module ConnectorsSdk
12
+ module ConfluenceCloud
13
+ class CustomClient < ConnectorsSdk::Confluence::CustomClient
14
+ def user_groups(account_id, limit: 200, start: 0)
15
+ size = Float::INFINITY
16
+
17
+ groups = []
18
+
19
+ while start + limit < size
20
+ params = {
21
+ :start => start,
22
+ :limit => limit,
23
+ :accountId => account_id
24
+ }
25
+ response = get('rest/api/user/memberof', params)
26
+ result = Hashie::Mash.new(parse_and_raise_if_necessary!(response))
27
+ size = result.size
28
+ start += limit
29
+ groups.concat(result.results)
30
+ end
31
+
32
+ groups
33
+ end
34
+
35
+ def user(account_id, expand: [])
36
+ params = {
37
+ :accountId => account_id
38
+ }
39
+ if expand.present?
40
+ params[:expand] = case expand
41
+ when Array
42
+ expand.join(',')
43
+ when String
44
+ expand
45
+ else
46
+ expand.to_s
47
+ end
48
+ end
49
+ response = get('rest/api/user', params)
50
+ Hashie::Mash.new(parse_and_raise_if_necessary!(response))
51
+ rescue ConnectorsSdk::Atlassian::CustomClient::ClientError => e
52
+ if e.status_code == 404
53
+ ConnectorsShared::Logger.warn("Could not find a user with account id #{account_id}")
54
+ nil
55
+ else
56
+ raise
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,59 @@
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/confluence/extractor'
10
+
11
+ module ConnectorsSdk
12
+ module ConfluenceCloud
13
+ class Extractor < ConnectorsSdk::Confluence::Extractor
14
+
15
+ def yield_permissions(source_user_id)
16
+ # yield empty permissions if the user is suspended or deleted
17
+ user = client.user(source_user_id, :expand => 'operations')
18
+ if user.nil? || user.operations.blank?
19
+ yield [] and return
20
+ end
21
+
22
+ # refresh space permissions if not initialized
23
+ if @space_permissions_cache.nil?
24
+ @space_permissions_cache = {}
25
+ yield_spaces do |space|
26
+ if config.index_permissions
27
+ get_space_permissions(space)
28
+ end
29
+ end
30
+ end
31
+
32
+ direct_spaces = get_user_spaces(source_user_id)
33
+ indirect_spaces = []
34
+
35
+ group_permissions = []
36
+ client.user_groups(source_user_id).each do |group|
37
+ group_name = group.name
38
+ group_spaces = get_group_spaces(group_name)
39
+ indirect_spaces << group_spaces
40
+ group_permissions << "group:#{group_name}"
41
+ end
42
+
43
+ total_user_spaces = indirect_spaces.flatten.concat(direct_spaces).uniq
44
+ user_permissions = ["user:#{source_user_id}"]
45
+ .concat(group_permissions)
46
+ .product(total_user_spaces)
47
+ .collect { |permission, space| "#{space}/#{permission}" }
48
+
49
+ yield user_permissions.flatten.uniq.sort
50
+ end
51
+
52
+ def download(item)
53
+ content = item[:content]
54
+ parent_id = content.dig('container', 'id')
55
+ client.download("#{client.base_url}/wiki/rest/api/content/#{parent_id}/child/attachment/#{content['id']}/download").body
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,10 @@
1
+ module ConnectorsSdk
2
+ module Helpers
3
+ module AtlassianTimeFormatter
4
+ def format_time(time)
5
+ time = Time.parse(time) if time.is_a?(String)
6
+ time.strftime('%Y-%m-%d %H:%M')
7
+ end
8
+ end
9
+ end
10
+ end
@@ -11,11 +11,11 @@ require 'connectors_sdk/base/adapter'
11
11
  module ConnectorsSdk
12
12
  module Office365
13
13
  class Adapter < ConnectorsSdk::Base::Adapter
14
- def self.swiftype_document_from_file(_file)
14
+ def self.es_document_from_file(_file)
15
15
  raise NotImplementedError
16
16
  end
17
17
 
18
- def self.swiftype_document_from_folder(_folder)
18
+ def self.es_document_from_folder(_folder)
19
19
  raise NotImplementedError
20
20
  end
21
21
 
@@ -26,7 +26,7 @@ module ConnectorsSdk
26
26
  @item = item
27
27
  end
28
28
 
29
- def self.convert_id_to_fp_id(_id)
29
+ def self.convert_id_to_es_id(_id)
30
30
  raise NotImplementedError
31
31
  end
32
32
 
@@ -41,10 +41,10 @@ module ConnectorsSdk
41
41
  ConnectorsSdk::Office365::Adapter.normalize_path("#{parent_folder_path}/#{item.name}")
42
42
  end
43
43
 
44
- def to_swiftype_document
44
+ def to_es_document
45
45
  {
46
46
  :_fields_to_preserve => ConnectorsSdk::Office365::Adapter.fields_to_preserve,
47
- :id => self.class.convert_id_to_fp_id(item.id),
47
+ :id => self.class.convert_id_to_es_id(item.id),
48
48
  :path => get_path(item),
49
49
  :title => item.name,
50
50
  :url => item.webUrl,
@@ -96,7 +96,7 @@ module ConnectorsSdk
96
96
  end
97
97
 
98
98
  class FileGraphItem < GraphItem
99
- def self.convert_id_to_fp_id(_id)
99
+ def self.convert_id_to_es_id(_id)
100
100
  raise NotImplementedError
101
101
  end
102
102
 
@@ -132,7 +132,7 @@ module ConnectorsSdk
132
132
  end
133
133
 
134
134
  class PackageGraphItem < GraphItem
135
- def self.convert_id_to_fp_id(id)
135
+ def self.convert_id_to_es_id(id)
136
136
  raise NotImplementedError
137
137
  end
138
138
 
@@ -7,6 +7,7 @@
7
7
  # frozen_string_literal: true
8
8
 
9
9
  require 'connectors_sdk/base/config'
10
+ require 'connectors_sdk/office365/extractor'
10
11
 
11
12
  module ConnectorsSdk
12
13
  module Office365
@@ -6,9 +6,11 @@
6
6
 
7
7
  # frozen_string_literal: true
8
8
 
9
+ require 'hashie/mash'
10
+
9
11
  require 'connectors_sdk/base/custom_client'
12
+ require 'connectors_sdk/office365/extractor'
10
13
  require 'connectors_shared'
11
- require 'hashie/mash'
12
14
 
13
15
  module ConnectorsSdk
14
16
  module Office365
@@ -50,7 +52,6 @@ module ConnectorsSdk
50
52
  def initialize(access_token:, cursors: {}, ensure_fresh_auth: nil)
51
53
  @access_token = access_token
52
54
  @cursors = cursors || {}
53
- @cursors[ConnectorsSdk::Office365::Extractor::DRIVE_IDS_CURSOR_KEY] ||= {}
54
55
  super(:ensure_fresh_auth => ensure_fresh_auth)
55
56
  end
56
57
 
@@ -75,12 +76,11 @@ module ConnectorsSdk
75
76
  # recently created groups (new Private Team site will be there) to reduce friction and index this site
76
77
  # earlier.
77
78
  # See: https://github.com/elastic/ent-search/pull/3581
78
- share_point_sites = (sites(:fields => %w[id]) + recent_share_point_group_sites(:fields => %[id]))
79
+ share_point_sites = (sites(:fields => %w[id,name]) + recent_share_point_group_sites(:fields => %w[id,name]))
79
80
 
80
81
  share_point_sites
81
- .map(&:id)
82
- .uniq
83
- .map { |site_id| site_drives(site_id, :fields => fields) }
82
+ .uniq(&:id)
83
+ .map { |site| site_drives(site, :fields => fields) }
84
84
  .flatten
85
85
  .compact
86
86
  end
@@ -102,27 +102,23 @@ module ConnectorsSdk
102
102
  request_all(:endpoint => 'sites/', :fields => fields, :additional_query_params => { :search => '', :top => 10 })
103
103
  end
104
104
 
105
- def site_drives(site_id, fields: [])
105
+ def site_drives(site, fields: [])
106
106
  document_libraries(
107
- request_all(:endpoint => "sites/#{site_id}/drives/", :fields => fields)
108
- )
107
+ request_all(:endpoint => "sites/#{site.id}/drives/", :fields => fields)
108
+ ).map do |drive|
109
+ drive.site_name = site.name
110
+ drive
111
+ end
109
112
  rescue ClientError => e
110
113
  ConnectorsShared::Logger.info("Received response of #{e.status_code} trying to get drive for Site with Id = #{site_id}: #{e.message}")
111
114
  nil
112
115
  end
113
116
 
114
- def list_items(drive_id, fields: [], break_after_page: false)
117
+ def list_items(drive_id, fields: [])
115
118
  # MSFT Graph API does not have a recursive list items, have to do this dfs style
116
-
117
- stack = if break_after_page && cursors['page_cursor'].present?
118
- cursors.delete('page_cursor')
119
- else
120
- [get_root_item(drive_id, ['id']).id]
121
- end
122
-
119
+ stack = [get_root_item(drive_id, ['id']).id]
123
120
  # We rely on the id field below to perform our DFS
124
121
  fields_with_id = fields.any? ? fields | ['id'] : fields
125
- yielded = 0
126
122
  while stack.any?
127
123
  folder_id = stack.pop
128
124
  item_children(drive_id, folder_id, :fields => fields_with_id) do |item|
@@ -130,14 +126,8 @@ module ConnectorsSdk
130
126
  stack << item.id
131
127
  end
132
128
  yield item
133
-
134
- yielded += 1
135
129
  end
136
130
 
137
- if break_after_page && yielded >= 100 && stack.any?
138
- cursors['page_cursor'] = stack.dup
139
- break
140
- end
141
131
  end
142
132
  end
143
133
 
@@ -145,19 +135,16 @@ module ConnectorsSdk
145
135
  request_endpoint(:endpoint => "drives/#{drive_id}/items/#{item_id}/permissions").value
146
136
  end
147
137
 
148
- def list_changes(drive_id:, start_delta_link: nil, last_modified: nil, break_after_page: false)
138
+ def list_changes(drive_id:, start_delta_link: nil, last_modified: nil)
149
139
  query_params = { :'$select' => %w(id content.downloadUrl lastModifiedDateTime lastModifiedBy root deleted file folder package name webUrl createdBy createdDateTime size).join(',') }
150
140
  response =
151
- if break_after_page && cursors['page_cursor'].present?
152
- request_json(:url => cursors.delete('page_cursor'))
153
- elsif start_delta_link.nil?
141
+ if start_delta_link.nil?
154
142
  endpoint = "drives/#{drive_id}/root/delta"
155
143
  request_endpoint(:endpoint => endpoint, :query_params => query_params)
156
144
  else
157
145
  request_json(:url => start_delta_link, :query_params => query_params)
158
146
  end
159
147
 
160
- yielded = 0
161
148
  loop do
162
149
  response.value.each do |change|
163
150
  # MSFT Graph API does not allow us to view "changes" in chronological order, so if there is no cursor,
@@ -165,25 +152,18 @@ module ConnectorsSdk
165
152
  # since to get another cursor, we would have to go through all the changes anyway
166
153
  next if last_modified.present? && Time.parse(change.lastModifiedDateTime) < last_modified
167
154
  next if change.root # We don't want to index the root of the drive
168
-
169
155
  yield change
170
- yielded += 1
171
- end
172
-
173
- if break_after_page && yielded >= 100 && response['@odata.nextLink'].present?
174
- cursors['page_cursor'] = response['@odata.nextLink']
175
- break
176
156
  end
177
157
 
178
158
  break if response['@odata.nextLink'].nil?
179
159
  response = request_json(:url => response['@odata.nextLink'])
180
160
  end
181
161
 
182
- cursors[ConnectorsSdk::Office365::Extractor::DRIVE_IDS_CURSOR_KEY][drive_id] = response['@odata.deltaLink']
162
+ cursors[drive_id] = response['@odata.deltaLink']
183
163
  end
184
164
 
185
165
  def get_latest_delta_link(drive_id)
186
- cursors[ConnectorsSdk::Office365::Extractor::DRIVE_IDS_CURSOR_KEY][drive_id] || exhaustively_get_delta_link(drive_id)
166
+ cursors[drive_id] || exhaustively_get_delta_link(drive_id)
187
167
  end
188
168
 
189
169
  def exhaustively_get_delta_link(drive_id)
@@ -203,6 +183,7 @@ module ConnectorsSdk
203
183
  def download_item(download_url)
204
184
  request(:url => download_url) do |request|
205
185
  request.options.params_encoder = Office365DownloadParamsEncoder
186
+ request.options.timeout = 30
206
187
  end.body
207
188
  end
208
189
 
@@ -228,7 +209,7 @@ module ConnectorsSdk
228
209
 
229
210
  groups(:fields => %w(id createdDateTime))
230
211
  .select { |group| group.createdDateTime > created_date_time_threshold }
231
- .map { |group| group_root_site(group.id, :fields => %w[id]) }.compact
212
+ .map { |group| group_root_site(group.id, :fields => fields) }.compact
232
213
  end
233
214
 
234
215
  def document_libraries(drives)
@@ -14,52 +14,34 @@ module ConnectorsSdk
14
14
  class Extractor < ConnectorsSdk::Base::Extractor
15
15
  DRIVE_IDS_CURSOR_KEY = 'drive_ids'.freeze
16
16
 
17
- def yield_document_changes(modified_since: nil, break_after_page: false, &block)
17
+ def yield_document_changes(modified_since: nil, &block)
18
18
  drives_to_index.each do |drive|
19
19
  drive_id = drive.id
20
-
21
- if break_after_page
22
- current_drive_id = config.cursors['current_drive_id']
23
- if current_drive_id.present? && current_drive_id > drive_id # they come alpha sorted
24
- next
25
- end
26
- config.cursors['current_drive_id'] = drive_id
27
- end
28
-
29
20
  drive_owner_name = drive.dig(:owner, :user, :displayName)
30
21
  drive_name = drive.name
22
+ site_name = drive.site_name
31
23
 
32
24
  drive_id_to_delta_link = config.cursors.fetch(DRIVE_IDS_CURSOR_KEY, {})
33
25
  begin
34
26
  if start_delta_link = drive_id_to_delta_link[drive_id]
35
27
  log_debug("Starting an incremental crawl with cursor for #{service_type.classify} with drive_id: #{drive_id}")
36
28
  begin
37
- yield_changes(drive_id, :start_delta_link => start_delta_link, :drive_owner_name => drive_owner_name, :drive_name => drive_name, :break_after_page => break_after_page, &block)
29
+ yield_changes(drive_id, :start_delta_link => start_delta_link, :drive_owner_name => drive_owner_name, :drive_name => drive_name, :site_name => site_name, &block)
38
30
  rescue ConnectorsSdk::Office365::CustomClient::Office365InvalidCursorsError
39
31
  log_warn("Error listing changes with start_delta_link: #{start_delta_link}, falling back to full crawl")
40
- yield_drive_items(drive_id, :drive_owner_name => drive_owner_name, :drive_name => drive_name, :break_after_page => break_after_page, &block)
32
+ yield_drive_items(drive_id, :drive_owner_name => drive_owner_name, :drive_name => drive_name, :site_name => site_name, &block)
41
33
  end
42
34
  elsif modified_since.present?
43
35
  log_debug("Starting an incremental crawl using last_modified (no cursor found) for #{service_type.classify} with drive_id: #{drive_id}")
44
- yield_changes(drive_id, :last_modified => modified_since, :drive_owner_name => drive_owner_name, :drive_name => drive_name, :break_after_page => break_after_page, &block)
36
+ yield_changes(drive_id, :last_modified => modified_since, :drive_owner_name => drive_owner_name, :drive_name => drive_name, :site_name => site_name, &block)
45
37
  else
46
38
  log_debug("Starting a full crawl #{service_type.classify} with drive_id: #{drive_id}")
47
- yield_drive_items(drive_id, :drive_owner_name => drive_owner_name, :drive_name => drive_name, :break_after_page => break_after_page, &block)
39
+ yield_drive_items(drive_id, :drive_owner_name => drive_owner_name, :drive_name => drive_name, :site_name => site_name, &block)
48
40
  end
49
41
  rescue ConnectorsSdk::Office365::CustomClient::ClientError => e
50
42
  log_warn("Error searching and listing drive #{drive_id}")
51
43
  capture_exception(e)
52
44
  end
53
-
54
- if break_after_page && config.cursors['page_cursor'].present?
55
- break
56
- end
57
- end
58
-
59
- if break_after_page && config.cursors['page_cursor'].blank?
60
- @completed = true
61
- config.overwrite_cursors!(retrieve_latest_cursors)
62
- log_debug("Completed #{modified_since.nil? ? 'full' : 'incremental'} extraction")
63
45
  end
64
46
 
65
47
  nil
@@ -132,7 +114,7 @@ module ConnectorsSdk
132
114
  @existing_drive_item_ids ||= Set.new.tap do |ids|
133
115
  drives_to_index.each do |drive|
134
116
  client.list_items(drive.id) do |item|
135
- ids << convert_id_to_fp_id(item.id)
117
+ ids << convert_id_to_es_id(item.id)
136
118
  end
137
119
  end
138
120
  end
@@ -142,7 +124,7 @@ module ConnectorsSdk
142
124
  raise NotImplementedError
143
125
  end
144
126
 
145
- def convert_id_to_fp_id(_id)
127
+ def convert_id_to_es_id(_id)
146
128
  raise NotImplementedError
147
129
  end
148
130
 
@@ -156,11 +138,12 @@ module ConnectorsSdk
156
138
  ConnectorsShared::ExceptionTracking.capture_exception(office365_client_error, options)
157
139
  end
158
140
 
159
- def yield_drive_items(drive_id, drive_owner_name:, drive_name:, break_after_page: false, &block)
160
- client.list_items(drive_id, break_after_page: break_after_page) do |item|
141
+ def yield_drive_items(drive_id, drive_owner_name:, drive_name:, site_name:, &block)
142
+ client.list_items(drive_id) do |item|
161
143
  yield_single_document_change(:identifier => "Office365 change: #{item&.id} (#{Office365::Adapter::GraphItem.get_path(item)})") do
162
144
  item.drive_owner_name = drive_owner_name
163
145
  item.drive_name = drive_name
146
+ item.site_name = site_name
164
147
  yield_create_or_update(drive_id, item, &block)
165
148
  end
166
149
  end
@@ -170,15 +153,16 @@ module ConnectorsSdk
170
153
  if item.deleted.nil?
171
154
  yield_create_or_update(drive_id, item, &block)
172
155
  else
173
- yield :delete, convert_id_to_fp_id(item.id)
156
+ yield :delete, convert_id_to_es_id(item.id)
174
157
  end
175
158
  end
176
159
 
177
- def yield_changes(drive_id, drive_owner_name:, drive_name:, start_delta_link: nil, last_modified: nil, break_after_page: false, &block)
178
- client.list_changes(:drive_id => drive_id, :start_delta_link => start_delta_link, :last_modified => last_modified, :break_after_page => break_after_page) do |item|
160
+ def yield_changes(drive_id, drive_owner_name:, drive_name:, site_name:, start_delta_link: nil, last_modified: nil, &block)
161
+ client.list_changes(:drive_id => drive_id, :start_delta_link => start_delta_link, :last_modified => last_modified) do |item|
179
162
  yield_single_document_change(:identifier => "Office365 change: #{item&.id} (#{Office365::Adapter::GraphItem.get_path(item)})") do
180
163
  item.drive_owner_name = drive_owner_name
181
164
  item.drive_name = drive_name
165
+ item.site_name = site_name
182
166
  yield_correct_actions_and_converted_item(drive_id, item, &block)
183
167
  end
184
168
  end
@@ -210,11 +194,11 @@ module ConnectorsSdk
210
194
 
211
195
  def generate_document(item)
212
196
  if item.file
213
- adapter.swiftype_document_from_file(item)
197
+ adapter.es_document_from_file(item)
214
198
  elsif item.folder
215
- adapter.swiftype_document_from_folder(item)
199
+ adapter.es_document_from_folder(item)
216
200
  elsif item.package
217
- adapter.swiftype_document_from_package(item)
201
+ adapter.es_document_from_package(item)
218
202
  else
219
203
  raise "Unexpected Office 365 item type for item #{item}"
220
204
  end
@@ -10,36 +10,48 @@ require 'connectors_sdk/office365/adapter'
10
10
 
11
11
  module ConnectorsSdk
12
12
  module SharePoint
13
+ module SitePrefix
14
+ def get_path(item)
15
+ item.site_name.present? ? "/sites/#{item.site_name}#{super}" : super
16
+ end
17
+ end
18
+
13
19
  class Adapter < Office365::Adapter
14
20
  generate_id_helpers :share_point, 'share_point'
15
21
 
16
- def self.swiftype_document_from_file(file)
17
- FileGraphItem.new(file).to_swiftype_document
22
+ def self.es_document_from_file(file)
23
+ FileGraphItem.new(file).to_es_document
18
24
  end
19
25
 
20
- def self.swiftype_document_from_folder(folder)
21
- FolderGraphItem.new(folder).to_swiftype_document
26
+ def self.es_document_from_folder(folder)
27
+ FolderGraphItem.new(folder).to_es_document
22
28
  end
23
29
 
24
- def self.swiftype_document_from_package(package)
25
- PackageGraphItem.new(package).to_swiftype_document
30
+ def self.es_document_from_package(package)
31
+ PackageGraphItem.new(package).to_es_document
26
32
  end
27
33
 
28
34
  class FileGraphItem < Office365::Adapter::FileGraphItem
29
- def self.convert_id_to_fp_id(id)
30
- ConnectorsSdk::SharePoint::Adapter.share_point_id_to_fp_id(id)
35
+ include SitePrefix
36
+
37
+ def self.convert_id_to_es_id(id)
38
+ ConnectorsSdk::SharePoint::Adapter.share_point_id_to_es_id(id)
31
39
  end
32
40
  end
33
41
 
34
42
  class FolderGraphItem < Office365::Adapter::FolderGraphItem
35
- def self.convert_id_to_fp_id(id)
36
- ConnectorsSdk::SharePoint::Adapter.share_point_id_to_fp_id(id)
43
+ include SitePrefix
44
+
45
+ def self.convert_id_to_es_id(id)
46
+ ConnectorsSdk::SharePoint::Adapter.share_point_id_to_es_id(id)
37
47
  end
38
48
  end
39
49
 
40
50
  class PackageGraphItem < Office365::Adapter::PackageGraphItem
41
- def self.convert_id_to_fp_id(id)
42
- ConnectorsSdk::SharePoint::Adapter.share_point_id_to_fp_id(id)
51
+ include SitePrefix
52
+
53
+ def self.convert_id_to_es_id(id)
54
+ ConnectorsSdk::SharePoint::Adapter.share_point_id_to_es_id(id)
43
55
  end
44
56
  end
45
57
  end