refactor(quota): move pkg/types to pkg/quota/types

Closes #9664

Signed-off-by: He Weiwei <hweiwei@vmware.com>
This commit is contained in:
He Weiwei 2020-07-14 14:28:53 +00:00
parent c000608d55
commit a22d803a95
39 changed files with 36 additions and 63 deletions

View File

@ -18,7 +18,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/goharbor/harbor/src/pkg/types" "github.com/goharbor/harbor/src/pkg/quota/types"
) )
const ( const (

View File

@ -27,7 +27,7 @@ import (
"github.com/goharbor/harbor/src/lib/q" "github.com/goharbor/harbor/src/lib/q"
"github.com/goharbor/harbor/src/pkg/quota" "github.com/goharbor/harbor/src/pkg/quota"
"github.com/goharbor/harbor/src/pkg/quota/driver" "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 // quota driver
_ "github.com/goharbor/harbor/src/controller/quota/driver" _ "github.com/goharbor/harbor/src/controller/quota/driver"

View File

@ -24,7 +24,7 @@ import (
"github.com/goharbor/harbor/src/lib/orm" "github.com/goharbor/harbor/src/lib/orm"
"github.com/goharbor/harbor/src/pkg/quota" "github.com/goharbor/harbor/src/pkg/quota"
"github.com/goharbor/harbor/src/pkg/quota/driver" "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" ormtesting "github.com/goharbor/harbor/src/testing/lib/orm"
"github.com/goharbor/harbor/src/testing/mock" "github.com/goharbor/harbor/src/testing/mock"
quotatesting "github.com/goharbor/harbor/src/testing/pkg/quota" quotatesting "github.com/goharbor/harbor/src/testing/pkg/quota"

View File

@ -25,7 +25,7 @@ import (
"github.com/goharbor/harbor/src/controller/blob" "github.com/goharbor/harbor/src/controller/blob"
"github.com/goharbor/harbor/src/lib/log" "github.com/goharbor/harbor/src/lib/log"
dr "github.com/goharbor/harbor/src/pkg/quota/driver" 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" "github.com/graph-gophers/dataloader"
) )

View File

@ -18,7 +18,7 @@ import (
"context" "context"
"testing" "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" artifacttesting "github.com/goharbor/harbor/src/testing/controller/artifact"
blobtesting "github.com/goharbor/harbor/src/testing/controller/blob" blobtesting "github.com/goharbor/harbor/src/testing/controller/blob"
"github.com/goharbor/harbor/src/testing/mock" "github.com/goharbor/harbor/src/testing/mock"

View File

@ -25,7 +25,7 @@ import (
"github.com/goharbor/harbor/src/lib/orm" "github.com/goharbor/harbor/src/lib/orm"
"github.com/goharbor/harbor/src/pkg/quota" "github.com/goharbor/harbor/src/pkg/quota"
"github.com/goharbor/harbor/src/pkg/quota/driver" "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" projecttesting "github.com/goharbor/harbor/src/testing/controller/project"
ormtesting "github.com/goharbor/harbor/src/testing/lib/orm" ormtesting "github.com/goharbor/harbor/src/testing/lib/orm"
"github.com/goharbor/harbor/src/testing/mock" "github.com/goharbor/harbor/src/testing/mock"

View File

@ -17,7 +17,6 @@ package api
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/goharbor/harbor/src/replication"
"net/http" "net/http"
"regexp" "regexp"
"strconv" "strconv"
@ -38,8 +37,9 @@ import (
"github.com/goharbor/harbor/src/lib/errors" "github.com/goharbor/harbor/src/lib/errors"
"github.com/goharbor/harbor/src/lib/log" "github.com/goharbor/harbor/src/lib/log"
evt "github.com/goharbor/harbor/src/pkg/notifier/event" 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/scan/vuln"
"github.com/goharbor/harbor/src/pkg/types" "github.com/goharbor/harbor/src/replication"
) )
type deletableResp struct { type deletableResp struct {

View File

@ -21,7 +21,7 @@ import (
"github.com/goharbor/harbor/src/lib/errors" "github.com/goharbor/harbor/src/lib/errors"
"github.com/goharbor/harbor/src/lib/q" "github.com/goharbor/harbor/src/lib/q"
"github.com/goharbor/harbor/src/pkg/quota/models" "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 // QuotaUpdateRequest struct for the body of put quota API

View File

@ -23,7 +23,7 @@ import (
"github.com/goharbor/harbor/src/controller/quota" "github.com/goharbor/harbor/src/controller/quota"
"github.com/goharbor/harbor/src/lib/orm" "github.com/goharbor/harbor/src/lib/orm"
"github.com/goharbor/harbor/src/pkg/quota/driver" "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/apitests/apilib"
"github.com/goharbor/harbor/src/testing/mock" "github.com/goharbor/harbor/src/testing/mock"
drivertesting "github.com/goharbor/harbor/src/testing/pkg/quota/driver" drivertesting "github.com/goharbor/harbor/src/testing/pkg/quota/driver"

View File

@ -24,7 +24,7 @@ import (
"github.com/goharbor/harbor/src/lib/q" "github.com/goharbor/harbor/src/lib/q"
"github.com/goharbor/harbor/src/pkg/quota/driver" "github.com/goharbor/harbor/src/pkg/quota/driver"
"github.com/goharbor/harbor/src/pkg/quota/models" "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 // DAO the dao for Quota and QuotaUsage

View File

@ -21,7 +21,7 @@ import (
"github.com/goharbor/harbor/src/lib/orm" "github.com/goharbor/harbor/src/lib/orm"
"github.com/goharbor/harbor/src/lib/q" "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" htesting "github.com/goharbor/harbor/src/testing"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"

View File

@ -21,7 +21,7 @@ import (
"github.com/goharbor/harbor/src/lib/orm" "github.com/goharbor/harbor/src/lib/orm"
"github.com/goharbor/harbor/src/lib/q" "github.com/goharbor/harbor/src/lib/q"
"github.com/goharbor/harbor/src/pkg/types" "github.com/goharbor/harbor/src/pkg/quota/types"
) )
var ( var (

View File

@ -18,7 +18,7 @@ import (
"context" "context"
"sync" "sync"
"github.com/goharbor/harbor/src/pkg/types" "github.com/goharbor/harbor/src/pkg/quota/types"
) )
var ( var (

View File

@ -18,7 +18,7 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/goharbor/harbor/src/pkg/types" "github.com/goharbor/harbor/src/pkg/quota/types"
) )
// Errors contains all happened errors // Errors contains all happened errors

View File

@ -21,7 +21,7 @@ import (
"github.com/goharbor/harbor/src/lib/q" "github.com/goharbor/harbor/src/lib/q"
"github.com/goharbor/harbor/src/pkg/quota/dao" "github.com/goharbor/harbor/src/pkg/quota/dao"
"github.com/goharbor/harbor/src/pkg/quota/models" "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 // Quota alias `models.Quota` to make it natural to use the Manager

View File

@ -17,7 +17,7 @@ package quota
import ( import (
"testing" "testing"
"github.com/goharbor/harbor/src/pkg/types" "github.com/goharbor/harbor/src/pkg/quota/types"
htesting "github.com/goharbor/harbor/src/testing" htesting "github.com/goharbor/harbor/src/testing"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
) )

View File

@ -20,7 +20,7 @@ import (
"time" "time"
"github.com/goharbor/harbor/src/pkg/quota/driver" "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 // Quota quota model for manager

View File

@ -17,7 +17,7 @@ package models
import ( import (
"testing" "testing"
"github.com/goharbor/harbor/src/pkg/types" "github.com/goharbor/harbor/src/pkg/quota/types"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )

View File

@ -18,7 +18,7 @@ import (
"sort" "sort"
"strings" "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 // IsSafe check new used is safe under the hard limits

View File

@ -17,7 +17,7 @@ package quota
import ( import (
"testing" "testing"
"github.com/goharbor/harbor/src/pkg/types" "github.com/goharbor/harbor/src/pkg/quota/types"
) )
func TestIsSafe(t *testing.T) { func TestIsSafe(t *testing.T) {

View File

@ -21,8 +21,8 @@ import (
"github.com/astaxie/beego/orm" "github.com/astaxie/beego/orm"
"github.com/goharbor/harbor/src/common/dao" "github.com/goharbor/harbor/src/common/dao"
"github.com/goharbor/harbor/src/lib/errors" "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/lib/q"
"github.com/goharbor/harbor/src/pkg/types"
) )
func init() { func init() {
@ -35,10 +35,7 @@ func AddRegistration(r *Registration) (int64, error) {
id, err := o.Insert(r) id, err := o.Insert(r)
if err != nil { if err != nil {
if strings.Contains(err.Error(), "duplicate key value violates unique constraint") { return 0, liborm.WrapConflictError(err, "registration name or url already exists")
return 0, types.ErrDupRows
}
return 0, err
} }
return id, nil return id, nil

View File

@ -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")
)

View File

@ -42,7 +42,7 @@ import (
"github.com/goharbor/harbor/src/pkg/blob" "github.com/goharbor/harbor/src/pkg/blob"
"github.com/goharbor/harbor/src/pkg/distribution" "github.com/goharbor/harbor/src/pkg/distribution"
"github.com/goharbor/harbor/src/pkg/notifier/event" "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 // CopyArtifactMiddleware middleware to request count and storage resources for copy artifact API

View File

@ -37,7 +37,7 @@ import (
"github.com/goharbor/harbor/src/controller/artifact" "github.com/goharbor/harbor/src/controller/artifact"
"github.com/goharbor/harbor/src/pkg/notification" "github.com/goharbor/harbor/src/pkg/notification"
"github.com/goharbor/harbor/src/pkg/quota" "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/goharbor/harbor/src/testing/mock"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
) )

View File

@ -21,7 +21,7 @@ import (
"github.com/goharbor/harbor/src/controller/blob" "github.com/goharbor/harbor/src/controller/blob"
"github.com/goharbor/harbor/src/lib/errors" "github.com/goharbor/harbor/src/lib/errors"
"github.com/goharbor/harbor/src/lib/log" "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 // PostInitiateBlobUploadMiddleware middleware to add blob to project after mount blob success

View File

@ -21,7 +21,7 @@ import (
"github.com/goharbor/harbor/src/pkg/blob" "github.com/goharbor/harbor/src/pkg/blob"
"github.com/goharbor/harbor/src/pkg/quota" "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/goharbor/harbor/src/testing/mock"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
) )

View File

@ -21,7 +21,7 @@ import (
"github.com/goharbor/harbor/src/controller/blob" "github.com/goharbor/harbor/src/controller/blob"
"github.com/goharbor/harbor/src/lib/log" "github.com/goharbor/harbor/src/lib/log"
"github.com/goharbor/harbor/src/pkg/distribution" "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 // PutBlobUploadMiddleware middleware to request storage resource for the project

View File

@ -25,7 +25,7 @@ import (
"github.com/goharbor/harbor/src/lib/errors" "github.com/goharbor/harbor/src/lib/errors"
"github.com/goharbor/harbor/src/pkg/notification" "github.com/goharbor/harbor/src/pkg/notification"
"github.com/goharbor/harbor/src/pkg/quota" "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/goharbor/harbor/src/testing/mock"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
) )

View File

@ -22,7 +22,7 @@ import (
"github.com/goharbor/harbor/src/lib/errors" "github.com/goharbor/harbor/src/lib/errors"
"github.com/goharbor/harbor/src/lib/log" "github.com/goharbor/harbor/src/lib/log"
"github.com/goharbor/harbor/src/pkg/blob/models" "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 // PutManifestMiddleware middleware to request count and storage resources for the project

View File

@ -29,7 +29,7 @@ import (
"github.com/goharbor/harbor/src/pkg/distribution" "github.com/goharbor/harbor/src/pkg/distribution"
"github.com/goharbor/harbor/src/pkg/notification" "github.com/goharbor/harbor/src/pkg/notification"
"github.com/goharbor/harbor/src/pkg/quota" "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/goharbor/harbor/src/testing/mock"
distributiontesting "github.com/goharbor/harbor/src/testing/pkg/distribution" distributiontesting "github.com/goharbor/harbor/src/testing/pkg/distribution"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"

View File

@ -27,7 +27,7 @@ import (
"github.com/goharbor/harbor/src/pkg/notification" "github.com/goharbor/harbor/src/pkg/notification"
"github.com/goharbor/harbor/src/pkg/notifier/event" "github.com/goharbor/harbor/src/pkg/notifier/event"
"github.com/goharbor/harbor/src/pkg/quota" "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" "github.com/goharbor/harbor/src/server/middleware"
) )

View File

@ -26,7 +26,7 @@ import (
"github.com/goharbor/harbor/src/controller/project" "github.com/goharbor/harbor/src/controller/project"
"github.com/goharbor/harbor/src/controller/quota" "github.com/goharbor/harbor/src/controller/quota"
pquota "github.com/goharbor/harbor/src/pkg/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" artifacttesting "github.com/goharbor/harbor/src/testing/controller/artifact"
blobtesting "github.com/goharbor/harbor/src/testing/controller/blob" blobtesting "github.com/goharbor/harbor/src/testing/controller/blob"
projecttesting "github.com/goharbor/harbor/src/testing/controller/project" projecttesting "github.com/goharbor/harbor/src/testing/controller/project"

View File

@ -12,7 +12,7 @@ import (
quota "github.com/goharbor/harbor/src/controller/quota" 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 // Controller is an autogenerated mock type for the Controller type

View File

@ -8,7 +8,7 @@ import (
driver "github.com/goharbor/harbor/src/pkg/quota/driver" driver "github.com/goharbor/harbor/src/pkg/quota/driver"
mock "github.com/stretchr/testify/mock" 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 // Driver is an autogenerated mock type for the Driver type

View File

@ -10,7 +10,7 @@ import (
q "github.com/goharbor/harbor/src/lib/q" 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 // Manager is an autogenerated mock type for the Manager type