Skip to content

Commit

Permalink
Merge branch 'main' into rb-permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
wy65701436 committed Nov 6, 2023
2 parents ac02679 + b8f65bb commit a74bbe6
Show file tree
Hide file tree
Showing 4,875 changed files with 2,100 additions and 1,504,337 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
20 changes: 10 additions & 10 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ jobs:
- ubuntu-latest
timeout-minutes: 100
steps:
- name: Set up Go 1.20
- name: Set up Go 1.21
uses: actions/setup-go@v1
with:
go-version: 1.20.10
go-version: 1.21.3
id: go
- uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -102,10 +102,10 @@ jobs:
- ubuntu-latest
timeout-minutes: 100
steps:
- name: Set up Go 1.20
- name: Set up Go 1.21
uses: actions/setup-go@v1
with:
go-version: 1.20.10
go-version: 1.21.3
id: go
- uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -157,10 +157,10 @@ jobs:
- ubuntu-latest
timeout-minutes: 100
steps:
- name: Set up Go 1.20
- name: Set up Go 1.21
uses: actions/setup-go@v1
with:
go-version: 1.20.10
go-version: 1.21.3
id: go
- uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -212,10 +212,10 @@ jobs:
- ubuntu-latest
timeout-minutes: 100
steps:
- name: Set up Go 1.20
- name: Set up Go 1.21
uses: actions/setup-go@v1
with:
go-version: 1.20.10
go-version: 1.21.3
id: go
- uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -265,10 +265,10 @@ jobs:
- ubuntu-latest
timeout-minutes: 100
steps:
- name: Set up Go 1.20
- name: Set up Go 1.21
uses: actions/setup-go@v1
with:
go-version: 1.20.10
go-version: 1.21.3
id: go
- uses: actions/checkout@v3
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
with:
version: '430.0.0'
- run: gcloud info
- name: Set up Go 1.20
- name: Set up Go 1.21
uses: actions/setup-go@v1
with:
go-version: 1.20.10
go-version: 1.21.3
id: go
- name: Setup Docker
uses: docker-practice/actions-setup-docker@master
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/conformance_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ jobs:
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'
- uses: google-github-actions/setup-gcloud@v1
- run: gcloud info
- name: Set up Go 1.20
- name: Set up Go 1.21
uses: actions/setup-go@v1
with:
go-version: 1.20.10
go-version: 1.21.3
id: go
- uses: actions/checkout@v3
with:
Expand Down
13 changes: 3 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,7 @@ The folder graph below shows the structure of the source code folder `harbor/src
│   ├── registry
│   ├── router
│   ├── v2.0
├── testing # Some utilities to handle testing.
└── vendor # Go code dependencies
├── github.com
├── golang.org
├── google.golang.org
└── gopkg.in
└── testing # Some utilities to handle testing.
```

