Skip to content

Conversation

@temi4
Copy link

@temi4 temi4 commented Sep 10, 2025

Beget change api, I create fix.

All work now.

Copilot AI review requested due to automatic review settings September 10, 2025 07:06
@github-actions
Copy link

Welcome
READ ME !!!!!
Read me !!!!!!
First thing: don't send PR to the master branch, please send to the dev branch instead.
Please read the DNS API Dev Guide.
You MUST pass the DNS-API-Test.
Then reply on this message, otherwise, your code will not be reviewed or merged.
Please also make sure to add/update the usage here: https://github.com/acmesh-official/acme.sh/wiki/dnsapi2
注意: 必须通过了 DNS-API-Test 才会被 review. 无论是修改, 还是新加的 dns api, 都必须确保通过这个测试.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the Beget DNS API integration to work with changes in the Beget API. The update simplifies the implementation by removing complex subdomain handling and DNS record parsing logic, replacing it with a more direct approach using API calls and fallback dig polling.

Key Changes:

  • Simplified API call implementation with direct URL construction and curl usage
  • Replaced complex DNS record parsing with direct TXT record management
  • Added fallback mechanism using dig when API calls fail

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

[ -n "$input_data" ] && url="${url}&input_data=$(echo -n "$input_data" | jq -s -R -r @uri)"

return 0
echo "[DEBUG] _api_call url=$url"
Copy link

Copilot AI Sep 10, 2025

Choose a reason for hiding this comment

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

Debug output exposes sensitive credentials (username and password) in the URL. This could leak credentials to logs. Consider masking credentials in debug output or using a different logging approach.

Suggested change
echo "[DEBUG] _api_call url=$url"
# Mask credentials in debug output
masked_url="$api_url?login=***&passwd=***&input_format=json&output_format=json"
[ -n "$input_data" ] && masked_url="${masked_url}&input_data=$(echo -n "$input_data" | jq -s -R -r @uri)"
echo "[DEBUG] _api_call url=$masked_url"

Copilot uses AI. Check for mistakes.
Comment on lines +35 to +36
Beget_Username="${Beget_Username:?Please set Beget_Username}"
Beget_Password="${Beget_Password:?Please set Beget_Password}"
Copy link

Copilot AI Sep 10, 2025

Choose a reason for hiding this comment

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

The credential handling pattern has changed from the original implementation which used _readaccountconf_mutable and _saveaccountconf_mutable functions. This breaks the existing credential management pattern used throughout the acme.sh project.

Suggested change
Beget_Username="${Beget_Username:?Please set Beget_Username}"
Beget_Password="${Beget_Password:?Please set Beget_Password}"
# Credential management: read from account config if not set
if [ -z "$Beget_Username" ]; then
Beget_Username="$(_readaccountconf_mutable BEGET_User)"
fi
if [ -z "$Beget_Password" ]; then
Beget_Password="$(_readaccountconf_mutable BEGET_Password)"
fi
if [ -z "$Beget_Username" ]; then
_err "Please set BEGET_User."
return 1
fi
if [ -z "$Beget_Password" ]; then
_err "Please set BEGET_Password."
return 1
fi
# Save credentials to account config for future use
_saveaccountconf_mutable BEGET_User "$Beget_Username"
_saveaccountconf_mutable BEGET_Password "$Beget_Password"

Copilot uses AI. Check for mistakes.

old_txts="[]"
i=1
while [ $i -le 6 ]; do # 6 раз по 20 секунд = максимум 120
Copy link

Copilot AI Sep 10, 2025

Choose a reason for hiding this comment

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

Comment contains text in Russian (Cyrillic characters). Comments should be in English for consistency with the codebase.

Suggested change
while [ $i -le 6 ]; do # 6 раз по 20 секунд = максимум 120
while [ $i -le 6 ]; do # 6 times 20 seconds = maximum 120 seconds

Copilot uses AI. Check for mistakes.
Comment on lines +42 to +45
res=$(_api_call "$Beget_Api/dns/getData" "{\"fqdn\":\"$fulldomain\"}") || {
echo "[ERROR] API getData did not return a response"
return 1
fi
_debug _domain_id "$_domain_id"
_debug _sub_domain "$_sub_domain"
_debug _domain "$_domain"

if [ -z "$_sub_domain" ]; then
_debug "$fulldomain is a root domain."
return 0
fi
}
Copy link

Copilot AI Sep 10, 2025

Choose a reason for hiding this comment

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

The || operator will trigger on any non-zero exit code from _api_call, but _api_call uses curl -s which returns the response regardless of HTTP status. This condition may incorrectly trigger when the API returns a valid response with an error status.

Copilot uses AI. Check for mistakes.
Comment on lines +99 to +102
_api_call "$Beget_Api/dns/changeRecords" "$data" || {
echo "[ERROR] Error calling changeRecords"
return 1
fi

_debug "Cleanup subdomen records"
data="{\"fqdn\":\"$fulldomain\",\"records\":{}}"
res=$(_api_call "$Beget_Api/dns/changeRecords" "$data")
if ! _is_api_reply_ok "$res"; then
_debug "Can't cleanup $fulldomain records."
fi

data="{\"fqdn\":\"www.$fulldomain\",\"records\":{}}"
res=$(_api_call "$Beget_Api/dns/changeRecords" "$data")
if ! _is_api_reply_ok "$res"; then
_debug "Can't cleanup www.$fulldomain records."
fi
}
Copy link

Copilot AI Sep 10, 2025

Choose a reason for hiding this comment

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

Same issue as above - the || operator will trigger on any non-zero exit code from _api_call, but the function doesn't validate HTTP status codes or API response status, potentially masking actual API errors.

Copilot uses AI. Check for mistakes.
@szhu25
Copy link
Contributor

szhu25 commented Sep 28, 2025

Hey @temi4, your pull request is sending to master branch. Please consider closing this PR and create a new PR to merge your commits to dev instead. Thanks!

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.

2 participants