from vscode

This commit is contained in:
zeaslity
2023-11-13 10:25:15 +08:00
parent cdfa4b5d04
commit 3f06350089
8 changed files with 42 additions and 30 deletions

View File

@@ -3,9 +3,10 @@ package executor
import (
"context"
"fmt"
"net"
"github.com/mittwald/goharbor-client/v5/apiv2"
"github.com/mittwald/goharbor-client/v5/apiv2/model"
"net"
)
type HarborOperator struct {
@@ -58,18 +59,20 @@ func (hOp *HarborOperator) CreateProjectExec(funcArgs []string) (bool, []string)
targetHarborHost := funcArgs[0]
parseIP := net.ParseIP(targetHarborHost)
if parseIP != nil {
if parseIP == nil {
return false, []string{
"[Harbor CreateProjectExec] - ip format is wrong!",
fmt.Sprintf("[Harbor CreateProjectExec] - ip format is wrong! parseIP is => %s ", parseIP),
}
}
hOp.TargetHarborHost = string(parseIP) + ":" + hOp.HarborPort
hOp.TargetHarborHost = "http://" + targetHarborHost + ":" + hOp.HarborPort + "/api"
log.DebugF("[Harbor CreateProjectExec] - harbor host is => %s", hOp.TargetHarborHost)
// check connection
client, err := apiv2.NewRESTClientForHost(hOp.TargetHarborHost, hOp.HarborAdminUser, hOp.HarborAdminPass, nil)
if err != nil {
errorLog := fmt.Sprintf("Error creating REST client: %v\n", err)
errorLog := fmt.Sprintf("Error creating REST client: %s\n", err.Error())
log.Error(errorLog)
return false, []string{errorLog}
}
@@ -94,13 +97,13 @@ func (hOp *HarborOperator) CreateProjectExec(funcArgs []string) (bool, []string)
ctx := context.Background()
err = client.NewProject(ctx, cmiiProject)
if err != nil {
errorLog := fmt.Sprintf("Error creating project: %v\n", err)
errorLog := fmt.Sprintf("Error creating project: %s\n", err.Error())
return false, []string{errorLog}
}
err = client.NewProject(ctx, rancherProject)
if err != nil {
errorLog := fmt.Sprintf("Error creating project: %v\n", err)
errorLog := fmt.Sprintf("Error creating project: %s\n", err.Error())
return false, []string{errorLog}
}