mirror of
https://github.com/goharbor/harbor
synced 2025-04-15 21:43:40 +00:00
enable visible when to list/create robot (#13840)
1, enable the visible attribute when to create/list robots 2, rename package name from robot2 to robot Signed-off-by: Wang Yan <wangyan@vmware.com>
This commit is contained in:
parent
bd46af691c
commit
0271efd3f7
|
@ -23,7 +23,7 @@ import (
|
|||
"github.com/goharbor/harbor/src/controller/project"
|
||||
"github.com/goharbor/harbor/src/pkg/permission/evaluator"
|
||||
"github.com/goharbor/harbor/src/pkg/permission/types"
|
||||
"github.com/goharbor/harbor/src/pkg/robot2/model"
|
||||
"github.com/goharbor/harbor/src/pkg/robot/model"
|
||||
)
|
||||
|
||||
// SecurityContext implements security.Context interface based on database
|
||||
|
|
|
@ -23,7 +23,7 @@ import (
|
|||
"github.com/goharbor/harbor/src/common/models"
|
||||
"github.com/goharbor/harbor/src/common/rbac"
|
||||
"github.com/goharbor/harbor/src/pkg/permission/types"
|
||||
"github.com/goharbor/harbor/src/pkg/robot2/model"
|
||||
"github.com/goharbor/harbor/src/pkg/robot/model"
|
||||
projecttesting "github.com/goharbor/harbor/src/testing/controller/project"
|
||||
"github.com/goharbor/harbor/src/testing/mock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
|
|
@ -13,8 +13,8 @@ import (
|
|||
"github.com/goharbor/harbor/src/pkg/project"
|
||||
"github.com/goharbor/harbor/src/pkg/rbac"
|
||||
rbac_model "github.com/goharbor/harbor/src/pkg/rbac/model"
|
||||
robot "github.com/goharbor/harbor/src/pkg/robot2"
|
||||
"github.com/goharbor/harbor/src/pkg/robot2/model"
|
||||
robot "github.com/goharbor/harbor/src/pkg/robot"
|
||||
"github.com/goharbor/harbor/src/pkg/robot/model"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -108,6 +108,7 @@ func (d *controller) Create(ctx context.Context, r *Robot) (int64, string, error
|
|||
Secret: secret,
|
||||
Duration: r.Duration,
|
||||
Salt: salt,
|
||||
Visible: r.Visible,
|
||||
})
|
||||
if err != nil {
|
||||
return 0, "", err
|
||||
|
|
|
@ -11,11 +11,11 @@ import (
|
|||
"github.com/goharbor/harbor/src/lib/q"
|
||||
"github.com/goharbor/harbor/src/pkg/permission/types"
|
||||
rbac_model "github.com/goharbor/harbor/src/pkg/rbac/model"
|
||||
"github.com/goharbor/harbor/src/pkg/robot2/model"
|
||||
"github.com/goharbor/harbor/src/pkg/robot/model"
|
||||
"github.com/goharbor/harbor/src/testing/mock"
|
||||
"github.com/goharbor/harbor/src/testing/pkg/project"
|
||||
"github.com/goharbor/harbor/src/testing/pkg/rbac"
|
||||
"github.com/goharbor/harbor/src/testing/pkg/robot2"
|
||||
"github.com/goharbor/harbor/src/testing/pkg/robot"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"os"
|
||||
"testing"
|
||||
|
@ -28,7 +28,7 @@ type ControllerTestSuite struct {
|
|||
func (suite *ControllerTestSuite) TestGet() {
|
||||
projectMgr := &project.Manager{}
|
||||
rbacMgr := &rbac.Manager{}
|
||||
robotMgr := &robot2.Manager{}
|
||||
robotMgr := &robot.Manager{}
|
||||
|
||||
c := controller{robotMgr: robotMgr, rbacMgr: rbacMgr, proMgr: projectMgr}
|
||||
ctx := context.TODO()
|
||||
|
@ -70,7 +70,7 @@ func (suite *ControllerTestSuite) TestGet() {
|
|||
func (suite *ControllerTestSuite) TestCount() {
|
||||
projectMgr := &project.Manager{}
|
||||
rbacMgr := &rbac.Manager{}
|
||||
robotMgr := &robot2.Manager{}
|
||||
robotMgr := &robot.Manager{}
|
||||
|
||||
c := controller{robotMgr: robotMgr, rbacMgr: rbacMgr, proMgr: projectMgr}
|
||||
ctx := context.TODO()
|
||||
|
@ -96,7 +96,7 @@ func (suite *ControllerTestSuite) TestCreate() {
|
|||
|
||||
projectMgr := &project.Manager{}
|
||||
rbacMgr := &rbac.Manager{}
|
||||
robotMgr := &robot2.Manager{}
|
||||
robotMgr := &robot.Manager{}
|
||||
|
||||
c := controller{robotMgr: robotMgr, rbacMgr: rbacMgr, proMgr: projectMgr}
|
||||
ctx := context.TODO()
|
||||
|
@ -137,7 +137,7 @@ func (suite *ControllerTestSuite) TestCreate() {
|
|||
func (suite *ControllerTestSuite) TestDelete() {
|
||||
projectMgr := &project.Manager{}
|
||||
rbacMgr := &rbac.Manager{}
|
||||
robotMgr := &robot2.Manager{}
|
||||
robotMgr := &robot.Manager{}
|
||||
|
||||
c := controller{robotMgr: robotMgr, rbacMgr: rbacMgr, proMgr: projectMgr}
|
||||
ctx := context.TODO()
|
||||
|
@ -152,7 +152,7 @@ func (suite *ControllerTestSuite) TestDelete() {
|
|||
func (suite *ControllerTestSuite) TestUpdate() {
|
||||
projectMgr := &project.Manager{}
|
||||
rbacMgr := &rbac.Manager{}
|
||||
robotMgr := &robot2.Manager{}
|
||||
robotMgr := &robot.Manager{}
|
||||
|
||||
c := controller{robotMgr: robotMgr, rbacMgr: rbacMgr, proMgr: projectMgr}
|
||||
ctx := context.TODO()
|
||||
|
@ -202,7 +202,7 @@ func (suite *ControllerTestSuite) TestUpdate() {
|
|||
func (suite *ControllerTestSuite) TestList() {
|
||||
projectMgr := &project.Manager{}
|
||||
rbacMgr := &rbac.Manager{}
|
||||
robotMgr := &robot2.Manager{}
|
||||
robotMgr := &robot.Manager{}
|
||||
|
||||
c := controller{robotMgr: robotMgr, rbacMgr: rbacMgr, proMgr: projectMgr}
|
||||
ctx := context.TODO()
|
||||
|
@ -251,7 +251,7 @@ func (suite *ControllerTestSuite) TestList() {
|
|||
func (suite *ControllerTestSuite) TestToScope() {
|
||||
projectMgr := &project.Manager{}
|
||||
rbacMgr := &rbac.Manager{}
|
||||
robotMgr := &robot2.Manager{}
|
||||
robotMgr := &robot.Manager{}
|
||||
|
||||
c := controller{robotMgr: robotMgr, rbacMgr: rbacMgr, proMgr: projectMgr}
|
||||
ctx := context.TODO()
|
||||
|
|
|
@ -2,7 +2,7 @@ package robot
|
|||
|
||||
import (
|
||||
"github.com/goharbor/harbor/src/pkg/permission/types"
|
||||
"github.com/goharbor/harbor/src/pkg/robot2/model"
|
||||
"github.com/goharbor/harbor/src/pkg/robot/model"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -2,7 +2,7 @@ package robot
|
|||
|
||||
import (
|
||||
"github.com/goharbor/harbor/src/pkg/permission/types"
|
||||
"github.com/goharbor/harbor/src/pkg/robot2/model"
|
||||
"github.com/goharbor/harbor/src/pkg/robot/model"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"testing"
|
||||
)
|
||||
|
|
|
@ -33,7 +33,7 @@ import (
|
|||
"github.com/goharbor/harbor/src/lib/orm"
|
||||
"github.com/goharbor/harbor/src/lib/q"
|
||||
"github.com/goharbor/harbor/src/pkg/permission/types"
|
||||
"github.com/goharbor/harbor/src/pkg/robot2/model"
|
||||
"github.com/goharbor/harbor/src/pkg/robot/model"
|
||||
sca "github.com/goharbor/harbor/src/pkg/scan"
|
||||
"github.com/goharbor/harbor/src/pkg/scan/dao/scan"
|
||||
"github.com/goharbor/harbor/src/pkg/scan/dao/scanner"
|
||||
|
|
|
@ -30,7 +30,7 @@ import (
|
|||
"github.com/goharbor/harbor/src/lib/orm"
|
||||
"github.com/goharbor/harbor/src/lib/q"
|
||||
"github.com/goharbor/harbor/src/pkg/permission/types"
|
||||
"github.com/goharbor/harbor/src/pkg/robot2/model"
|
||||
"github.com/goharbor/harbor/src/pkg/robot/model"
|
||||
sca "github.com/goharbor/harbor/src/pkg/scan"
|
||||
"github.com/goharbor/harbor/src/pkg/scan/dao/scan"
|
||||
"github.com/goharbor/harbor/src/pkg/scan/dao/scanner"
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"github.com/goharbor/harbor/src/lib/errors"
|
||||
"github.com/goharbor/harbor/src/lib/orm"
|
||||
"github.com/goharbor/harbor/src/lib/q"
|
||||
"github.com/goharbor/harbor/src/pkg/robot2/model"
|
||||
"github.com/goharbor/harbor/src/pkg/robot/model"
|
||||
"time"
|
||||
)
|
||||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"github.com/goharbor/harbor/src/lib/errors"
|
||||
"github.com/goharbor/harbor/src/lib/orm"
|
||||
"github.com/goharbor/harbor/src/lib/q"
|
||||
"github.com/goharbor/harbor/src/pkg/robot2/model"
|
||||
"github.com/goharbor/harbor/src/pkg/robot/model"
|
||||
htesting "github.com/goharbor/harbor/src/testing"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"testing"
|
||||
|
@ -91,6 +91,23 @@ func (suite *DaoTestSuite) TestList() {
|
|||
})
|
||||
suite.Require().Nil(err)
|
||||
suite.Equal(suite.robotID3, robots[0].ID)
|
||||
|
||||
r := &model.Robot{
|
||||
Name: "testvisible",
|
||||
Description: "test visible",
|
||||
ProjectID: 998,
|
||||
Visible: false,
|
||||
Secret: suite.RandString(10),
|
||||
}
|
||||
_, err = suite.dao.Create(orm.Context(), r)
|
||||
suite.Nil(err)
|
||||
robots, err = suite.dao.List(orm.Context(), &q.Query{
|
||||
Keywords: map[string]interface{}{
|
||||
"name": "testvisible",
|
||||
"visible": true,
|
||||
},
|
||||
})
|
||||
suite.Equal(len(robots), 0)
|
||||
}
|
||||
|
||||
func (suite *DaoTestSuite) TestGet() {
|
|
@ -1,10 +1,10 @@
|
|||
package robot2
|
||||
package robot
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/goharbor/harbor/src/lib/q"
|
||||
"github.com/goharbor/harbor/src/pkg/robot2/dao"
|
||||
"github.com/goharbor/harbor/src/pkg/robot2/model"
|
||||
"github.com/goharbor/harbor/src/pkg/robot/dao"
|
||||
"github.com/goharbor/harbor/src/pkg/robot/model"
|
||||
)
|
||||
|
||||
var (
|
|
@ -1,10 +1,10 @@
|
|||
package robot2
|
||||
package robot
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/goharbor/harbor/src/pkg/robot2/model"
|
||||
"github.com/goharbor/harbor/src/pkg/robot/model"
|
||||
"github.com/goharbor/harbor/src/testing/mock"
|
||||
"github.com/goharbor/harbor/src/testing/pkg/robot2/dao"
|
||||
"github.com/goharbor/harbor/src/testing/pkg/robot/dao"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"testing"
|
||||
)
|
|
@ -33,7 +33,7 @@ import (
|
|||
"github.com/goharbor/harbor/src/jobservice/job"
|
||||
"github.com/goharbor/harbor/src/jobservice/logger"
|
||||
"github.com/goharbor/harbor/src/lib/errors"
|
||||
"github.com/goharbor/harbor/src/pkg/robot2/model"
|
||||
"github.com/goharbor/harbor/src/pkg/robot/model"
|
||||
"github.com/goharbor/harbor/src/pkg/scan/dao/scanner"
|
||||
"github.com/goharbor/harbor/src/pkg/scan/report"
|
||||
v1 "github.com/goharbor/harbor/src/pkg/scan/rest/v1"
|
||||
|
|
|
@ -17,7 +17,7 @@ package scan
|
|||
import (
|
||||
"encoding/json"
|
||||
"github.com/goharbor/harbor/src/controller/robot"
|
||||
"github.com/goharbor/harbor/src/pkg/robot2/model"
|
||||
"github.com/goharbor/harbor/src/pkg/robot/model"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/goharbor/harbor/src/pkg/robot2/model"
|
||||
"github.com/goharbor/harbor/src/pkg/robot/model"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ import (
|
|||
"github.com/goharbor/harbor/src/pkg/project/metadata"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
"github.com/goharbor/harbor/src/pkg/retention/policy"
|
||||
"github.com/goharbor/harbor/src/pkg/robot2"
|
||||
"github.com/goharbor/harbor/src/pkg/robot"
|
||||
"github.com/goharbor/harbor/src/pkg/user"
|
||||
"github.com/goharbor/harbor/src/replication"
|
||||
"github.com/goharbor/harbor/src/server/v2.0/handler/model"
|
||||
|
@ -48,7 +48,7 @@ func newProjectAPI() *projectAPI {
|
|||
repositoryCtl: repository.Ctl,
|
||||
projectCtl: project.Ctl,
|
||||
quotaCtl: quota.Ctl,
|
||||
robotMgr: robot2.Mgr,
|
||||
robotMgr: robot.Mgr,
|
||||
preheatCtl: preheat.Ctl,
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ type projectAPI struct {
|
|||
repositoryCtl repository.Controller
|
||||
projectCtl project.Controller
|
||||
quotaCtl quota.Controller
|
||||
robotMgr robot2.Manager
|
||||
robotMgr robot.Manager
|
||||
preheatCtl preheat.Controller
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
"github.com/goharbor/harbor/src/core/config"
|
||||
"github.com/goharbor/harbor/src/lib"
|
||||
"github.com/goharbor/harbor/src/lib/errors"
|
||||
pkg "github.com/goharbor/harbor/src/pkg/robot2/model"
|
||||
pkg "github.com/goharbor/harbor/src/pkg/robot/model"
|
||||
"github.com/goharbor/harbor/src/server/v2.0/handler/model"
|
||||
"github.com/goharbor/harbor/src/server/v2.0/models"
|
||||
operation "github.com/goharbor/harbor/src/server/v2.0/restapi/operations/robot"
|
||||
|
@ -49,6 +49,7 @@ func (rAPI *robotAPI) CreateRobot(ctx context.Context, params operation.CreateRo
|
|||
Name: params.Robot.Name,
|
||||
Description: params.Robot.Description,
|
||||
Duration: params.Robot.Duration,
|
||||
Visible: true,
|
||||
},
|
||||
Level: params.Robot.Level,
|
||||
}
|
||||
|
@ -133,6 +134,7 @@ func (rAPI *robotAPI) ListRobot(ctx context.Context, params operation.ListRobotP
|
|||
level = robot.LEVELSYSTEM
|
||||
query.Keywords["ProjectID"] = 0
|
||||
}
|
||||
query.Keywords["Visible"] = true
|
||||
|
||||
if err := rAPI.requireAccess(ctx, level, projectID, rbac.ActionList); err != nil {
|
||||
return rAPI.SendError(ctx, err)
|
||||
|
|
|
@ -17,8 +17,8 @@ import (
|
|||
"github.com/goharbor/harbor/src/lib/log"
|
||||
"github.com/goharbor/harbor/src/lib/q"
|
||||
"github.com/goharbor/harbor/src/pkg/permission/types"
|
||||
pkg_robot "github.com/goharbor/harbor/src/pkg/robot2"
|
||||
pkg "github.com/goharbor/harbor/src/pkg/robot2/model"
|
||||
pkg_robot "github.com/goharbor/harbor/src/pkg/robot"
|
||||
pkg "github.com/goharbor/harbor/src/pkg/robot/model"
|
||||
handler_model "github.com/goharbor/harbor/src/server/v2.0/handler/model"
|
||||
"github.com/goharbor/harbor/src/server/v2.0/models"
|
||||
operation "github.com/goharbor/harbor/src/server/v2.0/restapi/operations/robotv1"
|
||||
|
@ -54,6 +54,7 @@ func (rAPI *robotV1API) CreateRobotV1(ctx context.Context, params operation.Crea
|
|||
Name: params.Robot.Name,
|
||||
Description: params.Robot.Description,
|
||||
ExpiresAt: params.Robot.ExpiresAt,
|
||||
Visible: true,
|
||||
},
|
||||
Level: robot.LEVELPROJECT,
|
||||
}
|
||||
|
@ -145,6 +146,7 @@ func (rAPI *robotV1API) ListRobotV1(ctx context.Context, params operation.ListRo
|
|||
if err != nil {
|
||||
return rAPI.SendError(ctx, err)
|
||||
}
|
||||
query.Keywords["Visible"] = true
|
||||
|
||||
pro, err := rAPI.projectCtr.Get(ctx, projectNameOrID)
|
||||
if err != nil {
|
||||
|
|
|
@ -30,5 +30,5 @@ package pkg
|
|||
//go:generate mockery --case snake --dir ../../pkg/user --name Manager --output ./user --outpkg user
|
||||
//go:generate mockery --case snake --dir ../../pkg/rbac --name Manager --output ./rbac --outpkg rbac
|
||||
//go:generate mockery --case snake --dir ../../pkg/rbac/dao --name DAO --output ./rbac/dao --outpkg dao
|
||||
//go:generate mockery --case snake --dir ../../pkg/robot2 --name Manager --output ./robot2 --outpkg robot2
|
||||
//go:generate mockery --case snake --dir ../../pkg/robot2/dao --name DAO --output ./robot2/dao --outpkg dao
|
||||
//go:generate mockery --case snake --dir ../../pkg/robot --name Manager --output ./robot --outpkg robot
|
||||
//go:generate mockery --case snake --dir ../../pkg/robot/dao --name DAO --output ./robot/dao --outpkg dao
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
|
||||
model "github.com/goharbor/harbor/src/pkg/robot2/model"
|
||||
model "github.com/goharbor/harbor/src/pkg/robot/model"
|
||||
|
||||
q "github.com/goharbor/harbor/src/lib/q"
|
||||
)
|
|
@ -1,11 +1,11 @@
|
|||
// Code generated by mockery v2.1.0. DO NOT EDIT.
|
||||
|
||||
package robot2
|
||||
package robot
|
||||
|
||||
import (
|
||||
context "context"
|
||||
|
||||
model "github.com/goharbor/harbor/src/pkg/robot2/model"
|
||||
model "github.com/goharbor/harbor/src/pkg/robot/model"
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
|
||||
q "github.com/goharbor/harbor/src/lib/q"
|
Loading…
Reference in New Issue
Block a user