feat(braze): add support for platform-specific app keys#45
feat(braze): add support for platform-specific app keys#451abhishekpandey wants to merge 11 commits intomasterfrom
Conversation
Add support for androidAppKey configuration option to enable multi-platform app key management. When usePlatformSpecificKeys is enabled, the SDK will prioritize androidAppKey over the deprecated appKey field for Android-specific configurations. This change maintains backward compatibility by falling back to the existing appKey field when platform-specific keys are not configured or the feature flag is disabled. 🔒 Scanned for secrets using gitleaks 8.28.0
Update API_KEY deprecation annotation to include required metadata for Java 9+ compatibility. Set forRemoval to false to explicitly indicate the field will be maintained for backward compatibility indefinitely. Resolves SonarQube issue java:S6355 requiring deprecation metadata for proper API evolution tracking. 🔒 Scanned for secrets using gitleaks 8.28.0
…droid-add-support-for-the-braze-multi-app-key-support 🔒 Scanned for secrets using gitleaks 8.28.0
🔒 Scanned for secrets using gitleaks 8.28.0
…y is empty 🔒 Scanned for secrets using gitleaks 8.28.0
| /** | ||
| * @deprecated Use {@link #ANDROID_APP_KEY} instead. This field is kept for backward compatibility. | ||
| */ |
There was a problem hiding this comment.
Why do we need this deprecation notice? It's not for public consumption.
Moreover, not all destinations must have opted for the new API keys. So, this is still a valid field.
There was a problem hiding this comment.
My main motive was to highlight which key should be preferred by the future maintainers. By marking it as deprecated, we ensure the new platform-specific key would be highlighted. I've also clearly highlighted that this is not going to be removed by setting forRemoval to false (in @Deprecated(since = "2.1.0", forRemoval = false) annotation).
Moreover, not all destinations must have opted for the new API keys. So, this is still a valid field.
I fully agree with this. We ensure full backward compatibility.
Need your final confirmation to understand if it would be better to remove this deprecation annotation!
There was a problem hiding this comment.
Let's not mark it as deprecated. You can add comments in the code to clarify the intention.
| */ | ||
| @Deprecated(since = "2.1.0", forRemoval = false) | ||
| private static final String API_KEY = "appKey"; | ||
| private static final String USE_PLATFORM_SPECIFIC_KEYS = "usePlatformSpecificKeys"; |
There was a problem hiding this comment.
Let's fix this in the config too.
| private static final String USE_PLATFORM_SPECIFIC_KEYS = "usePlatformSpecificKeys"; | |
| private static final String USE_PLATFORM_SPECIFIC_API_KEYS = "usePlatformSpecificApiKeys"; |
🔒 Scanned for secrets using gitleaks 8.28.0
🔒 Scanned for secrets using gitleaks 8.28.0
🔒 Scanned for secrets using gitleaks 8.28.0
🔒 Scanned for secrets using gitleaks 8.28.0
| // Fallback to default app key if either platform-specific key is not present or is set to false | ||
| if (TextUtils.isEmpty(apiKey) && destinationConfig.containsKey(API_KEY)) { | ||
| if (getBoolean(destinationConfig.get(USE_PLATFORM_SPECIFIC_API_KEYS))) { | ||
| RudderLogger.logWarn("BrazeIntegration: usePlatformSpecificApiKeys is enabled but androidApiKey is not configured. Falling back to legacy apiKey."); |
There was a problem hiding this comment.
Let's also include the Android API key in the message.
| RudderLogger.logWarn("BrazeIntegration: usePlatformSpecificApiKeys is enabled but androidApiKey is not configured. Falling back to legacy apiKey."); | |
| RudderLogger.logWarn("BrazeIntegration: Configured to use platform-specific API keys but Android API key is not valid. Falling back to the default API key."); |
There was a problem hiding this comment.
| RudderLogger.logError("Invalid API key. Aborting Braze initialization."); |
| // Prefer platform-specific key if present and not empty | ||
| if (getBoolean(destinationConfig.get(USE_PLATFORM_SPECIFIC_API_KEYS)) | ||
| && destinationConfig.containsKey(ANDROID_API_KEY)) { | ||
| apiKey = (String) destinationConfig.get(ANDROID_API_KEY); | ||
| } | ||
| // Fallback to default app key if either platform-specific key is not present or is set to false | ||
| if (TextUtils.isEmpty(apiKey) && destinationConfig.containsKey(API_KEY)) { | ||
| if (getBoolean(destinationConfig.get(USE_PLATFORM_SPECIFIC_API_KEYS))) { | ||
| RudderLogger.logWarn("BrazeIntegration: usePlatformSpecificApiKeys is enabled but androidApiKey is not configured. Falling back to legacy apiKey."); | ||
| } | ||
| apiKey = (String) destinationConfig.get(API_KEY); | ||
| } |
There was a problem hiding this comment.
@1abhishekpandey can we make it simple?
| // Prefer platform-specific key if present and not empty | |
| if (getBoolean(destinationConfig.get(USE_PLATFORM_SPECIFIC_API_KEYS)) | |
| && destinationConfig.containsKey(ANDROID_API_KEY)) { | |
| apiKey = (String) destinationConfig.get(ANDROID_API_KEY); | |
| } | |
| // Fallback to default app key if either platform-specific key is not present or is set to false | |
| if (TextUtils.isEmpty(apiKey) && destinationConfig.containsKey(API_KEY)) { | |
| if (getBoolean(destinationConfig.get(USE_PLATFORM_SPECIFIC_API_KEYS))) { | |
| RudderLogger.logWarn("BrazeIntegration: usePlatformSpecificApiKeys is enabled but androidApiKey is not configured. Falling back to legacy apiKey."); | |
| } | |
| apiKey = (String) destinationConfig.get(API_KEY); | |
| } | |
| apiKey = defaultApiKey | |
| if (usePlatformSpecificApiKeys) { | |
| if (android api key is valid) { | |
| apiKey = androidApiKey | |
| } else { | |
| log a warning and use default | |
| } | |
| } | |
| if (apiKey is invalid) { | |
| log an eeror | |
| } | |
🔒 Scanned for secrets using gitleaks 8.28.0
🔒 Scanned for secrets using gitleaks 8.28.0
|



Description
This PR adds support for platform-specific app key configuration in the Braze integration, enabling multi-platform app key management. When
usePlatformSpecificApiKeysis enabled, the integration will prioritise the newandroidAppKeyconfiguration field over the legacyappKeyfield. The implementation maintains full backward compatibility by falling back to the existingappKeywhen the feature is not enabled or platform-specific keys are not configured.Type of change
Approach
The implementation introduces two new configuration fields:
androidAppKey: Platform-specific app key for AndroidusePlatformSpecificApiKeys: UI toggle to enable platform-specific key resolutionWhen the UI toggle is enabled and
androidAppKeyis present, the integration will prioritize it over the legacyappKeyfield. If the feature is disabled or the platform-specific key is not configured, the integration falls back to the existingappKeyfield, ensuring full backward compatibility.The legacy
appKeyfield has been marked as deprecated with proper documentation to guide future migrations. (Note: This is an internal field used in the SDK).Impact
appKeycontinue to work without changes