Merge pull request #1458 from Yeqingky/main

fix: lecdn v4 API authentication and certificate deployment
This commit is contained in:
Yoan.liu
2026-09-20 17:01:18 +08:00
committed by GitHub
3 changed files with 10 additions and 17 deletions
+7 -6
View File
@@ -3,6 +3,7 @@ package lecdn
import (
"context"
"crypto/tls"
"encoding/base64"
"fmt"
"log/slog"
"time"
@@ -150,8 +151,8 @@ func (d *Deployer) deployToCertificate(ctx context.Context, certPEM, privkeyPEM
updateSSLCertReq := &lecdnclientsdkv4.UpdateCertificateRequest{
Name: certName,
Description: certDesc,
SSLPEM: certPEM,
SSLKey: privkeyPEM,
SSLPEM: base64.StdEncoding.EncodeToString([]byte(certPEM)),
SSLKey: base64.StdEncoding.EncodeToString([]byte(privkeyPEM)),
AutoRenewal: false,
}
updateSSLCertResp, err := sdkClient.UpdateCertificateWithContext(ctx, d.config.CertificateId, updateSSLCertReq)
@@ -166,8 +167,8 @@ func (d *Deployer) deployToCertificate(ctx context.Context, certPEM, privkeyPEM
updateSSLCertReq := &lecdnmastersdkv4.UpdateCertificateRequest{
Name: certName,
Description: certDesc,
SSLPEM: certPEM,
SSLKey: privkeyPEM,
SSLPEM: base64.StdEncoding.EncodeToString([]byte(certPEM)),
SSLKey: base64.StdEncoding.EncodeToString([]byte(privkeyPEM)),
AutoRenewal: false,
}
updateSSLCertResp, err := sdkClient.UpdateCertificateWithContext(ctx, d.config.CertificateId, updateSSLCertReq)
@@ -264,7 +265,7 @@ func createSDKClient(serverUrl, apiVersion, apiRole, authMethod, username, passw
case "", AUTH_METHOD_PASSWORD:
client, err = lecdnclientsdkv4.NewClient(serverUrl, lecdnclientsdkv4.WithLogins(username, password))
case AUTH_METHOD_APIKEY:
client, err = lecdnclientsdkv4.NewClient(serverUrl, lecdnclientsdkv4.WithLogins(username, password))
client, err = lecdnclientsdkv4.NewClient(serverUrl, lecdnclientsdkv4.WithApiKey(apiKey))
default:
err = fmt.Errorf("unsupported auth method '%s'", authMethod)
}
@@ -290,7 +291,7 @@ func createSDKClient(serverUrl, apiVersion, apiRole, authMethod, username, passw
case "", AUTH_METHOD_PASSWORD:
client, err = lecdnmastersdkv4.NewClient(serverUrl, lecdnmastersdkv4.WithLogins(username, password))
case AUTH_METHOD_APIKEY:
client, err = lecdnmastersdkv4.NewClient(serverUrl, lecdnmastersdkv4.WithLogins(username, password))
client, err = lecdnmastersdkv4.NewClient(serverUrl, lecdnmastersdkv4.WithApiKey(apiKey))
default:
err = fmt.Errorf("unsupported auth method '%s'", authMethod)
}
+2 -6
View File
@@ -48,11 +48,7 @@ func NewClient(serverUrl string, optFns ...OptionsFunc) (*Client, error) {
}
baseUrl := strings.TrimSuffix(serverUrl, "/")
if opts.ApiKey != "" {
baseUrl += "/api/client"
} else {
baseUrl += "/prod-api"
}
baseUrl += "/prod-api"
client := &Client{
username: opts.Username,
@@ -150,7 +146,7 @@ func (c *Client) ensureToken(ctx context.Context) error {
return nil
}
httpreq, err := c.newRequest(http.MethodPost, "/auth/login")
httpreq, err := c.newRequest(http.MethodPost, "/login")
if err != nil {
return err
} else {
+1 -5
View File
@@ -48,11 +48,7 @@ func NewClient(serverUrl string, optFns ...OptionsFunc) (*Client, error) {
}
baseUrl := strings.TrimSuffix(serverUrl, "/")
if opts.ApiKey != "" {
baseUrl += "/api/admin"
} else {
baseUrl += "/prod-api"
}
baseUrl += "/prod-api"
client := &Client{
username: opts.Username,