Skip to content

feat: add kconfig for http example Add Kconfig file and update source to use configurable credentials#21

Merged
YanKE01 merged 1 commit intomasterfrom
feat/update_http_example
May 31, 2025
Merged

feat: add kconfig for http example Add Kconfig file and update source to use configurable credentials#21
YanKE01 merged 1 commit intomasterfrom
feat/update_http_example

Conversation

@YanKE01
Copy link
Owner

@YanKE01 YanKE01 commented May 30, 2025

Summary by CodeRabbit

  • New Features

    • Added configuration options for API credentials and WiFi settings across multiple HTTP example projects, enabling users to customize these values during build time.
  • Refactor

    • Updated examples to use configurable parameters for API keys, access tokens, and WiFi credentials instead of hardcoded strings, enhancing flexibility and security.

@coderabbitai
Copy link

coderabbitai bot commented May 30, 2025

Walkthrough

Multiple 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

File(s) Change Summary
examples/http/http_xunfei_xinghuo/main/Kconfig.projbuild, examples/http/esp_gpt/main/Kconfig.projbuild, examples/http/http_aliyun_tongyiqianwen/main/Kconfig.projbuild, examples/http/http_baidu_access_token/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_tts/main/Kconfig.projbuild, examples/http/http_kimi/main/Kconfig.projbuild Added new Kconfig files defining string configuration options for API keys, access tokens, and WiFi SSID/password for each example project.
examples/http/http_xunfei_xinghuo/main/main.c, examples/http/esp_gpt/main/main.c, examples/http/http_aliyun_tongyiqianwen/main/main.c, examples/http/http_baidu_access_token/main/main.c, examples/http/http_baidu_img_classification/main/main.c, examples/http/http_baidu_speech_recognition/main/main.c, examples/http/http_baidu_tts/main/main.c, examples/http/http_kimi/main/main.c Replaced hardcoded API credentials and WiFi SSID/password strings with corresponding Kconfig macros for configurable build-time parameters.
examples/http/esp_gpt/main/app_http/app_http_asr.c, examples/http/esp_gpt/main/app_http/app_http_tongyi.c, examples/http/esp_gpt/main/app_http/app_http_tts.c, examples/http/http_baidu_img_classification/main/app_baidu/app_baidu.c Replaced hardcoded access tokens and API keys with configuration macros to use configurable tokens in the HTTP client code.
build_config.yml Added multiple new project entries for HTTP example projects targeting esp32s3 platform with release-v5.4 IDF version.

Poem

In the warren where code bunnies dwell,
We hid our secrets oh-so-well—
No more keys in plain old sight,
Now configs keep them snug and right!
With WiFi and keys tucked away,
Our example hops safely today.
🐇🔑📶

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai bot changed the title feat: add kconfig for http example @coderabbitai feat: add kconfig for http example Add Kconfig file and update source to use configurable credentials May 30, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. Using default "" 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 with CONFIG_EXAMPLE_WIFI_SSID and CONFIG_EXAMPLE_WIFI_PSWD. For full type safety, consider updating the app_wifi_init prototype to accept const char *ssid, const char *pswd.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cc3adf1 and baac98f.

📒 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 the menu "Example Configuration" / endmenu block are properly set up, providing a clear namespace for these options.


27-27: Configuration block closure is correct.
The endmenu marker cleanly terminates the example configuration section.

Comment on lines +10 to +11
char *xf_key = CONFIG_EXAMPLE_XF_KEY;
char *xf_secret = CONFIG_EXAMPLE_XF_SECRET;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ 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.

@YanKE01 YanKE01 force-pushed the feat/update_http_example branch from baac98f to 16cf744 Compare May 30, 2025 11:35
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_KEY prevents 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 NVS
examples/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.c for 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

📥 Commits

Reviewing files that changed from the base of the PR and between baac98f and 16cf744.

📒 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_init function 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_SSID and EXAMPLE_WIFI_PSWD symbols are properly defined (with defaults and help texts) in each example’s Kconfig.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_TOKEN is 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_TOKEN option 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.projbuild file correctly declares EXAMPLE_WIFI_SSID, EXAMPLE_WIFI_PSWD, and EXAMPLE_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_SSID and CONFIG_EXAMPLE_WIFI_PSWD are 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_init function signature from examples/http/esp_gpt/main/app_wifi/include/app_wifi.h (line 20) correctly accepts string parameters, ensuring compatibility with the configuration macros.

@YanKE01 YanKE01 merged commit 42192f1 into master May 31, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant