feat: add copy_and_replace_credentials convenience method to FlowsResource#15
Merged
saksham-nexla merged 2 commits intomainfrom Mar 7, 2026
Merged
Conversation
…ource Adds a new method that copies a flow and replaces credentials on specified resources in a single call. The mapping uses original resource IDs (source/sink) as keys and new credential IDs as values. Resources not in the mapping keep their original credentials. Co-Authored-By: abhijit.bharadwaj <abhijit.bharadwaj@nexla.com>
Contributor
Author
|
Prompt hidden (unlisted session) |
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
saksham-nexla
approved these changes
Mar 6, 2026
Member
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
Co-Authored-By: abhijit.bharadwaj <abhijit.bharadwaj@nexla.com>
saksham-nexla
added a commit
that referenced
this pull request
Mar 22, 2026
Merges 3 PRs from main: - #13: Make DataMapInfo.description and NotificationSetting.resource_id optional - #14: Add monitoring endpoint methods with explicit params for MCP integration - #15: Add copy_and_replace_credentials convenience method to FlowsResource Resolved conflicts in base_resource.py, metrics.py, organizations.py, and users.py by keeping branch's additional methods while incorporating main's enhanced audit_log params and new monitoring methods.
saksham-nexla
added a commit
that referenced
this pull request
Mar 22, 2026
Add 36 new tests (29 Python, 7 TypeScript) covering methods from merged PRs #13, #14, #15 and their TS SDK mirrors: Python: - base_resource get_audit_log filter/pagination params (6 tests) - metrics publish_raw, resource_flow_metrics, flow_metrics_summary (4) - organizations audit_log explicit params, flow_status_metrics (5) - users audit_log params, account_metrics aggregate, flow_status_metrics (6) - flows get_flow_logs, search_flow_logs, active_flows_metrics, run_status (8) TypeScript: - flows copy_and_replace_credentials edge cases (3) - organizations/users audit_log query params and empty responses (4)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat: add
copy_and_replace_credentialsconvenience method to FlowsResourceSummary
Adds a new convenience method
FlowsResource.copy_and_replace_credentials()that copies a flow and replaces credentials on specified resources in a single call.The method accepts a
resource_credential_mapping: Dict[int, int]where keys are original source/sink IDs and values are the new credential IDs to assign. Internally it:reuse_data_credentials=True(so copied resources keep their original creds)data_sourcesanddata_sinksin the copy response, matching viacopied_from_idsources.update()/destinations.update()for each matched resourceclient.projects.add_flows()Resources not in the mapping are left untouched. The
reuse_data_credentialsflag is always forcedTrueregardless of user-suppliedcopy_options.Six unit tests cover: full source+sink replacement, partial mapping (unmapped sinks left alone), copy option preservation, empty mapping (pure copy, no updates), target project assignment, and no-project default behavior.
Updates since last revision
target_project_id: Optional[int] = Noneparameter tocopy_and_replace_credentials().target_project_idis set, the method callsself.client.projects.add_flows(target_project_id, ProjectFlowList(flows=[origin_node_id]))after credential replacement to move the copied flow into the specified project.ProjectFlowListimport fromnexla_sdk.models.projects.requests.test_copy_and_replace_credentials_with_target_projectandtest_copy_and_replace_credentials_no_target_project.Review & Testing Checklist for Human
copied_from_idis reliably populated by the real API on flow copy responses. The method silently skips resources wherecopied_from_id is None— if the API doesn't always set this field, credential replacement will silently not happen. This is the highest-risk assumption and is not verifiable from unit tests alone.add_flowscall fails, the copied flow exists in an intermediate state (some credentials updated, possibly not in target project). There is no rollback. Decide if this is acceptable or if error handling/documentation should be added.copied_flow.flows[0]index access on line 263 — will raiseIndexErrorif the copy response returns an emptyflowslist. Unlikely in practice, but unguarded. Note this is now reached unconditionally (moved before thetarget_project_idcheck) so it affects all calls, not just project-move calls.origin_node_idis the correct identifier forProjectFlowList.flows. The method passesorigin_node_idtoadd_flows()— confirm this matches what the admin API expects for adding flows to a project.Notes