Files
kubesphere/pkg/models/registries/v2/registries.go
mango f018a23023 chore: add licenses check tools (#4706)
* feat: check licenses header with skywalking-eye and support check tools.

Signed-off-by: mango <xu.weiKyrie@foxmail.com>

* feat: check licenses header with skywalking-eye and support check tools.

Signed-off-by: mango <xu.weiKyrie@foxmail.com>

* feat: check licenses header with skywalking-eye and support check tools.

Signed-off-by: mango <xu.weiKyrie@foxmail.com>

* remove verify-licenses because verify-all exist.

Signed-off-by: mango <xu.weiKyrie@foxmail.com>

* update modules.txt

Signed-off-by: mango <xu.weiKyrie@foxmail.com>

* revert go.mod

Signed-off-by: mango <xu.weiKyrie@foxmail.com>

* update vendor directory.

Signed-off-by: mango <xu.weiKyrie@foxmail.com>

* revert go.sum

Signed-off-by: mango <xu.weiKyrie@foxmail.com>

* revert go.sum

Signed-off-by: mango <xu.weiKyrie@foxmail.com>

* ignore `pkg/controller/application/status.go`

Signed-off-by: mango <xu.weiKyrie@foxmail.com>

* add license header.

Signed-off-by: mango <xu.weiKyrie@foxmail.com>
2022-03-09 10:25:13 +08:00

86 lines
2.0 KiB
Go

// Copyright 2022 The KubeSphere 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 v2
import (
"github.com/google/go-containerregistry/pkg/name"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/remote"
)
type Registryer interface {
// list repository tags
ListRepositoryTags(image string) (RepositoryTags, error)
// get image config
Config(image string) (*v1.ConfigFile, error)
}
type registryer struct {
opts options
}
func NewRegistryer(opts ...Option) *registryer {
return &registryer{
opts: makeOptions(opts...),
}
}
func (r *registryer) ListRepositoryTags(src string) (RepositoryTags, error) {
repo, err := name.NewRepository(src, r.opts.name...)
if err != nil {
return RepositoryTags{}, err
}
tags, err := remote.List(repo, r.opts.remote...)
if err != nil {
return RepositoryTags{}, err
}
return RepositoryTags{
Registry: repo.RegistryStr(),
Repository: repo.RepositoryStr(),
Tags: tags,
}, nil
}
func (r *registryer) Config(image string) (*v1.ConfigFile, error) {
img, _, err := r.getImage(image)
if err != nil {
return nil, err
}
configFile, err := img.ConfigFile()
if err != nil {
return nil, err
}
return configFile, nil
}
func (r *registryer) getImage(reference string) (v1.Image, name.Reference, error) {
ref, err := name.ParseReference(reference, r.opts.name...)
if err != nil {
return nil, nil, err
}
img, err := remote.Image(ref, r.opts.remote...)
if err != nil {
return nil, nil, err
}
return img, ref, nil
}