### Setup Development Environment
Expand Down Expand Up @@ -168,12 +163,10 @@ Harbor backend is written in [Go](http://golang.org/). If you don't have a Harbo
| 2.6 | 1.18.6 |
| 2.7 | 1.19.4 |
| 2.8 | 1.20.6 |
| 2.9 | 1.20.10 |
| 2.9 | 1.21.3 |

Ensure your GOPATH and PATH have been configured in accordance with the Go environment instructions.

**Dependency Management:** Harbor uses [Go modules](https://github.com/golang/go/wiki/Modules) for dependency management of go code. The official maintainers will take the responsibility for managing the code in `vendor` directory. Please don't try to submit a PR to update the dependency code, open an issue instead. If your PR requires a change in the vendor code please make sure you discuss it with the maintainers in advance.

#### Web

Harbor web UI is built based on [Clarity](https://vmware.github.io/clarity/) and [Angular](https://angular.io/) web framework. To setup web UI development environment, please make sure the [npm](https://www.npmjs.com/get-npm) tool is installed first.
Expand Down Expand Up @@ -258,7 +251,7 @@ go install github.com/GeertJohan/fgt@latest

#In the #working_dir/harbor, run

go list ./... | grep -v -E 'vendor|tests' | xargs -L1 fgt golint
go list ./... | grep -v -E 'tests' | xargs -L1 fgt golint

```

Expand Down
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ PREPARE_VERSION_NAME=versions

#versions
REGISTRYVERSION=v2.8.2-patch-redis
TRIVYVERSION=v0.46.0
TRIVYADAPTERVERSION=v0.30.17
TRIVYVERSION=v0.46.1
TRIVYADAPTERVERSION=v0.30.18

# version of registry for pulling the source code
REGISTRY_SRC_TAG=v2.8.2
Expand Down Expand Up @@ -140,7 +140,7 @@ GOINSTALL=$(GOCMD) install
GOTEST=$(GOCMD) test
GODEP=$(GOTEST) -i
GOFMT=gofmt -w
GOBUILDIMAGE=golang:1.20.10
GOBUILDIMAGE=golang:1.21.3
GOBUILDPATHINCONTAINER=/harbor

# go build
Expand All @@ -156,7 +156,7 @@ ifneq ($(GOBUILDLDFLAGS),)
endif

# go build command
GOIMAGEBUILDCMD=/usr/local/go/bin/go build -mod vendor
GOIMAGEBUILDCMD=/usr/local/go/bin/go build
GOIMAGEBUILD_COMMON=$(GOIMAGEBUILDCMD) $(GOFLAGS) ${GOTAGS} ${GOLDFLAGS}
GOIMAGEBUILD_CORE=$(GOIMAGEBUILDCMD) $(GOFLAGS) ${GOTAGS} --ldflags "-w -s $(CORE_LDFLAGS)"

Expand Down Expand Up @@ -312,7 +312,7 @@ gen_apis: lint_apis


MOCKERY_IMAGENAME=$(IMAGENAMESPACE)/mockery
MOCKERY_VERSION=v2.22.1
MOCKERY_VERSION=v2.35.4
MOCKERY=$(RUNCONTAINER) ${MOCKERY_IMAGENAME}:${MOCKERY_VERSION}
MOCKERY_IMAGE_BUILD_CMD=${DOCKERBUILD} -f ${TOOLSPATH}/mockery/Dockerfile --build-arg GOLANG=${GOBUILDIMAGE} --build-arg MOCKERY_VERSION=${MOCKERY_VERSION} -t ${MOCKERY_IMAGENAME}:$(MOCKERY_VERSION) .

Expand Down Expand Up @@ -466,7 +466,7 @@ go_check: gen_apis mocks_check misspell commentfmt lint

commentfmt:
@echo checking comment format...
@res=$$(find . -type d \( -path ./src/vendor -o -path ./tests \) -prune -o -name '*.go' -print | xargs egrep '(^|\s)\/\/(\S)'|grep -v '//go:generate'); \
@res=$$(find . -type d \( -path ./tests \) -prune -o -name '*.go' -print | xargs egrep '(^|\s)\/\/(\S)'|grep -v '//go:generate'); \
if [ -n "$${res}" ]; then \
echo checking comment format fail.. ; \
echo missing whitespace between // and comment body;\
Expand All @@ -476,7 +476,7 @@ commentfmt:

misspell:
@echo checking misspell...
@find . -type d \( -path ./src/vendor -o -path ./tests \) -prune -o -name '*.go' -print | xargs misspell -error
@find . -type d \( -path ./tests \) -prune -o -name '*.go' -print | xargs misspell -error

# golangci-lint binary installation or refer to https://golangci-lint.run/usage/install/#local-installation
# curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.51.2
Expand Down
2 changes: 1 addition & 1 deletion make/photon/registry/Dockerfile.binary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.20.10
FROM golang:1.21.3

ENV DISTRIBUTION_DIR /go/src/github.com/docker/distribution
ENV BUILDTAGS include_oss include_gcs
Expand Down
2 changes: 1 addition & 1 deletion make/photon/trivy-adapter/Dockerfile.binary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.20.10
FROM golang:1.21.3

ADD . /go/src/github.com/aquasecurity/harbor-scanner-trivy/
WORKDIR /go/src/github.com/aquasecurity/harbor-scanner-trivy/
Expand Down
2 changes: 1 addition & 1 deletion make/photon/trivy-adapter/builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ TEMP=$(mktemp -d ${TMPDIR-/tmp}/trivy-adapter.XXXXXX)
git clone https://github.com/aquasecurity/harbor-scanner-trivy.git $TEMP
cd $TEMP; git checkout $VERSION; cd -

echo "Building Trivy adapter binary based on golang:1.20.10..."
echo "Building Trivy adapter binary based on golang:1.21.3..."
cp Dockerfile.binary $TEMP
docker build -f $TEMP/Dockerfile.binary -t trivy-adapter-golang $TEMP

Expand Down
2 changes: 2 additions & 0 deletions src/common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,6 @@ const (
ExecutionStatusRefreshIntervalSeconds = "execution_status_refresh_interval_seconds"
// QuotaUpdateProvider is the provider for updating quota, currently support Redis and DB
QuotaUpdateProvider = "quota_update_provider"
// IllegalCharsInUsername is the illegal chars in username
IllegalCharsInUsername = `,"~#%$`
)
10 changes: 0 additions & 10 deletions src/common/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,16 +247,6 @@ func IsIllegalLength(s string, min int, max int) bool {
return (len(s) < min || len(s) > max)
}

// IsContainIllegalChar ...
func IsContainIllegalChar(s string, illegalChar []string) bool {
for _, c := range illegalChar {
if strings.Contains(s, c) {
return true
}
}
return false
}

// ParseJSONInt ...
func ParseJSONInt(value interface{}) (int, bool) {
switch v := value.(type) {
Expand Down
7 changes: 4 additions & 3 deletions src/controller/event/handler/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ func init() {
_ = notifier.Subscribe(event.TopicDeleteTag, &auditlog.Handler{})

// internal
_ = notifier.Subscribe(event.TopicPullArtifact, &internal.Handler{})
_ = notifier.Subscribe(event.TopicPushArtifact, &internal.Handler{})
_ = notifier.Subscribe(event.TopicDeleteArtifact, &internal.Handler{})
_ = notifier.Subscribe(event.TopicPullArtifact, &internal.ArtifactEventHandler{})
_ = notifier.Subscribe(event.TopicPushArtifact, &internal.ArtifactEventHandler{})
_ = notifier.Subscribe(event.TopicDeleteArtifact, &internal.ArtifactEventHandler{})
_ = notifier.Subscribe(event.TopicDeleteProject, &internal.ProjectEventHandler{})

_ = task.RegisterTaskStatusChangePostFunc(job.ReplicationVendorType, func(ctx context.Context, taskID int64, status string) error {
notification.AddEvent(ctx, &metadata.ReplicationMetaData{
Expand Down
28 changes: 14 additions & 14 deletions src/controller/event/handler/internal/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func init() {
}
}

// Handler preprocess artifact event data
type Handler struct {
// ArtifactEventHandler preprocess artifact event data
type ArtifactEventHandler struct {
// execMgr for managing executions
execMgr task.ExecutionManager
// reportMgr for managing scan reports
Expand All @@ -89,12 +89,12 @@ type Handler struct {
}

// Name ...
func (a *Handler) Name() string {
func (a *ArtifactEventHandler) Name() string {
return "InternalArtifact"
}

// Handle ...
func (a *Handler) Handle(ctx context.Context, value interface{}) error {
func (a *ArtifactEventHandler) Handle(ctx context.Context, value interface{}) error {
switch v := value.(type) {
case *event.PullArtifactEvent:
return a.onPull(ctx, v.ArtifactEvent)
Expand All @@ -109,11 +109,11 @@ func (a *Handler) Handle(ctx context.Context, value interface{}) error {
}

// IsStateful ...
func (a *Handler) IsStateful() bool {
func (a *ArtifactEventHandler) IsStateful() bool {
return false
}

func (a *Handler) onPull(ctx context.Context, event *event.ArtifactEvent) error {
func (a *ArtifactEventHandler) onPull(ctx context.Context, event *event.ArtifactEvent) error {
if config.ScannerSkipUpdatePullTime(ctx) && isScannerUser(ctx, event) {
return nil
}
Expand Down Expand Up @@ -159,7 +159,7 @@ func (a *Handler) onPull(ctx context.Context, event *event.ArtifactEvent) error
return nil
}

func (a *Handler) updatePullTimeInCache(ctx context.Context, event *event.ArtifactEvent) {
func (a *ArtifactEventHandler) updatePullTimeInCache(ctx context.Context, event *event.ArtifactEvent) {
var tagName string
if len(event.Tags) != 0 {
tagName = event.Tags[0]
Expand All @@ -173,14 +173,14 @@ func (a *Handler) updatePullTimeInCache(ctx context.Context, event *event.Artifa
a.pullTimeStore[key] = time.Now()
}

func (a *Handler) addPullCountInCache(ctx context.Context, event *event.ArtifactEvent) {
func (a *ArtifactEventHandler) addPullCountInCache(ctx context.Context, event *event.ArtifactEvent) {
a.pullCountLock.Lock()
defer a.pullCountLock.Unlock()

a.pullCountStore[event.Artifact.RepositoryID] = a.pullCountStore[event.Artifact.RepositoryID] + 1
}

func (a *Handler) syncFlushPullTime(ctx context.Context, artifactID int64, tagName string, time time.Time) {
func (a *ArtifactEventHandler) syncFlushPullTime(ctx context.Context, artifactID int64, tagName string, time time.Time) {
var tagID int64

if tagName != "" {
Expand All @@ -203,13 +203,13 @@ func (a *Handler) syncFlushPullTime(ctx context.Context, artifactID int64, tagNa
}
}

func (a *Handler) syncFlushPullCount(ctx context.Context, repositoryID int64, count uint64) {
func (a *ArtifactEventHandler) syncFlushPullCount(ctx context.Context, repositoryID int64, count uint64) {
if err := repository.Ctl.AddPullCount(ctx, repositoryID, count); err != nil {
log.Warningf("failed to add pull count repository %d, %v", repositoryID, err)
}
}

func (a *Handler) asyncFlushPullTime(ctx context.Context) {
func (a *ArtifactEventHandler) asyncFlushPullTime(ctx context.Context) {
for {
<-time.After(asyncFlushDuration)
a.pullTimeLock.Lock()
Expand All @@ -235,7 +235,7 @@ func (a *Handler) asyncFlushPullTime(ctx context.Context) {
}
}

func (a *Handler) asyncFlushPullCount(ctx context.Context) {
func (a *ArtifactEventHandler) asyncFlushPullCount(ctx context.Context) {
for {
<-time.After(asyncFlushDuration)
a.pullCountLock.Lock()
Expand All @@ -249,7 +249,7 @@ func (a *Handler) asyncFlushPullCount(ctx context.Context) {
}
}

func (a *Handler) onPush(ctx context.Context, event *event.ArtifactEvent) error {
func (a *ArtifactEventHandler) onPush(ctx context.Context, event *event.ArtifactEvent) error {
go func() {
if event.Operator != "" {
ctx = context.WithValue(ctx, operator.ContextKey{}, event.Operator)
Expand All @@ -263,7 +263,7 @@ func (a *Handler) onPush(ctx context.Context, event *event.ArtifactEvent) error
return nil
}

func (a *Handler) onDelete(ctx context.Context, event *event.ArtifactEvent) error {
func (a *ArtifactEventHandler) onDelete(ctx context.Context, event *event.ArtifactEvent) error {
execMgr := task.ExecMgr
reportMgr := report.Mgr
artMgr := pkg.ArtifactMgr
Expand Down
4 changes: 2 additions & 2 deletions src/controller/event/handler/internal/artifact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type ArtifactHandlerTestSuite struct {
suite.Suite

ctx context.Context
handler *Handler
handler *ArtifactEventHandler
projectManager project.Manager
scannerCtl scanner.Controller
reportMgr *reportMock.Manager
Expand All @@ -70,7 +70,7 @@ func (suite *ArtifactHandlerTestSuite) SetupSuite() {
suite.execMgr = &taskMock.ExecutionManager{}
suite.reportMgr = &reportMock.Manager{}
suite.artMgr = &artMock.Manager{}
suite.handler = &Handler{execMgr: suite.execMgr, reportMgr: suite.reportMgr, artMgr: suite.artMgr}
suite.handler = &ArtifactEventHandler{execMgr: suite.execMgr, reportMgr: suite.reportMgr, artMgr: suite.artMgr}

// mock artifact
_, err := pkg.ArtifactMgr.Create(suite.ctx, &artifact.Artifact{ID: 1, RepositoryID: 1})
Expand Down

0 comments on commit a74bbe6

Please sign in to comment.