allow temporary credential overrides with api calls for multi-cloud c…#446
Open
ojhilt wants to merge 1 commit into
Open
allow temporary credential overrides with api calls for multi-cloud c…#446ojhilt wants to merge 1 commit into
ojhilt wants to merge 1 commit into
Conversation
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.
…odebases
Brief Summary of Changes
Summary
Adds a
cloudinary_configkeyword argument to all SDK API functions (Admin API, Upload API, Provisioning API). When provided, its values are used as configuration overrides for that single call only. The globalcloudinary.config()singleton is never mutated.Closes #445
Motivation
The current SDK configuration model uses a module-level singleton (
cloudinary._config). Any call tocloudinary.config(cloud_name=..., api_key=..., api_secret=...)overwrites this singleton in place. In a multi-threaded or async server handling requests for multiple Cloudinary accounts, concurrent requests can read each other's credentials, causing assets to be uploaded to the wrong account or authentication errors.How it works
A new helper function
consume_cloudinary_config(options)is added tocloudinary/utils.py. When called, it:cloudinary_configdict from the options dict (so it is never forwarded to the HTTP layer).cloudinary_configtooptionsviasetdefault— meaning explicit per-call options always win, and the global config is the final fallback.This function is called at the entry point of every low-level API dispatch function:
cloudinary/api_client/call_api.py_call_apicloudinary/api_client/call_account_api.py_call_account_api,_call_public_account_api,_execute_account_requestcloudinary/uploader.pyupload,upload_large,upload_large_part,call_api,call_cacheable_api,_upload_large_part_with_auth_retrycloudinary/utils.pysign_request,build_distribution_domain,base_api_url,build_upload_paramsUsage
Upload API:
Admin API:
Provisioning API:
Any field accepted by
cloudinary.config()(e.g.upload_prefix,secure,oauth_token) can be passed this way.Changes
cloudinary/utils.pyCLOUDINARY_CONFIG_OPTIONconstant andconsume_cloudinary_config()helper; call it insign_request,build_distribution_domain,base_api_url,build_upload_paramscloudinary/api_client/call_api.pyconsume_cloudinary_configat entry of_call_apicloudinary/api_client/call_account_api.pyconsume_cloudinary_configat entry of each account API dispatch functioncloudinary/uploader.pyconsume_cloudinary_configat entry of upload and call helper functionstest/test_api_authorization.pytest_temporary_config_admin_apiandtest_temporary_config_upload_apitest/test_provisioning_api.pytest_temporary_config_account_apiREADME.mdTesting
All new tests use the mocked urllib3 transport so no live credentials are required:
test_temporary_config_admin_api— verifies credentials andcloud_namefromcloudinary_configare used in the Admin API request; asserts global config is unchanged after the call.test_temporary_config_upload_api— verifies credentials,cloud_name, andupload_presetfromcloudinary_configare applied in the Upload API request; asserts global config is unchanged.test_temporary_config_account_api— verifiesaccount_id,provisioning_api_key,provisioning_api_secret, andupload_prefixfromcloudinary_configare applied in the Provisioning API request; asserts global account config is unchanged.Backwards compatibility
Fully backwards compatible. The
cloudinary_configkey is only consumed when explicitly provided. All existing call signatures are unchanged. Global config behaviour is identical whencloudinary_configis not passed.What does this PR address?
Are tests included?
Checklist: