Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

部署到白山云时继续返回 400209 错误 #544

Closed
Anbool opened this issue Mar 22, 2025 · 6 comments · Fixed by #543
Closed

部署到白山云时继续返回 400209 错误 #544

Anbool opened this issue Mar 22, 2025 · 6 comments · Fixed by #543
Labels
bug Something isn't working

Comments

@Anbool
Copy link

Anbool commented Mar 22, 2025

版本号:0.3.5

问题:我注意到似乎已经是数组了,但不知道为什么仍然返回了错误。

日志:
[2025-03-22 14:07:20] ready to deploy ...
[2025-03-22 14:07:21] sdk request 'baishan.GetDomainConfig'
request:
{"domains":"google.com","config":["https"]}
response:
null
[2025-03-22 14:07:21] failed to deploy
[2025-03-22 14:07:21] failed to execute sdk request 'baishan.GetDomainConfig': baishan api error: unexpected status code: 400, {"code":400209,"message":"parameter config must be an array."}

我尝试对接口进行手动构建请求,可以按照预期返回。

示例:
curl 'https://cdn.api.baishan.com/v2/domain/config?token=token&domains=google.com&config[]=https'

响应体:
{
"code": 0,
"data": [
{
"domain": "google.com",
"domain_id": "106001",
"status": "serving",
"type": "dynamic",
"config": {
"https": {
"cert_id": 120610,
"http2": "on",
"force_https": "302",
"ocsp": "on"
}
}
}
]
}

@Anbool Anbool added the bug Something isn't working label Mar 22, 2025
@fudiwei fudiwei added the backlog Todo label Mar 22, 2025
@fudiwei
Copy link
Collaborator

fudiwei commented Mar 22, 2025

config 传多个值的时候 URL 是啥样的?

fudiwei added a commit to fudiwei/certimate that referenced this issue Mar 22, 2025
@fudiwei fudiwei linked a pull request Mar 22, 2025 that will close this issue
@fudiwei
Copy link
Collaborator

fudiwei commented Mar 22, 2025

@Anbool 看起来白山云用了某种非标的 URL 传参方式,试着改了改。但我没有白山云账号,你可以帮我拉一下 commit 代码后用你的 Token 跑一下单测用例吗?

commit: 516a958

终端进入到项目的 internal/pkg/core/deployer/providers/baishan-cdn/ 目录下,执行:

# 请将参数替换为实际值
go test -v ./baishan_cdn_test.go -args --CERTIMATE_DEPLOYER_BAISHANCDN_INPUTCERTPATH="/path/to/your-input-cert.pem" --CERTIMATE_DEPLOYER_BAISHANCDN_INPUTKEYPATH="/path/to/your-input-key.pem" --CERTIMATE_DEPLOYER_BAISHANCDN_APITOKEN="your-api-token" --CERTIMATE_DEPLOYER_BAISHANCDN_DOMAIN="example.com"

@fudiwei fudiwei added help wanted Extra attention is needed and removed backlog Todo labels Mar 22, 2025
@Anbool
Copy link
Author

Anbool commented Mar 22, 2025

@Anbool 看起来白山云用了某种非标的 URL 传参方式,试着改了改。但我没有白山云账号,你可以帮我拉一下 commit 代码后用你的 Token 跑一下单测用例吗?

commit: 516a958

终端进入到项目的 internal/pkg/core/deployer/providers/baishan-cdn/ 目录下,执行:

请将参数替换为实际值

go test -v ./baishan_cdn_test.go -args --CERTIMATE_DEPLOYER_BAISHANCDN_INPUTCERTPATH="/path/to/your-input-cert.pem" --CERTIMATE_DEPLOYER_BAISHANCDN_INPUTKEYPATH="/path/to/your-input-key.pem" --CERTIMATE_DEPLOYER_BAISHANCDN_APITOKEN="your-api-token" --CERTIMATE_DEPLOYER_BAISHANCDN_DOMAIN="example.com"

可以的,这两天测试后给你反馈

@Anbool
Copy link
Author

Anbool commented Mar 24, 2025

我已经进行了测试并失败,以下是测试日志。不过值得一提的是,白山云 API 的接口传递数组参数确实是非标的:https://cdn.api.baishan.com/v2/domain/config?token=token&domains=www.test.com&config[]=referer&config[]=origin
代表查询 www.test.com 域名下的 referer 和 origin 配置。

root@Small-Build:/data/certimate# git status
HEAD detached at 516a958
nothing to commit, working tree clean

root@Small-Build:/data/certimate# cd internal/pkg/core/deployer/providers/baishan-cdn/

root@Small-Build:/data/certimate/internal/pkg/core/deployer/providers/baishan-cdn# ls
baishan_cdn.go baishan_cdn_test.go

root@Small-Build:/data/certimate/internal/pkg/core/deployer/providers/baishan-cdn# go test -v ./baishan_cdn_test.go -args --CERTIMATE_DEPLOYER_BAISHANCDN_INPUTCERTPATH="/root/cert.pem" --CERTIMATE_DEPLOYER_BAISHANCDN_INPUTKEYPATH="/root/key.pem" --CERTIMATE_DEPLOYER_BAISHANCDN_APITOKEN="这是一个Token" --CERTIMATE_DEPLOYER_BAISHANCDN_DOMAIN="这是一个域名"

