mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-18 22:57:38 +01:00
refactor(quota): move pkg/types to pkg/quota/types
Closes #9664 Signed-off-by: He Weiwei <hweiwei@vmware.com>
This commit is contained in:
parent
c000608d55
commit
a22d803a95
@ -18,7 +18,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/goharbor/harbor/src/pkg/types"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -27,7 +27,7 @@ import (
|
||||
"github.com/goharbor/harbor/src/lib/q"
|
||||
"github.com/goharbor/harbor/src/pkg/quota"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/driver"
|
||||
"github.com/goharbor/harbor/src/pkg/types"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
|
||||
// quota driver
|
||||
_ "github.com/goharbor/harbor/src/controller/quota/driver"
|
||||
|
@ -24,7 +24,7 @@ import (
|
||||
"github.com/goharbor/harbor/src/lib/orm"
|
||||
"github.com/goharbor/harbor/src/pkg/quota"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/driver"
|
||||
"github.com/goharbor/harbor/src/pkg/types"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
ormtesting "github.com/goharbor/harbor/src/testing/lib/orm"
|
||||
"github.com/goharbor/harbor/src/testing/mock"
|
||||
quotatesting "github.com/goharbor/harbor/src/testing/pkg/quota"
|
||||
|
@ -25,7 +25,7 @@ import (
|
||||
"github.com/goharbor/harbor/src/controller/blob"
|
||||
"github.com/goharbor/harbor/src/lib/log"
|
||||
dr "github.com/goharbor/harbor/src/pkg/quota/driver"
|
||||
"github.com/goharbor/harbor/src/pkg/types"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
"github.com/graph-gophers/dataloader"
|
||||
)
|
||||
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/goharbor/harbor/src/pkg/types"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
artifacttesting "github.com/goharbor/harbor/src/testing/controller/artifact"
|
||||
blobtesting "github.com/goharbor/harbor/src/testing/controller/blob"
|
||||
"github.com/goharbor/harbor/src/testing/mock"
|
||||
|
@ -25,7 +25,7 @@ import (
|
||||
"github.com/goharbor/harbor/src/lib/orm"
|
||||
"github.com/goharbor/harbor/src/pkg/quota"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/driver"
|
||||
"github.com/goharbor/harbor/src/pkg/types"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
projecttesting "github.com/goharbor/harbor/src/testing/controller/project"
|
||||
ormtesting "github.com/goharbor/harbor/src/testing/lib/orm"
|
||||
"github.com/goharbor/harbor/src/testing/mock"
|
||||
|
@ -17,7 +17,6 @@ package api
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/goharbor/harbor/src/replication"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strconv"
|
||||
@ -38,8 +37,9 @@ import (
|
||||
"github.com/goharbor/harbor/src/lib/errors"
|
||||
"github.com/goharbor/harbor/src/lib/log"
|
||||
evt "github.com/goharbor/harbor/src/pkg/notifier/event"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
"github.com/goharbor/harbor/src/pkg/scan/vuln"
|
||||
"github.com/goharbor/harbor/src/pkg/types"
|
||||
"github.com/goharbor/harbor/src/replication"
|
||||
)
|
||||
|
||||
type deletableResp struct {
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
"github.com/goharbor/harbor/src/lib/errors"
|
||||
"github.com/goharbor/harbor/src/lib/q"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/models"
|
||||
"github.com/goharbor/harbor/src/pkg/types"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
)
|
||||
|
||||
// QuotaUpdateRequest struct for the body of put quota API
|
||||
|
@ -23,7 +23,7 @@ import (
|
||||
"github.com/goharbor/harbor/src/controller/quota"
|
||||
"github.com/goharbor/harbor/src/lib/orm"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/driver"
|
||||
"github.com/goharbor/harbor/src/pkg/types"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
"github.com/goharbor/harbor/src/testing/apitests/apilib"
|
||||
"github.com/goharbor/harbor/src/testing/mock"
|
||||
drivertesting "github.com/goharbor/harbor/src/testing/pkg/quota/driver"
|
||||
|
@ -24,7 +24,7 @@ import (
|
||||
"github.com/goharbor/harbor/src/lib/q"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/driver"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/models"
|
||||
"github.com/goharbor/harbor/src/pkg/types"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
)
|
||||
|
||||
// DAO the dao for Quota and QuotaUsage
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
|
||||
"github.com/goharbor/harbor/src/lib/orm"
|
||||
"github.com/goharbor/harbor/src/lib/q"
|
||||
"github.com/goharbor/harbor/src/pkg/types"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
htesting "github.com/goharbor/harbor/src/testing"
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
|
||||
"github.com/goharbor/harbor/src/lib/orm"
|
||||
"github.com/goharbor/harbor/src/lib/q"
|
||||
"github.com/goharbor/harbor/src/pkg/types"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"github.com/goharbor/harbor/src/pkg/types"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/goharbor/harbor/src/pkg/types"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
)
|
||||
|
||||
// Errors contains all happened errors
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
"github.com/goharbor/harbor/src/lib/q"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/dao"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/models"
|
||||
"github.com/goharbor/harbor/src/pkg/types"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
)
|
||||
|
||||
// Quota alias `models.Quota` to make it natural to use the Manager
|
||||
|
@ -17,7 +17,7 @@ package quota
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/goharbor/harbor/src/pkg/types"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
htesting "github.com/goharbor/harbor/src/testing"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
@ -20,7 +20,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/goharbor/harbor/src/pkg/quota/driver"
|
||||
"github.com/goharbor/harbor/src/pkg/types"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
)
|
||||
|
||||
// Quota quota model for manager
|
||||
|
@ -17,7 +17,7 @@ package models
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/goharbor/harbor/src/pkg/types"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/goharbor/harbor/src/pkg/types"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
)
|
||||
|
||||
// IsSafe check new used is safe under the hard limits
|
||||
|
@ -17,7 +17,7 @@ package quota
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/goharbor/harbor/src/pkg/types"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
)
|
||||
|
||||
func TestIsSafe(t *testing.T) {
|
||||
|
@ -21,8 +21,8 @@ import (
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/goharbor/harbor/src/common/dao"
|
||||
"github.com/goharbor/harbor/src/lib/errors"
|
||||
liborm "github.com/goharbor/harbor/src/lib/orm"
|
||||
"github.com/goharbor/harbor/src/lib/q"
|
||||
"github.com/goharbor/harbor/src/pkg/types"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -35,10 +35,7 @@ func AddRegistration(r *Registration) (int64, error) {
|
||||
|
||||
id, err := o.Insert(r)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "duplicate key value violates unique constraint") {
|
||||
return 0, types.ErrDupRows
|
||||
}
|
||||
return 0, err
|
||||
return 0, liborm.WrapConflictError(err, "registration name or url already exists")
|
||||
}
|
||||
|
||||
return id, nil
|
||||
|
@ -1,24 +0,0 @@
|
||||
// Copyright Project Harbor Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package types
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrDupRows is returned by DAO when inserting failed with error "duplicate key value violates unique constraint"
|
||||
ErrDupRows = errors.New("sql: duplicate row in DB")
|
||||
)
|
@ -42,7 +42,7 @@ import (
|
||||
"github.com/goharbor/harbor/src/pkg/blob"
|
||||
"github.com/goharbor/harbor/src/pkg/distribution"
|
||||
"github.com/goharbor/harbor/src/pkg/notifier/event"
|
||||
"github.com/goharbor/harbor/src/pkg/types"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
)
|
||||
|
||||
// CopyArtifactMiddleware middleware to request count and storage resources for copy artifact API
|
||||
|
@ -37,7 +37,7 @@ import (
|
||||
"github.com/goharbor/harbor/src/controller/artifact"
|
||||
"github.com/goharbor/harbor/src/pkg/notification"
|
||||
"github.com/goharbor/harbor/src/pkg/quota"
|
||||
"github.com/goharbor/harbor/src/pkg/types"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
"github.com/goharbor/harbor/src/testing/mock"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
"github.com/goharbor/harbor/src/controller/blob"
|
||||
"github.com/goharbor/harbor/src/lib/errors"
|
||||
"github.com/goharbor/harbor/src/lib/log"
|
||||
"github.com/goharbor/harbor/src/pkg/types"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
)
|
||||
|
||||
// PostInitiateBlobUploadMiddleware middleware to add blob to project after mount blob success
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
|
||||
"github.com/goharbor/harbor/src/pkg/blob"
|
||||
"github.com/goharbor/harbor/src/pkg/quota"
|
||||
"github.com/goharbor/harbor/src/pkg/types"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
"github.com/goharbor/harbor/src/testing/mock"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
"github.com/goharbor/harbor/src/controller/blob"
|
||||
"github.com/goharbor/harbor/src/lib/log"
|
||||
"github.com/goharbor/harbor/src/pkg/distribution"
|
||||
"github.com/goharbor/harbor/src/pkg/types"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
)
|
||||
|
||||
// PutBlobUploadMiddleware middleware to request storage resource for the project
|
||||
|
@ -25,7 +25,7 @@ import (
|
||||
"github.com/goharbor/harbor/src/lib/errors"
|
||||
"github.com/goharbor/harbor/src/pkg/notification"
|
||||
"github.com/goharbor/harbor/src/pkg/quota"
|
||||
"github.com/goharbor/harbor/src/pkg/types"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
"github.com/goharbor/harbor/src/testing/mock"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
@ -22,7 +22,7 @@ import (
|
||||
"github.com/goharbor/harbor/src/lib/errors"
|
||||
"github.com/goharbor/harbor/src/lib/log"
|
||||
"github.com/goharbor/harbor/src/pkg/blob/models"
|
||||
"github.com/goharbor/harbor/src/pkg/types"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
)
|
||||
|
||||
// PutManifestMiddleware middleware to request count and storage resources for the project
|
||||
|
@ -29,7 +29,7 @@ import (
|
||||
"github.com/goharbor/harbor/src/pkg/distribution"
|
||||
"github.com/goharbor/harbor/src/pkg/notification"
|
||||
"github.com/goharbor/harbor/src/pkg/quota"
|
||||
"github.com/goharbor/harbor/src/pkg/types"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
"github.com/goharbor/harbor/src/testing/mock"
|
||||
distributiontesting "github.com/goharbor/harbor/src/testing/pkg/distribution"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
@ -27,7 +27,7 @@ import (
|
||||
"github.com/goharbor/harbor/src/pkg/notification"
|
||||
"github.com/goharbor/harbor/src/pkg/notifier/event"
|
||||
"github.com/goharbor/harbor/src/pkg/quota"
|
||||
"github.com/goharbor/harbor/src/pkg/types"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
"github.com/goharbor/harbor/src/server/middleware"
|
||||
)
|
||||
|
||||
|
@ -26,7 +26,7 @@ import (
|
||||
"github.com/goharbor/harbor/src/controller/project"
|
||||
"github.com/goharbor/harbor/src/controller/quota"
|
||||
pquota "github.com/goharbor/harbor/src/pkg/quota"
|
||||
"github.com/goharbor/harbor/src/pkg/types"
|
||||
"github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
artifacttesting "github.com/goharbor/harbor/src/testing/controller/artifact"
|
||||
blobtesting "github.com/goharbor/harbor/src/testing/controller/blob"
|
||||
projecttesting "github.com/goharbor/harbor/src/testing/controller/project"
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
|
||||
quota "github.com/goharbor/harbor/src/controller/quota"
|
||||
|
||||
types "github.com/goharbor/harbor/src/pkg/types"
|
||||
types "github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
)
|
||||
|
||||
// Controller is an autogenerated mock type for the Controller type
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
driver "github.com/goharbor/harbor/src/pkg/quota/driver"
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
|
||||
types "github.com/goharbor/harbor/src/pkg/types"
|
||||
types "github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
)
|
||||
|
||||
// Driver is an autogenerated mock type for the Driver type
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
|
||||
q "github.com/goharbor/harbor/src/lib/q"
|
||||
|
||||
types "github.com/goharbor/harbor/src/pkg/types"
|
||||
types "github.com/goharbor/harbor/src/pkg/quota/types"
|
||||
)
|
||||
|
||||
// Manager is an autogenerated mock type for the Manager type
|
||||
|
Loading…
Reference in New Issue
Block a user