// GetRegistryByURL returns a registry that handles the types for a given URL.
func (rs *inmemRegistryService) GetRegistryByURL(URL string) (*common.Registry, error) {
	trimmed := util.TrimURLScheme(URL)
	for _, r := range rs.registries {
		if strings.HasPrefix(trimmed, util.TrimURLScheme(r.URL)) {
			return r, nil
		}
	}

	return nil, fmt.Errorf("Failed to find registry for url: %s", URL)
}
// findRegistryByShortURL trims the scheme from both the supplied URL
// and the short URL returned by GetRegistryShortURL.
func (rp *registryProvider) findRegistryByShortURL(URL string) Registry {
	trimmed := util.TrimURLScheme(URL)
	for _, r := range rp.registries {
		if strings.HasPrefix(trimmed, util.TrimURLScheme(r.GetRegistryShortURL())) {
			return r
		}
	}

	return nil
}
Esempio n. 3
0
// NewTestGithubRegistryProviderWithDownloads creates a test github registry provider with download responses.
func NewTestGithubRegistryProviderWithDownloads(shortURL string, responses map[Type]TestURLAndError, downloadResponses map[string]DownloadResponse) GithubRegistryProvider {
	return testGithubRegistryProvider{
		shortURL:          util.TrimURLScheme(shortURL),
		responses:         responses,
		downloadResponses: downloadResponses,
	}
}
Esempio n. 4
0
func newRegistry(URL string) *common.Registry {
	tFormat := fmt.Sprintf("%s;%s", common.VersionedRegistry, common.CollectionRegistry)
	return &common.Registry{
		Name:           util.TrimURLScheme(URL),
		Type:           common.GithubRegistryType,
		URL:            URL,
		Format:         common.RegistryFormat(tFormat),
		CredentialName: "default",
	}
}
Esempio n. 5
0
// GetDownloadURLs is a mock implementation of the same method on GCSRegistryProvider.
func (tgrp testGCSRegistryProvider) GetGCSRegistry(cr common.Registry) (ObjectStorageRegistry, error) {
	trimmed := util.TrimURLScheme(cr.URL)
	if strings.HasPrefix(trimmed, tgrp.shortURL) {
		gcsr, err := NewGCSRegistry(cr.Name, trimmed, http.DefaultClient, nil)
		if err != nil {
			panic(fmt.Errorf("cannot create gcs registry: %s", err))
		}

		return &testGCSRegistry{
			GCSRegistry: *gcsr,
			responses:   tgrp.responses,
		}, nil
	}

	panic(fmt.Errorf("unknown registry: %v", cr))
}
Esempio n. 6
0
func (tgrp testGithubRegistryProvider) GetGithubRegistry(cr common.Registry) (GithubRegistry, error) {
	trimmed := util.TrimURLScheme(cr.URL)
	if strings.HasPrefix(trimmed, tgrp.shortURL) {
		ghr, err := newGithubRegistry(cr.Name, trimmed, cr.Format, nil)
		if err != nil {
			panic(fmt.Errorf("cannot create a github registry: %s", err))
		}

		return &testGithubRegistry{
			githubRegistry: *ghr,
			responses:      tgrp.responses,
		}, nil
	}

	panic(fmt.Errorf("unknown registry: %v", cr))
}
// newGithubRegistry creates a githubRegistry.
func newGithubRegistry(name, shortURL string, format common.RegistryFormat, service GithubRepositoryService) (*githubRegistry, error) {
	trimmed := util.TrimURLScheme(shortURL)
	owner, repository, path, err := parseGithubShortURL(trimmed)
	if err != nil {
		return nil, fmt.Errorf("cannot create Github template registry %s: %s", name, err)
	}

	return &githubRegistry{
		name:       name,
		shortURL:   trimmed,
		owner:      owner,
		repository: repository,
		path:       path,
		format:     format,
		service:    service,
	}, nil
}
Esempio n. 8
0
// NewTestGithubRegistryProvider creates a test github registry provider.
func NewTestGithubRegistryProvider(shortURL string, responses map[Type]TestURLAndError) GithubRegistryProvider {
	return testGithubRegistryProvider{
		shortURL:  util.TrimURLScheme(shortURL),
		responses: responses,
	}
}