Skip to content

Commit be25b1e

Browse files
authored
perm sync validation framework (#4958)
* perm synce validation framework * frontend fixes * validate perm sync when getting runner * attempt to fix integration tests * added new file * oops * skipping salesforce test due to creds * add todo
1 parent 2044934 commit be25b1e

File tree

17 files changed

+97
-20
lines changed

17 files changed

+97
-20
lines changed

backend/ee/onyx/background/celery/tasks/doc_permission_syncing/tasks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ def connector_permission_sync_generator_task(
425425
created = validate_ccpair_for_user(
426426
cc_pair.connector.id,
427427
cc_pair.credential.id,
428+
cc_pair.access_type,
428429
db_session,
429430
enforce_creation=False,
430431
)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from onyx.connectors.confluence.connector import ConfluenceConnector
2+
from onyx.connectors.google_drive.connector import GoogleDriveConnector
3+
from onyx.connectors.interfaces import BaseConnector
4+
5+
6+
def validate_confluence_perm_sync(connector: ConfluenceConnector) -> None:
7+
"""
8+
Validate that the connector is configured correctly for permissions syncing.
9+
"""
10+
11+
12+
def validate_drive_perm_sync(connector: GoogleDriveConnector) -> None:
13+
"""
14+
Validate that the connector is configured correctly for permissions syncing.
15+
"""
16+
17+
18+
def validate_perm_sync(connector: BaseConnector) -> None:
19+
"""
20+
Override this if your connector needs to validate permissions syncing.
21+
Raise an exception if invalid, otherwise do nothing.
22+
23+
Default is a no-op (always successful).
24+
"""
25+
if isinstance(connector, ConfluenceConnector):
26+
validate_confluence_perm_sync(connector)
27+
elif isinstance(connector, GoogleDriveConnector):
28+
validate_drive_perm_sync(connector)

backend/onyx/background/indexing/run_indexing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ def _get_connector_runner(
103103
# validate the connector settings
104104
if not INTEGRATION_TESTS_MODE:
105105
runnable_connector.validate_connector_settings()
106+
if attempt.connector_credential_pair.access_type == AccessType.SYNC:
107+
runnable_connector.validate_perm_sync()
106108

107109
except UnexpectedValidationError as e:
108110
logger.exception(

backend/onyx/connectors/factory.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
from onyx.db.connector import fetch_connector_by_id
6161
from onyx.db.credentials import backend_update_credential_json
6262
from onyx.db.credentials import fetch_credential_by_id
63+
from onyx.db.enums import AccessType
6364
from onyx.db.models import Credential
6465
from shared_configs.contextvars import get_current_tenant_id
6566

@@ -193,6 +194,7 @@ def instantiate_connector(
193194
def validate_ccpair_for_user(
194195
connector_id: int,
195196
credential_id: int,
197+
access_type: AccessType,
196198
db_session: Session,
197199
enforce_creation: bool = True,
198200
) -> bool:
@@ -235,4 +237,6 @@ def validate_ccpair_for_user(
235237
return False
236238

237239
runnable_connector.validate_connector_settings()
240+
if access_type == AccessType.SYNC:
241+
runnable_connector.validate_perm_sync()
238242
return True

backend/onyx/connectors/interfaces.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from onyx.connectors.models import Document
1616
from onyx.connectors.models import SlimDocument
1717
from onyx.indexing.indexing_heartbeat import IndexingHeartbeatInterface
18+
from onyx.utils.variable_functionality import fetch_ee_implementation_or_noop
1819

1920
SecondsSinceUnixEpoch = float
2021

@@ -59,6 +60,18 @@ def validate_connector_settings(self) -> None:
5960
Default is a no-op (always successful).
6061
"""
6162

63+
def validate_perm_sync(self) -> None:
64+
"""
65+
Don't override this; add a function to perm_sync_valid.py in the ee package
66+
to do permission sync validation
67+
"""
68+
validate_connector_settings_fn = fetch_ee_implementation_or_noop(
69+
"onyx.connectors.perm_sync_valid",
70+
"validate_perm_sync",
71+
noop_return_value=None,
72+
)
73+
validate_connector_settings_fn(self)
74+
6275
def set_allow_images(self, value: bool) -> None:
6376
"""Implement if the underlying connector wants to skip/allow image downloading
6477
based on the application level image analysis setting."""

backend/onyx/server/documents/cc_pair.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,9 @@ def associate_credential_to_connector(
466466
)
467467

468468
try:
469-
validate_ccpair_for_user(connector_id, credential_id, db_session)
469+
validate_ccpair_for_user(
470+
connector_id, credential_id, metadata.access_type, db_session
471+
)
470472

471473
response = add_credential_to_connector(
472474
db_session=db_session,

backend/onyx/server/documents/connector.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,7 @@ def create_connector_with_mock_credential(
953953
validate_ccpair_for_user(
954954
connector_id=connector_id,
955955
credential_id=credential_id,
956+
access_type=connector_data.access_type,
956957
db_session=db_session,
957958
)
958959
response = add_credential_to_connector(

backend/onyx/server/documents/credential.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def swap_credentials_for_connector(
104104
validate_ccpair_for_user(
105105
credential_swap_req.connector_id,
106106
credential_swap_req.new_credential_id,
107+
credential_swap_req.access_type,
107108
db_session,
108109
)
109110

backend/onyx/server/documents/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def from_connector_db_model(
106106
class CredentialSwapRequest(BaseModel):
107107
new_credential_id: int
108108
connector_id: int
109+
access_type: AccessType
109110

110111

111112
class CredentialDataUpdateRequest(BaseModel):

backend/tests/integration/tests/indexing/test_repeated_error_state.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def test_repeated_error_state_detection_and_recovery(
8686
for ia in index_attempts_page.items
8787
if ia.status and ia.status.is_terminal()
8888
]
89-
if len(index_attempts) == NUM_REPEAT_ERRORS_BEFORE_REPEATED_ERROR_STATE:
89+
if len(index_attempts) >= NUM_REPEAT_ERRORS_BEFORE_REPEATED_ERROR_STATE:
9090
break
9191

9292
if time.monotonic() - start_time > 180:

0 commit comments

Comments
 (0)