Provide a null implementation for Harbor adapter

This commit provides a null implementation for Harbor adapter to fill data for the listing adapter API

Signed-off-by: Wenkai Yin <yinw@vmware.com>
This commit is contained in:
Wenkai Yin 2019-03-11 18:52:57 +08:00
parent 2911ac7a34
commit 272508e509
4 changed files with 101 additions and 1 deletions

1
.gitignore vendored
View File

@ -1,4 +1,3 @@
harbor
!/contrib/helm/harbor !/contrib/helm/harbor
make/docker-compose.yml make/docker-compose.yml

View File

@ -0,0 +1,59 @@
// 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 harbor
import (
"github.com/goharbor/harbor/src/common/utils/log"
adp "github.com/goharbor/harbor/src/replication/ng/adapter"
"github.com/goharbor/harbor/src/replication/ng/model"
)
const (
harbor model.RegistryType = "Harbor"
)
func init() {
// TODO add more information to the info
info := &adp.Info{
Type: harbor,
SupportedResourceTypes: []model.ResourceType{model.ResourceTypeRepository},
}
if err := adp.RegisterFactory(info, func(registry *model.Registry) (adp.Adapter, error) {
return newAdapter(registry), nil
}); err != nil {
log.Errorf("failed to register factory for %s: %v", harbor, err)
return
}
log.Infof("the factory for adapter %s registered", harbor)
}
// TODO implement the functions
type adapter struct {
*adp.DefaultImageRegistry
}
func newAdapter(registry *model.Registry) *adapter {
return &adapter{}
}
func (a *adapter) ListNamespaces(*model.NamespaceQuery) ([]*model.Namespace, error) {
return nil, nil
}
func (a *adapter) CreateNamespace(*model.Namespace) error {
return nil
}
func (a *adapter) GetNamespace(string) (*model.Namespace, error) {
return nil, nil
}

View File

@ -31,3 +31,43 @@ type ImageRegistry interface {
PullBlob(repository, digest string) (size int64, blob io.ReadCloser, err error) PullBlob(repository, digest string) (size int64, blob io.ReadCloser, err error)
PushBlob(repository, digest string, size int64, blob io.Reader) error PushBlob(repository, digest string, size int64, blob io.Reader) error
} }
// TODO implement the functions
// DefaultImageRegistry provides a default implementation for interface ImageRegistry
type DefaultImageRegistry struct{}
// FetchImages ...
func (d *DefaultImageRegistry) FetchImages(namespaces []string, filters []*model.Filter) ([]*model.Resource, error) {
return nil, nil
}
// ManifestExist ...
func (d *DefaultImageRegistry) ManifestExist(repository, reference string) (exist bool, digest string, err error) {
return false, "", nil
}
// PullManifest ...
func (d *DefaultImageRegistry) PullManifest(repository, reference string, accepttedMediaTypes []string) (manifest distribution.Manifest, digest string, err error) {
return nil, "", nil
}
// PushManifest ...
func (d *DefaultImageRegistry) PushManifest(repository, reference, mediaType string, payload []byte) error {
return nil
}
// BlobExist ...
func (d *DefaultImageRegistry) BlobExist(repository, digest string) (exist bool, err error) {
return false, nil
}
// PullBlob ...
func (d *DefaultImageRegistry) PullBlob(repository, digest string) (size int64, blob io.ReadCloser, err error) {
return 0, nil, nil
}
// PushBlob ...
func (d *DefaultImageRegistry) PushBlob(repository, digest string, size int64, blob io.Reader) error {
return nil
}

View File

@ -25,6 +25,8 @@ import (
"github.com/goharbor/harbor/src/replication/ng/scheduler" "github.com/goharbor/harbor/src/replication/ng/scheduler"
// register the Harbor adapter
_ "github.com/goharbor/harbor/src/replication/ng/adapter/harbor"
"github.com/goharbor/harbor/src/replication/ng/flow" "github.com/goharbor/harbor/src/replication/ng/flow"
"github.com/goharbor/harbor/src/replication/ng/operation" "github.com/goharbor/harbor/src/replication/ng/operation"
"github.com/goharbor/harbor/src/replication/ng/registry" "github.com/goharbor/harbor/src/replication/ng/registry"