go: downloading github.com/pkg/errors v0.9.1
go: downloading github.com/go-resty/resty/v2 v2.16.5
go: downloading golang.org/x/net v0.37.0
=== RUN TestDeploy
=== RUN TestDeploy/Deploy
baishan_cdn_test.go:43: args:
INPUTCERTPATH: /root/cert.pem
INPUTKEYPATH: /root/key.pem
APITOKEN: 这是一个Token
DOMAIN: 这是一个域名
2025/03/24 02:46:59.513279 DEBUG RESTY

GET  /v2/domain/config?config%5B%5D=https&domains=这是一个域名&token=这是一个Token  HTTP/1.1
HOST   : cdn.api.baishan.com
HEADERS:
        User-Agent: go-resty/2.16.5 (https://github.com/go-resty/resty)
BODY   :
***** NO CONTENT *****
------------------------------------------------------------------------------
~~~ RESPONSE ~~~
STATUS       : 200 OK
PROTO        : HTTP/1.1
RECEIVED AT  : 2025-03-24T02:46:59.513170817Z
TIME DURATION: 845.792418ms
HEADERS      :
        Api-Id: 0
        Connection: keep-alive
        Content-Type: application/json; charset=utf-8
        Date: Mon, 24 Mar 2025 02:46:59 GMT
        Server: Apache/2.2.22 (Unix) mod_ssl/2.2.22 OpenSSL/1.0.1e-fips
        Vary: Accept-Encoding
        X-Frame-Options: SAMEORIGIN
        X-Ratelimit-Grad: minute
        X-Ratelimit-Limit: 80
        X-Ratelimit-Remaining: 80
        X-Retry-After: 1
        X-Ser: i48254_c14260, i59680_c22359, i45464_c18583
BODY         :
{
   "code": 0,
   "data": [
      {
         "domain": "这是一个域名",
         "domain_id": "这是一个域名ID",
         "status": "serving",
         "type": "dynamic",
         "config": {
            "https": {
               "cert_id": 这是一个证书ID,
               "http2": "on",
               "force_https": "302",
               "ocsp": "on"
            }
         }
      }
   ]
}
==============================================================================
    baishan_cdn_test.go:64: err: baishan api error: failed to parse response: json: cannot unmarshal string into Go struct field DomainCertificate.data.cert_id of type int64
        failed to execute sdk request 'baishan.CreateCertificate'
        github.com/usual2970/certimate/internal/pkg/core/deployer/providers/baishan-cdn.(*DeployerProvider).Deploy
                /data/certimate/internal/pkg/core/deployer/providers/baishan-cdn/baishan_cdn.go:86
        command-line-arguments_test.TestDeploy.func1
                /data/certimate/internal/pkg/core/deployer/providers/baishan-cdn/baishan_cdn_test.go:62
        testing.tRunner
                /usr/local/go/src/testing/testing.go:1792
        runtime.goexit
                /usr/local/go/src/runtime/asm_amd64.s:1700
--- FAIL: TestDeploy (1.01s)
    --- FAIL: TestDeploy/Deploy (1.01s)
FAIL
FAIL    command-line-arguments  1.010s
FAIL

fudiwei added a commit to fudiwei/certimate that referenced this issue Mar 24, 2025
@fudiwei
Copy link
Collaborator

fudiwei commented Mar 24, 2025

@Anbool 麻烦在现在的基础上再拉一下 commit 892256c ,重新跑一下单测看看。

@Anbool
Copy link
Author

Anbool commented Mar 24, 2025

@fudiwei 看上去 892256c 测试已通过。

root@Small-Build:/data/certimate/internal/pkg/core/deployer/providers/baishan-cdn# go test -v ./baishan_cdn_test.go -args --CERTIMATE_DEPLOYER_BAISHANCDN_INPUTCERTPATH="/root/cert.pem" --CERTIMATE_DEPLOYER_BAISHANCDN_INPUTKEYPATH="/root/key.pem" --CERTIMATE_DEPLOYER_BAISHANCDN_APITOKEN="这是一个Token" --CERTIMATE_DEPLOYER_BAISHANCDN_DOMAIN="这是一个域名"
go: downloading github.com/pkg/errors v0.9.1
go: downloading github.com/go-resty/resty/v2 v2.16.5
go: downloading golang.org/x/net v0.37.0
=== RUN TestDeploy
=== RUN TestDeploy/Deploy
baishan_cdn_test.go:43: args:
INPUTCERTPATH: /root/cert.pem
INPUTKEYPATH: /root/key.pem
APITOKEN: 这是一个Token
DOMAIN: 这是一个域名
baishan_cdn_test.go:64: err: baishan api error: unexpected status code: 400, {"code":400699,"message":"this certificate is exists, cert_id is (这是一个证书ID)"}
failed to execute sdk request 'baishan.CreateCertificate'
github.com/usual2970/certimate/internal/pkg/core/deployer/providers/baishan-cdn.(*DeployerProvider).Deploy
/data/certimate/internal/pkg/core/deployer/providers/baishan-cdn/baishan_cdn.go:86
command-line-arguments_test.TestDeploy.func1
/data/certimate/internal/pkg/core/deployer/providers/baishan-cdn/baishan_cdn_test.go:62
testing.tRunner
/usr/local/go/src/testing/testing.go:1792
runtime.goexit
/usr/local/go/src/runtime/asm_amd64.s:1700
--- FAIL: TestDeploy (1.25s)
--- FAIL: TestDeploy/Deploy (1.25s)
FAIL
FAIL command-line-arguments 1.255s
FAIL

fudiwei added a commit to fudiwei/certimate that referenced this issue Mar 24, 2025
@fudiwei fudiwei removed the help wanted Extra attention is needed label Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants