func spawnTestRegistrySession(t *testing.T) *Session { authConfig := &AuthConfig{} endpoint, err := NewEndpoint(makeURL("/v1/"), insecureRegistries) if err != nil { t.Fatal(err) } r, err := NewSession(authConfig, utils.NewHTTPRequestFactory(), endpoint, true) if err != nil { t.Fatal(err) } return r }
func FetchMetadata(repoName string, tag string, insecureRegistries []string, authConfig *registry.AuthConfig) (*image.Image, error) { hostname, repoName, err := registry.ResolveRepositoryName(repoName) if err != nil { return nil, err } endpoint, err := registry.NewEndpoint(hostname, insecureRegistries) if err != nil { return nil, err } session, err := registry.NewSession(authConfig, utils.NewHTTPRequestFactory(), endpoint, true) if err != nil { return nil, err } repoData, err := session.GetRepositoryData(repoName) if err != nil { return nil, err } tagsList, err := session.GetRemoteTags(repoData.Endpoints, repoName, repoData.Tokens) if err != nil { return nil, err } imgID, ok := tagsList[tag] if !ok { return nil, fmt.Errorf("unknown tag: %s:%s", repoName, tag) } errors := make([]string, 0) for _, endpoint := range repoData.Endpoints { imgJSON, _, err := session.GetRemoteImageJSON(imgID, endpoint, repoData.Tokens) if err == nil { img, parseErr := image.NewImgJSON(imgJSON) if parseErr != nil { return nil, parseErr } return img, nil } errors = append(errors, endpoint+": "+err.Error()) } return nil, fmt.Errorf("all endpoints failed: [%s]", strings.Join(errors, ", ")) }
func HTTPRequestFactory(metaHeaders map[string][]string) *utils.HTTPRequestFactory { // FIXME: this replicates the 'info' job. httpVersion := make([]utils.VersionInfo, 0, 4) httpVersion = append(httpVersion, &simpleVersionInfo{"docker", dockerversion.VERSION}) httpVersion = append(httpVersion, &simpleVersionInfo{"go", runtime.Version()}) httpVersion = append(httpVersion, &simpleVersionInfo{"git-commit", dockerversion.GITCOMMIT}) if kernelVersion, err := kernel.GetKernelVersion(); err == nil { httpVersion = append(httpVersion, &simpleVersionInfo{"kernel", kernelVersion.String()}) } httpVersion = append(httpVersion, &simpleVersionInfo{"os", runtime.GOOS}) httpVersion = append(httpVersion, &simpleVersionInfo{"arch", runtime.GOARCH}) ud := utils.NewHTTPUserAgentDecorator(httpVersion...) md := &utils.HTTPMetaHeadersDecorator{ Headers: metaHeaders, } factory := utils.NewHTTPRequestFactory(ud, md) return factory }