mirror of
https://github.com/containers/skopeo.git
synced 2025-08-05 16:44:27 +00:00
playing around with unauthorized errors
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
parent
2f3278f74b
commit
2431a49897
46
inspect.go
46
inspect.go
@ -60,23 +60,23 @@ func inspect(c *cli.Context) (*imageInspect, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
authConfig, err := getAuthConfig(c, ref)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ii *imageInspect
|
ii *imageInspect
|
||||||
)
|
)
|
||||||
|
|
||||||
if ref.Hostname() != "" {
|
if ref.Hostname() != "" {
|
||||||
ii, err = getData(ref)
|
ii, err = getData(ref, authConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return ii, nil
|
return ii, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
authConfig, err := getAuthConfig(c, ref)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
_ = authConfig
|
_ = authConfig
|
||||||
// TODO(runcom): ...
|
// TODO(runcom): ...
|
||||||
// both authConfig and unqualified images
|
// both authConfig and unqualified images
|
||||||
@ -84,7 +84,7 @@ func inspect(c *cli.Context) (*imageInspect, error) {
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getData(ref reference.Named) (*imageInspect, error) {
|
func getData(ref reference.Named, authConfig types.AuthConfig) (*imageInspect, error) {
|
||||||
repoInfo, err := registry.ParseRepositoryInfo(ref)
|
repoInfo, err := registry.ParseRepositoryInfo(ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -124,7 +124,7 @@ func getData(ref reference.Named) (*imageInspect, error) {
|
|||||||
logrus.Debugf("Trying to fetch image manifest of %s repository from %s %s", repoInfo.Name(), endpoint.URL, endpoint.Version)
|
logrus.Debugf("Trying to fetch image manifest of %s repository from %s %s", repoInfo.Name(), endpoint.URL, endpoint.Version)
|
||||||
|
|
||||||
//fetcher, err := newManifestFetcher(endpoint, repoInfo, config)
|
//fetcher, err := newManifestFetcher(endpoint, repoInfo, config)
|
||||||
fetcher, err := newManifestFetcher(endpoint, repoInfo)
|
fetcher, err := newManifestFetcher(endpoint, repoInfo, authConfig, registryService)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
lastErr = err
|
lastErr = err
|
||||||
continue
|
continue
|
||||||
@ -169,12 +169,13 @@ func getData(ref reference.Named) (*imageInspect, error) {
|
|||||||
return nil, lastErr
|
return nil, lastErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func newManifestFetcher(endpoint registry.APIEndpoint, repoInfo *registry.RepositoryInfo) (manifestFetcher, error) {
|
func newManifestFetcher(endpoint registry.APIEndpoint, repoInfo *registry.RepositoryInfo, authConfig types.AuthConfig, registryService *registry.Service) (manifestFetcher, error) {
|
||||||
switch endpoint.Version {
|
switch endpoint.Version {
|
||||||
case registry.APIVersion2:
|
case registry.APIVersion2:
|
||||||
return &v2ManifestFetcher{
|
return &v2ManifestFetcher{
|
||||||
endpoint: endpoint,
|
endpoint: endpoint,
|
||||||
//config: config,
|
authConfig: authConfig,
|
||||||
|
service: registryService,
|
||||||
repoInfo: repoInfo,
|
repoInfo: repoInfo,
|
||||||
}, nil
|
}, nil
|
||||||
//case registry.APIVersion1:
|
//case registry.APIVersion1:
|
||||||
@ -193,19 +194,20 @@ func getAuthConfig(c *cli.Context, ref reference.Named) (types.AuthConfig, error
|
|||||||
// if no /.docker -> docker not installed fallback to require username|password
|
// if no /.docker -> docker not installed fallback to require username|password
|
||||||
// maybe prompt user:passwd?
|
// maybe prompt user:passwd?
|
||||||
|
|
||||||
//var (
|
var (
|
||||||
//authConfig engineTypes.AuthConfig
|
authConfig types.AuthConfig
|
||||||
//username = c.GlobalString("username")
|
username = c.GlobalString("username")
|
||||||
//password = c.GlobalString("password")
|
password = c.GlobalString("password")
|
||||||
//)
|
)
|
||||||
//if username != "" && password != "" {
|
if username != "" && password != "" {
|
||||||
//authConfig = engineTypes.AuthConfig{
|
authConfig = types.AuthConfig{
|
||||||
//Username: username,
|
Username: username,
|
||||||
//Password: password,
|
Password: password,
|
||||||
//}
|
Email: "antonio.murdaca@gmail.com",
|
||||||
//}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return types.AuthConfig{}, nil
|
return authConfig, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateRepoName(name string) error {
|
func validateRepoName(name string) error {
|
||||||
|
@ -28,21 +28,28 @@ type v2ManifestFetcher struct {
|
|||||||
repoInfo *registry.RepositoryInfo
|
repoInfo *registry.RepositoryInfo
|
||||||
repo distribution.Repository
|
repo distribution.Repository
|
||||||
confirmedV2 bool
|
confirmedV2 bool
|
||||||
|
authConfig types.AuthConfig
|
||||||
|
service *registry.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mf *v2ManifestFetcher) Fetch(ctx context.Context, ref reference.Named) (*imageInspect, error) {
|
func (mf *v2ManifestFetcher) Fetch(ctx context.Context, ref reference.Named) (*imageInspect, error) {
|
||||||
var (
|
var (
|
||||||
err error
|
|
||||||
imgInspect *imageInspect
|
imgInspect *imageInspect
|
||||||
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
//mf.repo, mf.confirmedV2, err = distribution.NewV2Repository(ctx, mf.repoInfo, mf.endpoint, mf.config.MetaHeaders, mf.config.AuthConfig, "pull")
|
//mf.repo, mf.confirmedV2, err = distribution.NewV2Repository(ctx, mf.repoInfo, mf.endpoint, mf.config.MetaHeaders, mf.config.AuthConfig, "pull")
|
||||||
mf.repo, mf.confirmedV2, err = dockerdistribution.NewV2Repository(ctx, mf.repoInfo, mf.endpoint, nil, &types.AuthConfig{}, "pull")
|
mf.repo, mf.confirmedV2, err = dockerdistribution.NewV2Repository(ctx, mf.repoInfo, mf.endpoint, nil, &mf.authConfig, "pull")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Debugf("Error getting v2 registry: %v", err)
|
logrus.Debugf("Error getting v2 registry: %v", err)
|
||||||
return nil, fallbackError{err: err, confirmedV2: mf.confirmedV2}
|
return nil, fallbackError{err: err, confirmedV2: mf.confirmedV2}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, err = mf.service.Auth(&mf.authConfig)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
imgInspect, err = mf.fetchWithRepository(ctx, ref)
|
imgInspect, err = mf.fetchWithRepository(ctx, ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch t := err.(type) {
|
switch t := err.(type) {
|
||||||
|
Loading…
Reference in New Issue
Block a user