2014-04-28 02:06:09 +04:00
|
|
|
package registry
|
|
|
|
|
2015-05-16 04:35:04 +03:00
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/docker/docker/cliconfig"
|
|
|
|
)
|
2015-04-22 15:06:58 +03:00
|
|
|
|
2014-04-28 02:06:09 +04:00
|
|
|
type Service struct {
|
2014-10-07 05:54:52 +04:00
|
|
|
Config *ServiceConfig
|
2014-04-28 02:06:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewService returns a new instance of Service ready to be
|
|
|
|
// installed no an engine.
|
2014-10-07 05:54:52 +04:00
|
|
|
func NewService(options *Options) *Service {
|
2014-08-20 19:31:24 +04:00
|
|
|
return &Service{
|
2014-10-07 05:54:52 +04:00
|
|
|
Config: NewServiceConfig(options),
|
2014-08-20 19:31:24 +04:00
|
|
|
}
|
2014-04-28 02:06:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Auth contacts the public registry with the provided credentials,
|
|
|
|
// and returns OK if authentication was sucessful.
|
|
|
|
// It can be used to verify the validity of a client's credentials.
|
2015-04-22 15:06:58 +03:00
|
|
|
func (s *Service) Auth(authConfig *cliconfig.AuthConfig) (string, error) {
|
2014-12-12 04:55:15 +03:00
|
|
|
addr := authConfig.ServerAddress
|
|
|
|
if addr == "" {
|
|
|
|
// Use the official registry address if not specified.
|
|
|
|
addr = IndexServerAddress()
|
2014-04-28 02:06:09 +04:00
|
|
|
}
|
2015-04-01 02:21:37 +03:00
|
|
|
index, err := s.ResolveIndex(addr)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
2014-04-28 02:06:09 +04:00
|
|
|
}
|
2015-05-16 04:35:04 +03:00
|
|
|
endpoint, err := NewEndpoint(index, nil)
|
2015-04-01 02:21:37 +03:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
2014-12-12 04:55:15 +03:00
|
|
|
}
|
|
|
|
authConfig.ServerAddress = endpoint.String()
|
2015-05-14 17:12:54 +03:00
|
|
|
return Login(authConfig, endpoint)
|
2014-04-28 02:06:09 +04:00
|
|
|
}
|
2014-04-28 02:21:42 +04:00
|
|
|
|
|
|
|
// Search queries the public registry for images matching the specified
|
|
|
|
// search terms, and returns the results.
|
2015-04-22 15:06:58 +03:00
|
|
|
func (s *Service) Search(term string, authConfig *cliconfig.AuthConfig, headers map[string][]string) (*SearchResults, error) {
|
2015-04-01 02:21:37 +03:00
|
|
|
repoInfo, err := s.ResolveRepository(term)
|
2014-08-09 11:16:54 +04:00
|
|
|
if err != nil {
|
2015-04-01 02:21:37 +03:00
|
|
|
return nil, err
|
2014-08-09 11:16:54 +04:00
|
|
|
}
|
2015-05-14 17:12:54 +03:00
|
|
|
|
2014-10-07 05:54:52 +04:00
|
|
|
// *TODO: Search multiple indexes.
|
2015-05-16 04:35:04 +03:00
|
|
|
endpoint, err := repoInfo.GetEndpoint(http.Header(headers))
|
2014-08-09 11:16:54 +04:00
|
|
|
if err != nil {
|
2015-04-01 02:21:37 +03:00
|
|
|
return nil, err
|
2014-04-28 02:21:42 +04:00
|
|
|
}
|
2015-05-16 04:35:04 +03:00
|
|
|
r, err := NewSession(endpoint.client, authConfig, endpoint)
|
2014-04-28 02:21:42 +04:00
|
|
|
if err != nil {
|
2015-04-01 02:21:37 +03:00
|
|
|
return nil, err
|
2014-04-28 02:21:42 +04:00
|
|
|
}
|
2015-04-01 02:21:37 +03:00
|
|
|
return r.SearchRepositories(repoInfo.GetSearchTerm())
|
2014-04-28 02:21:42 +04:00
|
|
|
}
|
2014-10-07 05:54:52 +04:00
|
|
|
|
|
|
|
// ResolveRepository splits a repository name into its components
|
|
|
|
// and configuration of the associated registry.
|
2015-04-01 02:21:37 +03:00
|
|
|
func (s *Service) ResolveRepository(name string) (*RepositoryInfo, error) {
|
|
|
|
return s.Config.NewRepositoryInfo(name)
|
2014-10-07 05:54:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ResolveIndex takes indexName and returns index info
|
2015-04-01 02:21:37 +03:00
|
|
|
func (s *Service) ResolveIndex(name string) (*IndexInfo, error) {
|
|
|
|
return s.Config.NewIndexInfo(name)
|
2014-10-07 05:54:52 +04:00
|
|
|
}
|