feat: add cdnfly deployer

This commit is contained in:
Fu Diwei
2025-02-18 15:14:24 +08:00
parent 46f02331fd
commit 03d2f4ca32
122 changed files with 955 additions and 243 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"net/url"
xerrors "github.com/pkg/errors"
@@ -38,11 +39,11 @@ func New(config *SafeLineDeployerConfig) (*SafeLineDeployer, error) {
func NewWithLogger(config *SafeLineDeployerConfig, logger logger.Logger) (*SafeLineDeployer, error) {
if config == nil {
return nil, errors.New("config is nil")
panic("config is nil")
}
if logger == nil {
return nil, errors.New("logger is nil")
panic("logger is nil")
}
client, err := createSdkClient(config.ApiUrl, config.ApiToken)
@@ -97,6 +98,14 @@ func (d *SafeLineDeployer) deployToCertificate(ctx context.Context, certPem stri
}
func createSdkClient(apiUrl, apiToken string) (*safelinesdk.Client, error) {
if _, err := url.Parse(apiUrl); err != nil {
return nil, errors.New("invalid safeline api url")
}
if apiToken == "" {
return nil, errors.New("invalid safeline api token")
}
client := safelinesdk.NewClient(apiUrl, apiToken)
return client, nil
}

View File

@@ -35,8 +35,8 @@ Shell command to run this test:
go test -v ./safeline_test.go -args \
--CERTIMATE_DEPLOYER_SAFELINE_INPUTCERTPATH="/path/to/your-input-cert.pem" \
--CERTIMATE_DEPLOYER_SAFELINE_INPUTKEYPATH="/path/to/your-input-key.pem" \
--CERTIMATE_DEPLOYER_SAFELINE_APIURL="your-safeline-url" \
--CERTIMATE_DEPLOYER_SAFELINE_APITOKEN="your-safeline-api-token" \
--CERTIMATE_DEPLOYER_SAFELINE_APIURL="http://127.0.0.1:9443" \
--CERTIMATE_DEPLOYER_SAFELINE_APITOKEN="your-api-token" \
--CERTIMATE_DEPLOYER_SAFELINE_CERTIFICATEID="your-cerficiate-id"
*/
func TestDeploy(t *testing.T) {