Conversation
WalkthroughMultiple new Kconfig project build configuration files were added across several HTTP example projects, each defining string options for API credentials and WiFi parameters. Corresponding main application source files were updated to replace hardcoded sensitive strings with configuration macros, enabling build-time configurability without altering program logic. Changes
Poem
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (5)
examples/http/http_xunfei_xinghuo/main/Kconfig.projbuild (4)
3-8: Avoid placeholder defaults for sensitive API keys.
Using"xf_api_key"as a default may lead to accidental use of dummy credentials in production builds. Consider setting an empty default (default "") to force explicit input of a real API key at build time.
9-14: Avoid placeholder defaults for API secrets.
Similarly,"xf_api_secret"should be replaced with an empty default to ensure a real secret is always provided and to prevent accidental usage of dummy values.
15-20: Require explicit WiFi SSID input.
Hardcoding"my_wifi_ssid"may not suit all users. Usingdefault ""will prompt users to specify their actual SSID, reducing build-time surprises.
21-26: Require explicit WiFi password input.
As with the SSID, replace"my_wifi_pswd"with an empty default to enforce user-supplied credentials and avoid shipping example passwords.examples/http/http_xunfei_xinghuo/main/main.c (1)
38-38: Leverage Kconfig macros for WiFi parameters.
Great replacement of hardcoded SSID and password withCONFIG_EXAMPLE_WIFI_SSIDandCONFIG_EXAMPLE_WIFI_PSWD. For full type safety, consider updating theapp_wifi_initprototype to acceptconst char *ssid, const char *pswd.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
examples/http/http_xunfei_xinghuo/main/Kconfig.projbuild(1 hunks)examples/http/http_xunfei_xinghuo/main/main.c(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
examples/http/http_xunfei_xinghuo/main/main.c (2)
examples/http/http_xunfei_xinghuo/main/app_wifi/app_wifi.c (1)
app_wifi_init(34-70)examples/http/http_xunfei_xinghuo/main/app_wifi/include/app_wifi.h (1)
app_wifi_init(9-9)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build
🔇 Additional comments (2)
examples/http/http_xunfei_xinghuo/main/Kconfig.projbuild (2)
1-2: Menu grouping is correctly defined.
Indentation and themenu "Example Configuration"/endmenublock are properly set up, providing a clear namespace for these options.
27-27: Configuration block closure is correct.
Theendmenumarker cleanly terminates the example configuration section.
| char *xf_key = CONFIG_EXAMPLE_XF_KEY; | ||
| char *xf_secret = CONFIG_EXAMPLE_XF_SECRET; |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Prefer const char * for configuration strings.
Since CONFIG_EXAMPLE_XF_KEY and CONFIG_EXAMPLE_XF_SECRET expand to string literals, declaring these as const char * (instead of char *) will avoid deprecated conversion warnings and clearly signal immutability.
🤖 Prompt for AI Agents
In examples/http/http_xunfei_xinghuo/main/main.c at lines 10 to 11, change the
declarations of xf_key and xf_secret from char * to const char * to reflect that
these variables point to string literals. This will prevent deprecated
conversion warnings and indicate that the strings should not be modified.
baac98f to
16cf744
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
examples/http/http_aliyun_tongyiqianwen/main/main.c (1)
16-16: Excellent security improvement by externalizing the API key.Replacing the hardcoded empty string with
CONFIG_EXAMPLE_TONGYI_KEYprevents credentials from being exposed in source code.However, consider adding validation to ensure the key is properly configured:
-char *key = CONFIG_EXAMPLE_TONGYI_KEY; +char *key = CONFIG_EXAMPLE_TONGYI_KEY; + +void validate_config(void) { + if (strlen(key) == 0) { + ESP_LOGE(TAG, "TONGYI_KEY not configured! Please set CONFIG_EXAMPLE_TONGYI_KEY in menuconfig"); + abort(); + } +}examples/http/http_kimi/main/main.c (1)
36-36: WiFi credential externalization follows security best practices.The consistent replacement of hardcoded WiFi credentials with configuration macros across multiple examples demonstrates good security hygiene.
Consider adding early validation in
app_main()to catch configuration issues:void app_main(void) { + // Validate configuration early + if (strlen(CONFIG_EXAMPLE_WIFI_SSID) == 0 || strlen(CONFIG_EXAMPLE_KIMI_KEY) == 0) { + ESP_LOGE(TAG, "Configuration incomplete! Please set values in menuconfig"); + return; + } + // Init NVSexamples/http/esp_gpt/main/app_http/app_http_tongyi.c (1)
13-13: Consistent API key externalization across Tongyi implementations.This change matches the pattern established in
examples/http/http_aliyun_tongyiqianwen/main/main.cfor externalizing the Tongyi API key. Since this key is used for HTTP authorization (line 68), ensure it's properly validated during initialization.Consider adding validation in the task function:
void app_http_ask_tongyi_task(void *pvParameters) { + if (strlen(key) == 0) { + ESP_LOGE(TAG, "Tongyi API key not configured"); + vTaskDelete(NULL); + return; + } + xTongyiQuestion = xQueueCreate(10, 1024);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (21)
build_config.yml(1 hunks)examples/http/esp_gpt/main/Kconfig.projbuild(1 hunks)examples/http/esp_gpt/main/app_http/app_http_asr.c(1 hunks)examples/http/esp_gpt/main/app_http/app_http_tongyi.c(1 hunks)examples/http/esp_gpt/main/app_http/app_http_tts.c(1 hunks)examples/http/esp_gpt/main/main.c(1 hunks)examples/http/http_aliyun_tongyiqianwen/main/Kconfig.projbuild(1 hunks)examples/http/http_aliyun_tongyiqianwen/main/main.c(2 hunks)examples/http/http_baidu_access_token/main/Kconfig.projbuild(1 hunks)examples/http/http_baidu_access_token/main/main.c(2 hunks)examples/http/http_baidu_img_classification/main/Kconfig.projbuild(1 hunks)examples/http/http_baidu_img_classification/main/app_baidu/app_baidu.c(1 hunks)examples/http/http_baidu_img_classification/main/main.c(2 hunks)examples/http/http_baidu_speech_recognition/main/Kconfig.projbuild(1 hunks)examples/http/http_baidu_speech_recognition/main/main.c(2 hunks)examples/http/http_baidu_tts/main/Kconfig.projbuild(1 hunks)examples/http/http_baidu_tts/main/main.c(2 hunks)examples/http/http_kimi/main/Kconfig.projbuild(1 hunks)examples/http/http_kimi/main/main.c(2 hunks)examples/http/http_xunfei_xinghuo/main/Kconfig.projbuild(1 hunks)examples/http/http_xunfei_xinghuo/main/main.c(2 hunks)
✅ Files skipped from review due to trivial changes (14)
- examples/http/esp_gpt/main/app_http/app_http_tts.c
- examples/http/http_baidu_img_classification/main/main.c
- examples/http/http_baidu_access_token/main/main.c
- examples/http/http_baidu_img_classification/main/app_baidu/app_baidu.c
- examples/http/http_baidu_speech_recognition/main/main.c
- examples/http/esp_gpt/main/app_http/app_http_asr.c
- examples/http/http_baidu_tts/main/Kconfig.projbuild
- build_config.yml
- examples/http/http_aliyun_tongyiqianwen/main/Kconfig.projbuild
- examples/http/http_baidu_img_classification/main/Kconfig.projbuild
- examples/http/http_baidu_speech_recognition/main/Kconfig.projbuild
- examples/http/http_baidu_access_token/main/Kconfig.projbuild
- examples/http/esp_gpt/main/Kconfig.projbuild
- examples/http/http_kimi/main/Kconfig.projbuild
🚧 Files skipped from review as they are similar to previous changes (2)
- examples/http/http_xunfei_xinghuo/main/main.c
- examples/http/http_xunfei_xinghuo/main/Kconfig.projbuild
🧰 Additional context used
🧬 Code Graph Analysis (2)
examples/http/esp_gpt/main/main.c (2)
examples/http/esp_gpt/main/app_wifi/app_wifi.c (1)
app_wifi_init(33-69)examples/http/esp_gpt/main/app_wifi/include/app_wifi.h (1)
app_wifi_init(20-20)
examples/http/http_baidu_tts/main/main.c (2)
examples/http/http_baidu_tts/main/app_wifi/app_wifi.c (1)
app_wifi_init(34-70)examples/http/http_baidu_tts/main/app_wifi/include/app_wifi.h (1)
app_wifi_init(9-9)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build
🔇 Additional comments (6)
examples/http/http_baidu_tts/main/main.c (3)
19-19: Consider the impact of changing the TTS text content.The text has been changed from Chinese ("早上好,下午好,晚上好") to English ("Good morning"). While this makes the example more universally accessible, it represents a functional change rather than just a configuration improvement.
Consider whether this text should also be configurable via Kconfig to allow users to customize the TTS content at build time:
-char *text = "Good morning"; +char *text = CONFIG_EXAMPLE_TTS_TEXT;
47-47:Details
✅ Verification successful
Excellent security enhancement for WiFi credentials.
Replacing hardcoded WiFi credentials with configuration macros significantly improves security and makes the example more reusable. The
app_wifi_initfunction properly handles these parameters as confirmed by the relevant code snippets.
🏁 Script executed:
#!/bin/bash # Verify that the WiFi configuration macros are defined in Kconfig files fd -e projbuild -x cat {} | rg -A 5 -B 5 "EXAMPLE_WIFI_(SSID|PSWD)"Length of output: 3129
WiFi credential configuration macros verified
The
EXAMPLE_WIFI_SSIDandEXAMPLE_WIFI_PSWDsymbols are properly defined (with defaults and help texts) in each example’sKconfig.projbuild. No further changes are required—these macros ensure secure and reusable WiFi credential handling.
17-17:Details
✅ Verification successful
Good security improvement, but verify the configuration macro is defined.
Moving the access token from a hardcoded value to a configurable macro is a significant security improvement. However, ensure that
CONFIG_EXAMPLE_ACCESS_TOKENis properly defined in the corresponding Kconfig file.
🏁 Script executed:
#!/bin/bash # Verify that the CONFIG_EXAMPLE_ACCESS_TOKEN macro is defined in Kconfig files fd -e projbuild -x cat {} | rg -A 5 -B 5 "EXAMPLE_ACCESS_TOKEN"Length of output: 990
Verified CONFIG_EXAMPLE_ACCESS_TOKEN definition in Kconfig
The
CONFIG_EXAMPLE_ACCESS_TOKENoption is properly declared in the example’s Kconfig:config EXAMPLE_ACCESS_TOKEN string "Baidu Access Token" default "baidu_access_token" help Access token for baidu.No further action needed—security improvement confirmed and ready to merge.
examples/http/http_aliyun_tongyiqianwen/main/main.c (1)
80-80:Details
✅ Verification successful
Good security practice replacing hardcoded WiFi credentials.
The change from hardcoded WiFi credentials to configurable macros improves security and flexibility.
Ensure the WiFi configuration values are validated before use:
If the Kconfig file exists, check that it defines the required configuration options:
🏁 Script executed:
#!/bin/bash # Verify that corresponding Kconfig.projbuild files exist and define the required macros fd -t f "Kconfig.projbuild" examples/http/http_aliyun_tongyiqianwen/Length of output: 131
🏁 Script executed:
#!/bin/bash # Check if the required config options are defined in Kconfig files rg -A 3 "EXAMPLE_WIFI_SSID|EXAMPLE_WIFI_PSWD|EXAMPLE_TONGYI_KEY" examples/http/http_aliyun_tongyiqianwen/Length of output: 2062
Configuration Macros Validated – Approval Granted
The
examples/http/http_aliyun_tongyiqianwen/main/Kconfig.projbuildfile correctly declaresEXAMPLE_WIFI_SSID,EXAMPLE_WIFI_PSWD, andEXAMPLE_TONGYI_KEY. The switch from hardcoded Wi-Fi credentials to these configurable macros is a solid security improvement.No changes are required here. As a best practice, you may still want to add a simple runtime check that both
CONFIG_EXAMPLE_WIFI_SSIDandCONFIG_EXAMPLE_WIFI_PSWDare non-empty before invoking:app_wifi_init(CONFIG_EXAMPLE_WIFI_SSID, CONFIG_EXAMPLE_WIFI_PSWD);examples/http/http_kimi/main/main.c (1)
11-11: Consistent security improvement with Kimi API key externalization.This change aligns with the broader pattern across the PR to externalize sensitive credentials from source code.
examples/http/esp_gpt/main/main.c (1)
61-61: Critical security fix removing hardcoded WiFi credentials.This change removes actual hardcoded WiFi credentials ("ChinaUnicom-3LRNAS", "244244244") from the source code, which is a significant security improvement. The
app_wifi_initfunction signature fromexamples/http/esp_gpt/main/app_wifi/include/app_wifi.h(line 20) correctly accepts string parameters, ensuring compatibility with the configuration macros.
Summary by CodeRabbit
New Features
Refactor