1
0
mirror of https://github.com/regclient/regclient.git synced 2025-09-18 07:43:15 +03:00
Files
regclient/repo.go
Brandon Mitchell d99294d76e Fix crash on RepoList from invalid hostname
Signed-off-by: Brandon Mitchell <git@bmitch.net>
2023-10-16 21:33:38 -04:00

34 lines
918 B
Go

package regclient
import (
"context"
"fmt"
"strings"
"github.com/regclient/regclient/scheme"
"github.com/regclient/regclient/types"
"github.com/regclient/regclient/types/repo"
)
type repoLister interface {
RepoList(ctx context.Context, hostname string, opts ...scheme.RepoOpts) (*repo.RepoList, error)
}
// RepoList returns a list of repositories on a registry.
// Note the underlying "_catalog" API is not supported on many cloud registries.
func (rc *RegClient) RepoList(ctx context.Context, hostname string, opts ...scheme.RepoOpts) (*repo.RepoList, error) {
i := strings.Index(hostname, "/")
if i > 0 {
return nil, fmt.Errorf("invalid hostname: %s%.0w", hostname, types.ErrParsingFailed)
}
schemeAPI, err := rc.schemeGet("reg")
if err != nil {
return nil, err
}
rl, ok := schemeAPI.(repoLister)
if !ok {
return nil, types.ErrNotImplemented
}
return rl.RepoList(ctx, hostname, opts...)
}