mirror of https://github.com/allinssl/allinssl
【新增】增加API接口测试功能接口 为部分供应商API增加测试功能
parent
4a2f500006
commit
77d82ad8a0
|
@ -2,6 +2,7 @@ package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"ALLinSSL/backend/internal/access"
|
"ALLinSSL/backend/internal/access"
|
||||||
|
"ALLinSSL/backend/internal/cert/deploy"
|
||||||
"ALLinSSL/backend/public"
|
"ALLinSSL/backend/public"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -133,3 +134,47 @@ func DelAccess(c *gin.Context) {
|
||||||
public.SuccessMsg(c, "删除成功")
|
public.SuccessMsg(c, "删除成功")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccess(c *gin.Context) {
|
||||||
|
var form struct {
|
||||||
|
ID string `form:"id"`
|
||||||
|
Type string `form:"type"`
|
||||||
|
}
|
||||||
|
err := c.Bind(&form)
|
||||||
|
if err != nil {
|
||||||
|
public.FailMsg(c, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if form.Type == "" {
|
||||||
|
public.FailMsg(c, "类型不能为空")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var result error
|
||||||
|
switch form.Type {
|
||||||
|
case "btwaf":
|
||||||
|
result = deploy.BtWafAPITest(form.ID)
|
||||||
|
case "btpanel":
|
||||||
|
result = deploy.BtPanelAPITest(form.ID)
|
||||||
|
case "ssh":
|
||||||
|
result = deploy.SSHAPITest(form.ID)
|
||||||
|
case "safeline":
|
||||||
|
result = deploy.SafeLineAPITest(form.ID)
|
||||||
|
case "1panel":
|
||||||
|
result = deploy.OnePanelAPITest(form.ID)
|
||||||
|
case "tencentcloud":
|
||||||
|
result = deploy.TencentCloudAPITest(form.ID)
|
||||||
|
case "aliyun":
|
||||||
|
result = deploy.AliyunCdnAPITest(form.ID)
|
||||||
|
default:
|
||||||
|
public.FailMsg(c, "不支持测试的提供商")
|
||||||
|
}
|
||||||
|
|
||||||
|
if result != nil {
|
||||||
|
public.FailMsg(c, result.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
public.SuccessMsg(c, "请求测试成功!")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
|
@ -29,3 +29,12 @@ func TestP(t *testing.T) {
|
||||||
err := Deploy1panel(cfg)
|
err := Deploy1panel(cfg)
|
||||||
println(err)
|
println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestOnePanelAPITest(t *testing.T) {
|
||||||
|
result := OnePanelAPITest("8")
|
||||||
|
if result != nil {
|
||||||
|
t.Fatalf("SSHAPITest failed: %v", result)
|
||||||
|
} else {
|
||||||
|
t.Log("SSHAPITest success")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -97,9 +97,9 @@ func Request1panel(data *map[string]any, method, providerID, requestUrl string)
|
||||||
if code != 200 {
|
if code != 200 {
|
||||||
msg, ok := res["message"].(string)
|
msg, ok := res["message"].(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("证书部署失败")
|
return nil, fmt.Errorf("请求失败")
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("证书部署失败: %s", msg)
|
return nil, fmt.Errorf("请求失败: %s", msg)
|
||||||
}
|
}
|
||||||
return res, nil
|
return res, nil
|
||||||
|
|
||||||
|
@ -223,3 +223,12 @@ func Deploy1panelSite(cfg map[string]any) error {
|
||||||
_, err = Request1panel(&data, "POST", providerID, fmt.Sprintf("api/v1/websites/%s/https", siteId))
|
_, err = Request1panel(&data, "POST", providerID, fmt.Sprintf("api/v1/websites/%s/https", siteId))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func OnePanelAPITest(providerID string) error {
|
||||||
|
data := map[string]interface{}{}
|
||||||
|
_, err := Request1panel(&data, "GET", providerID, "api/v1/settings/upgrade")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("测试请求失败: %v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -39,3 +39,12 @@ func TestALiOss(t *testing.T) {
|
||||||
t.Logf("DeployAliCdn succeeded")
|
t.Logf("DeployAliCdn succeeded")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAliyunCdnAPITest(t *testing.T) {
|
||||||
|
result := AliyunCdnAPITest("10")
|
||||||
|
if result != nil {
|
||||||
|
t.Fatalf("SSHAPITest failed: %v", result)
|
||||||
|
} else {
|
||||||
|
t.Log("SSHAPITest success")
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,11 +6,11 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
aliyuncdn "github.com/alibabacloud-go/cdn-20180510/v6/client"
|
aliyuncdn "github.com/alibabacloud-go/cdn-20180510/v6/client"
|
||||||
aliyunopenapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
aliyunopenapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
||||||
|
aliyunmarket "github.com/alibabacloud-go/market-20151101/v4/client"
|
||||||
"github.com/alibabacloud-go/tea/tea"
|
"github.com/alibabacloud-go/tea/tea"
|
||||||
|
"github.com/aliyun/aliyun-oss-go-sdk/oss"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/aliyun/aliyun-oss-go-sdk/oss"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func ClientAliCdn(accessKey, accessSecret string) (_result *aliyuncdn.Client, err error) {
|
func ClientAliCdn(accessKey, accessSecret string) (_result *aliyuncdn.Client, err error) {
|
||||||
|
@ -183,3 +183,43 @@ func DeployOss(cfg map[string]any) error {
|
||||||
err = client.PutBucketCnameWithCertificate(bucket, putBucketCnameWithCertificateRequest)
|
err = client.PutBucketCnameWithCertificate(bucket, putBucketCnameWithCertificateRequest)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ClientMaker(accessKeyId, accessKeySecret string) (*aliyunmarket.Client, error) {
|
||||||
|
config := &aliyunopenapi.Config{
|
||||||
|
AccessKeyId: tea.String(accessKeyId),
|
||||||
|
AccessKeySecret: tea.String(accessKeySecret),
|
||||||
|
Endpoint: tea.String("market.aliyuncs.com"),
|
||||||
|
}
|
||||||
|
|
||||||
|
client, _ := aliyunmarket.NewClient(config)
|
||||||
|
return client, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func AliyunCdnAPITest(providerID string) error {
|
||||||
|
providerData, err := access.GetAccess(providerID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
providerConfigStr, ok := providerData["config"].(string)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("api配置错误")
|
||||||
|
}
|
||||||
|
// 解析 JSON 配置
|
||||||
|
var providerConfig map[string]string
|
||||||
|
err = json.Unmarshal([]byte(providerConfigStr), &providerConfig)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
client, err := ClientMaker(providerConfig["access_key_id"], providerConfig["access_key_secret"])
|
||||||
|
describeApiMeteringRequest := &aliyunmarket.DescribeApiMeteringRequest{
|
||||||
|
PageNum: tea.Int32(1),
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = client.DescribeApiMetering(describeApiMeteringRequest)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("测试请求失败: %v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -1,6 +1,8 @@
|
||||||
package deploy
|
package deploy
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
func TestBTSite(t *testing.T) {
|
func TestBTSite(t *testing.T) {
|
||||||
cfg := map[string]any{
|
cfg := map[string]any{
|
||||||
|
@ -43,3 +45,12 @@ func TestBTDockerSite(t *testing.T) {
|
||||||
err := DeployBtDockerSite(cfg)
|
err := DeployBtDockerSite(cfg)
|
||||||
println(err)
|
println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBtPanelAPITest(t *testing.T) {
|
||||||
|
result := BtPanelAPITest("4")
|
||||||
|
if result != nil {
|
||||||
|
t.Fatalf("SSHAPITest failed: %v", result)
|
||||||
|
} else {
|
||||||
|
t.Log("SSHAPITest success")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -197,3 +197,12 @@ func DeployBtDockerSite(cfg map[string]any) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BtPanelAPITest(providerID string) error {
|
||||||
|
data := url.Values{}
|
||||||
|
_, err := RequestBt(&data, "POST", providerID, "mod/push/task/get_task_list")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("测试请求失败: %v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -199,3 +199,12 @@ func DeployBtWafSite(cfg map[string]any) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BtWafAPITest(providerID string) error {
|
||||||
|
data := map[string]any{}
|
||||||
|
_, err := RequestBtWaf(&data, "POST", providerID, "api/overview/infos")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("测试请求失败: %v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -40,3 +40,11 @@ func TestGetBTWAFSiteList(t *testing.T) {
|
||||||
}
|
}
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBtWafAPITest(t *testing.T) {
|
||||||
|
result := BtWafAPITest("1")
|
||||||
|
if result != nil {
|
||||||
|
fmt.Println(result)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
|
@ -204,3 +204,11 @@ func DeploySafeLineWafSite(cfg map[string]any, logger *public.Logger) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SafeLineAPITest(providerID string) error {
|
||||||
|
_, err := RequestSafeLineWaf(&map[string]any{}, "GET", providerID, "api/open/site/group")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("测试请求失败: %v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -45,3 +45,12 @@ func TestGetSafeLineWAFSiteList(t *testing.T) {
|
||||||
siteId := matchSafeLineSiteByColumn(res, "comment", "测得3")
|
siteId := matchSafeLineSiteByColumn(res, "comment", "测得3")
|
||||||
fmt.Println(siteId)
|
fmt.Println(siteId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSafeLineAPITest(t *testing.T) {
|
||||||
|
result := SafeLineAPITest("5")
|
||||||
|
if result != nil {
|
||||||
|
t.Fatalf("SafeLineAPITest failed: %v", result)
|
||||||
|
} else {
|
||||||
|
t.Log("SafeLineAPITest success")
|
||||||
|
}
|
||||||
|
}
|
|
@ -235,3 +235,61 @@ func DeployLocalhost(cfg map[string]any) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SSHAPITest(providerID string) error {
|
||||||
|
providerData, err := access.GetAccess(providerID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
providerConfigStr, ok := providerData["config"].(string)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("api配置错误")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解析 JSON 配置
|
||||||
|
var providerConfig SSHConfig
|
||||||
|
err = json.Unmarshal([]byte(providerConfigStr), &providerConfig)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var port string
|
||||||
|
switch v := providerConfig.Port.(type) {
|
||||||
|
case float64:
|
||||||
|
port = strconv.Itoa(int(v))
|
||||||
|
case string:
|
||||||
|
port = v
|
||||||
|
case int:
|
||||||
|
port = strconv.Itoa(v)
|
||||||
|
default:
|
||||||
|
port = "22"
|
||||||
|
}
|
||||||
|
addr := fmt.Sprintf("%s:%s", providerConfig.Host, port)
|
||||||
|
|
||||||
|
authMethods, err := buildAuthMethods(providerConfig.Password, providerConfig.PrivateKey)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
sshConfig := &ssh.ClientConfig{
|
||||||
|
User: providerConfig.User,
|
||||||
|
Auth: authMethods,
|
||||||
|
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
|
||||||
|
}
|
||||||
|
|
||||||
|
client, err := ssh.Dial("tcp", addr, sshConfig)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("SSH连接失败: %v", err)
|
||||||
|
}
|
||||||
|
defer client.Close()
|
||||||
|
|
||||||
|
// 尝试创建会话来验证连接
|
||||||
|
session, err := client.NewSession()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("SSH会话创建失败: %v", err)
|
||||||
|
}
|
||||||
|
defer session.Close()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -20,3 +20,12 @@ func TestSSH(t *testing.T) {
|
||||||
}
|
}
|
||||||
// println(err.Error())
|
// println(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSSHAPITest(t *testing.T) {
|
||||||
|
result := SSHAPITest("7")
|
||||||
|
if result != nil {
|
||||||
|
t.Fatalf("SSHAPITest failed: %v", result)
|
||||||
|
} else {
|
||||||
|
t.Log("SSHAPITest success")
|
||||||
|
}
|
||||||
|
}
|
|
@ -130,3 +130,33 @@ func DeployToTX(cfg map[string]any) error {
|
||||||
fmt.Println(response.Response.DeployRecordId)
|
fmt.Println(response.Response.DeployRecordId)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TencentCloudAPITest(providerID string) error {
|
||||||
|
providerData, err := access.GetAccess(providerID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
providerConfigStr, ok := providerData["config"].(string)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("api配置错误")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解析 JSON 配置
|
||||||
|
var providerConfig map[string]string
|
||||||
|
err = json.Unmarshal([]byte(providerConfigStr), &providerConfig)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建客户端
|
||||||
|
client := ClientTencentcloud(providerConfig["secret_id"], providerConfig["secret_key"], "")
|
||||||
|
|
||||||
|
request := ssl.NewDescribeCertificatesRequest()
|
||||||
|
_, err = client.DescribeCertificates(request)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("测试请求失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
package deploy
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestTencentCloudAPITest(t *testing.T) {
|
||||||
|
result := TencentCloudAPITest("9")
|
||||||
|
if result != nil {
|
||||||
|
t.Fatalf("SSHAPITest failed: %v", result)
|
||||||
|
} else {
|
||||||
|
t.Log("SSHAPITest success")
|
||||||
|
}
|
||||||
|
}
|
|
@ -43,6 +43,7 @@ func Register(r *gin.Engine) {
|
||||||
access.POST("/del_access", api.DelAccess)
|
access.POST("/del_access", api.DelAccess)
|
||||||
access.POST("/upd_access", api.UpdateAccess)
|
access.POST("/upd_access", api.UpdateAccess)
|
||||||
access.POST("/get_all", api.GetAllAccess)
|
access.POST("/get_all", api.GetAllAccess)
|
||||||
|
access.POST("/test_access", api.TestAccess)
|
||||||
}
|
}
|
||||||
cert := v1.Group("/cert")
|
cert := v1.Group("/cert")
|
||||||
{
|
{
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -5,6 +5,7 @@ go 1.23.2
|
||||||
require (
|
require (
|
||||||
github.com/alibabacloud-go/cdn-20180510/v6 v6.0.0
|
github.com/alibabacloud-go/cdn-20180510/v6 v6.0.0
|
||||||
github.com/alibabacloud-go/darabonba-openapi/v2 v2.1.7
|
github.com/alibabacloud-go/darabonba-openapi/v2 v2.1.7
|
||||||
|
github.com/alibabacloud-go/market-20151101/v4 v4.1.0
|
||||||
github.com/alibabacloud-go/tea v1.3.9
|
github.com/alibabacloud-go/tea v1.3.9
|
||||||
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible
|
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible
|
||||||
github.com/gin-contrib/gzip v1.2.3
|
github.com/gin-contrib/gzip v1.2.3
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -81,6 +81,8 @@ github.com/alibabacloud-go/debug v1.0.1 h1:MsW9SmUtbb1Fnt3ieC6NNZi6aEwrXfDksD4QA
|
||||||
github.com/alibabacloud-go/debug v1.0.1/go.mod h1:8gfgZCCAC3+SCzjWtY053FrOcd4/qlH6IHTI4QyICOc=
|
github.com/alibabacloud-go/debug v1.0.1/go.mod h1:8gfgZCCAC3+SCzjWtY053FrOcd4/qlH6IHTI4QyICOc=
|
||||||
github.com/alibabacloud-go/endpoint-util v1.1.0 h1:r/4D3VSw888XGaeNpP994zDUaxdgTSHBbVfZlzf6b5Q=
|
github.com/alibabacloud-go/endpoint-util v1.1.0 h1:r/4D3VSw888XGaeNpP994zDUaxdgTSHBbVfZlzf6b5Q=
|
||||||
github.com/alibabacloud-go/endpoint-util v1.1.0/go.mod h1:O5FuCALmCKs2Ff7JFJMudHs0I5EBgecXXxZRyswlEjE=
|
github.com/alibabacloud-go/endpoint-util v1.1.0/go.mod h1:O5FuCALmCKs2Ff7JFJMudHs0I5EBgecXXxZRyswlEjE=
|
||||||
|
github.com/alibabacloud-go/market-20151101/v4 v4.1.0 h1:o5e9gCxVOKOGeslAFRtaRHsQAveH1i3aGFDNfyCUsVU=
|
||||||
|
github.com/alibabacloud-go/market-20151101/v4 v4.1.0/go.mod h1:PCt2sE7Y0SknDc0oMxjdTmNCB1qGY4ZyREyiXjHvmY4=
|
||||||
github.com/alibabacloud-go/openapi-util v0.1.0/go.mod h1:sQuElr4ywwFRlCCberQwKRFhRzIyG4QTP/P4y1CJ6Ws=
|
github.com/alibabacloud-go/openapi-util v0.1.0/go.mod h1:sQuElr4ywwFRlCCberQwKRFhRzIyG4QTP/P4y1CJ6Ws=
|
||||||
github.com/alibabacloud-go/openapi-util v0.1.1 h1:ujGErJjG8ncRW6XtBBMphzHTvCxn4DjrVw4m04HsS28=
|
github.com/alibabacloud-go/openapi-util v0.1.1 h1:ujGErJjG8ncRW6XtBBMphzHTvCxn4DjrVw4m04HsS28=
|
||||||
github.com/alibabacloud-go/openapi-util v0.1.1/go.mod h1:/UehBSE2cf1gYT43GV4E+RxTdLRzURImCYY0aRmlXpw=
|
github.com/alibabacloud-go/openapi-util v0.1.1/go.mod h1:/UehBSE2cf1gYT43GV4E+RxTdLRzURImCYY0aRmlXpw=
|
||||||
|
|
Loading…
Reference in New Issue