forked from TrueCloudLab/distribution
Fix docker search problem
Search terms shouldn't be restricted to only full valid repository names. It should be perfectly valid to search using a part of a name, even if it ends with a period, dash or underscore. Signed-off-by: Hu Keping <hukeping@huawei.com>
This commit is contained in:
parent
2b658054bb
commit
82965f6c84
2 changed files with 27 additions and 6 deletions
|
@ -295,14 +295,17 @@ func splitReposName(reposName string) (string, string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRepositoryInfo validates and breaks down a repository name into a RepositoryInfo
|
// NewRepositoryInfo validates and breaks down a repository name into a RepositoryInfo
|
||||||
func (config *ServiceConfig) NewRepositoryInfo(reposName string) (*RepositoryInfo, error) {
|
func (config *ServiceConfig) NewRepositoryInfo(reposName string, bySearch bool) (*RepositoryInfo, error) {
|
||||||
if err := validateNoSchema(reposName); err != nil {
|
if err := validateNoSchema(reposName); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
indexName, remoteName := splitReposName(reposName)
|
indexName, remoteName := splitReposName(reposName)
|
||||||
if err := validateRemoteName(remoteName); err != nil {
|
|
||||||
return nil, err
|
if !bySearch {
|
||||||
|
if err := validateRemoteName(remoteName); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
repoInfo := &RepositoryInfo{
|
repoInfo := &RepositoryInfo{
|
||||||
|
@ -354,7 +357,18 @@ func (repoInfo *RepositoryInfo) GetSearchTerm() string {
|
||||||
// ParseRepositoryInfo performs the breakdown of a repository name into a RepositoryInfo, but
|
// ParseRepositoryInfo performs the breakdown of a repository name into a RepositoryInfo, but
|
||||||
// lacks registry configuration.
|
// lacks registry configuration.
|
||||||
func ParseRepositoryInfo(reposName string) (*RepositoryInfo, error) {
|
func ParseRepositoryInfo(reposName string) (*RepositoryInfo, error) {
|
||||||
return emptyServiceConfig.NewRepositoryInfo(reposName)
|
return emptyServiceConfig.NewRepositoryInfo(reposName, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParseIndexInfo will use repository name to get back an indexInfo.
|
||||||
|
func ParseIndexInfo(reposName string) (*IndexInfo, error) {
|
||||||
|
indexName, _ := splitReposName(reposName)
|
||||||
|
|
||||||
|
indexInfo, err := emptyServiceConfig.NewIndexInfo(indexName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return indexInfo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NormalizeLocalName transforms a repository name into a normalize LocalName
|
// NormalizeLocalName transforms a repository name into a normalize LocalName
|
||||||
|
|
|
@ -51,7 +51,8 @@ func (s *Service) Auth(authConfig *cliconfig.AuthConfig) (string, error) {
|
||||||
// Search queries the public registry for images matching the specified
|
// Search queries the public registry for images matching the specified
|
||||||
// search terms, and returns the results.
|
// search terms, and returns the results.
|
||||||
func (s *Service) Search(term string, authConfig *cliconfig.AuthConfig, headers map[string][]string) (*SearchResults, error) {
|
func (s *Service) Search(term string, authConfig *cliconfig.AuthConfig, headers map[string][]string) (*SearchResults, error) {
|
||||||
repoInfo, err := s.ResolveRepository(term)
|
|
||||||
|
repoInfo, err := s.ResolveRepositoryBySearch(term)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -71,7 +72,13 @@ func (s *Service) Search(term string, authConfig *cliconfig.AuthConfig, headers
|
||||||
// ResolveRepository splits a repository name into its components
|
// ResolveRepository splits a repository name into its components
|
||||||
// and configuration of the associated registry.
|
// and configuration of the associated registry.
|
||||||
func (s *Service) ResolveRepository(name string) (*RepositoryInfo, error) {
|
func (s *Service) ResolveRepository(name string) (*RepositoryInfo, error) {
|
||||||
return s.Config.NewRepositoryInfo(name)
|
return s.Config.NewRepositoryInfo(name, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResolveRepositoryBySearch splits a repository name into its components
|
||||||
|
// and configuration of the associated registry.
|
||||||
|
func (s *Service) ResolveRepositoryBySearch(name string) (*RepositoryInfo, error) {
|
||||||
|
return s.Config.NewRepositoryInfo(name, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResolveIndex takes indexName and returns index info
|
// ResolveIndex takes indexName and returns index info
|
||||||
|
|
Loading…
Reference in a new issue