Refactor connector profile updates

This commit is contained in:
2026-07-21 18:16:55 +02:00
parent 1401c78c8a
commit 1069f85796
2 changed files with 236 additions and 10 deletions

View File

@@ -188,18 +188,80 @@ def update_connector_profile_row(
clear_password: bool = False,
clear_token: bool = False,
) -> FileConnectorProfile:
_validate_profile_update_references(
row,
password_env=password_env,
token_env=token_env,
secret_ref=secret_ref,
metadata=metadata,
)
_update_profile_connection_fields(
row,
label=label,
provider=provider,
endpoint_url=endpoint_url,
base_path=base_path,
enabled=enabled,
credential_profile_id=credential_profile_id,
credential_mode=credential_mode,
)
_update_profile_credential_fields(
row,
username=username,
password=password,
token=token,
password_env=password_env,
token_env=token_env,
secret_ref=secret_ref,
clear_password=clear_password,
clear_token=clear_token,
)
_update_profile_governance_fields(
row,
capabilities=capabilities,
policy=policy,
metadata=metadata,
)
row.updated_by_user_id = user_id
session.add(row)
session.flush()
return row
def _validate_profile_update_references(
row: FileConnectorProfile,
*,
password_env: str | None,
token_env: str | None,
secret_ref: str | None,
metadata: Mapping[str, Any] | None,
) -> None:
reject_api_controlled_deployment_references(
password_env=password_env,
token_env=token_env,
secret_ref=secret_ref,
metadata=metadata,
)
if secret_ref is not None and _clean(secret_ref) != _clean(row.secret_ref):
if _clean(row.secret_ref):
raise FileStorageError(
"An existing external secret reference cannot be replaced or cleared until Files can prove "
"provider ownership and confirm provider-side deletion"
)
if secret_ref is None or _clean(secret_ref) == _clean(row.secret_ref):
return
if _clean(row.secret_ref):
raise FileStorageError(
"An existing external secret reference cannot be replaced or cleared until Files can prove "
"provider ownership and confirm provider-side deletion"
)
def _update_profile_connection_fields(
row: FileConnectorProfile,
*,
label: str | None,
provider: str | None,
endpoint_url: str | None,
base_path: str | None,
enabled: bool | None,
credential_profile_id: str | None,
credential_mode: str | None,
) -> None:
if label is not None:
row.label = _normalize_label(label)
if provider is not None:
@@ -214,6 +276,20 @@ def update_connector_profile_row(
row.credential_profile_id = _clean(credential_profile_id)
if credential_mode is not None:
row.credential_mode = _normalize_credential_mode(credential_mode)
def _update_profile_credential_fields(
row: FileConnectorProfile,
*,
username: str | None,
password: str | None,
token: str | None,
password_env: str | None,
token_env: str | None,
secret_ref: str | None,
clear_password: bool,
clear_token: bool,
) -> None:
if username is not None:
row.username = _clean(username)
if password is not None:
@@ -230,16 +306,21 @@ def update_connector_profile_row(
row.token_env = _clean(token_env)
if secret_ref is not None:
row.secret_ref = _clean(secret_ref)
def _update_profile_governance_fields(
row: FileConnectorProfile,
*,
capabilities: list[str] | None,
policy: Mapping[str, Any] | None,
metadata: Mapping[str, Any] | None,
) -> None:
if capabilities is not None:
row.capabilities = _string_list(capabilities)
if policy is not None:
row.policy = dict(policy)
if metadata is not None:
row.metadata_ = dict(metadata)
row.updated_by_user_id = user_id
session.add(row)
session.flush()
return row
def _normalize_scope(*, tenant_id: str, scope_type: str, scope_id: str | None) -> tuple[str, str | None, str | None]: