|
|
|
|
@@ -63,7 +63,6 @@ func (hOp *HarborOperator) Exec(baseFuncName string, funcArgs ...string) (bool,
|
|
|
|
|
|
|
|
|
|
func (hOp *HarborOperator) CreateProjectExec(funcArgs []string) (bool, []string) {
|
|
|
|
|
|
|
|
|
|
client := hOp.TargetHarborClient
|
|
|
|
|
if hOp.TargetHarborClient == nil {
|
|
|
|
|
ok, createClient := hOp.CheckAndBuildHarborClient(funcArgs)
|
|
|
|
|
if !ok {
|
|
|
|
|
@@ -73,18 +72,18 @@ func (hOp *HarborOperator) CreateProjectExec(funcArgs []string) (bool, []string)
|
|
|
|
|
}
|
|
|
|
|
hOp.TargetHarborClient = createClient
|
|
|
|
|
}
|
|
|
|
|
client := hOp.TargetHarborClient
|
|
|
|
|
|
|
|
|
|
// create project
|
|
|
|
|
// 定义你想要创建的仓库(项目)的详细信息
|
|
|
|
|
|
|
|
|
|
log.Debug("[Harbor Create Project] - create project !")
|
|
|
|
|
needToCreateProjectNameList := []string{"cmii", "rancher"}
|
|
|
|
|
var err error
|
|
|
|
|
// 使用客户端创建项目
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
for _, projectName := range needToCreateProjectNameList {
|
|
|
|
|
|
|
|
|
|
log.DebugF("start to create => %s", projectName)
|
|
|
|
|
log.DebugF("start to create proect => %s", projectName)
|
|
|
|
|
projectReq := &model.ProjectReq{
|
|
|
|
|
ProjectName: projectName, // 仓库名称
|
|
|
|
|
Metadata: &model.ProjectMetadata{
|
|
|
|
|
@@ -93,16 +92,16 @@ func (hOp *HarborOperator) CreateProjectExec(funcArgs []string) (bool, []string)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
exists, _ := client.ProjectExists(ctx, projectName)
|
|
|
|
|
if exists {
|
|
|
|
|
log.DebugF("[Harbor Create Project] - Project %s already exists ! continue ", projectName)
|
|
|
|
|
continue
|
|
|
|
|
if !exists {
|
|
|
|
|
|
|
|
|
|
err := client.NewProject(ctx, projectReq)
|
|
|
|
|
if err != nil {
|
|
|
|
|
errorLog := fmt.Sprintf("Error creating project %s: %s\n", projectName, err.Error())
|
|
|
|
|
return false, []string{errorLog}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = client.NewProject(ctx, projectReq)
|
|
|
|
|
if err != nil {
|
|
|
|
|
errorLog := fmt.Sprintf("Error creating project %s: %s\n", projectName, err.Error())
|
|
|
|
|
return false, []string{errorLog}
|
|
|
|
|
}
|
|
|
|
|
log.DebugF("[Harbor Create Project] - Project %s already exists ! continue ", projectName)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -141,7 +140,6 @@ func (hOp *HarborOperator) CheckAndBuildHarborClient(funcArgs []string) (bool, *
|
|
|
|
|
|
|
|
|
|
func (hOp *HarborOperator) ListProjectExec(funcArgs []string) (bool, []string) {
|
|
|
|
|
|
|
|
|
|
client := hOp.TargetHarborClient
|
|
|
|
|
if hOp.TargetHarborClient == nil {
|
|
|
|
|
ok, createClient := hOp.CheckAndBuildHarborClient(funcArgs)
|
|
|
|
|
if !ok {
|
|
|
|
|
@@ -151,10 +149,11 @@ func (hOp *HarborOperator) ListProjectExec(funcArgs []string) (bool, []string) {
|
|
|
|
|
}
|
|
|
|
|
hOp.TargetHarborClient = createClient
|
|
|
|
|
}
|
|
|
|
|
client := hOp.TargetHarborClient
|
|
|
|
|
|
|
|
|
|
// 使用客户端列出所有项目
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
projects, err := client.ListProjects(ctx, "*")
|
|
|
|
|
projects, err := client.ListProjects(ctx, "")
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Printf("Error listing projects: %v\n", err)
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
|