mirror of
https://github.com/containers/skopeo.git
synced 2025-07-31 06:31:06 +00:00
playing around with unauthorized errors
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
parent
2f3278f74b
commit
2431a49897
50
inspect.go
50
inspect.go
@ -60,23 +60,23 @@ func inspect(c *cli.Context) (*imageInspect, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
authConfig, err := getAuthConfig(c, ref)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var (
|
||||
ii *imageInspect
|
||||
)
|
||||
|
||||
if ref.Hostname() != "" {
|
||||
ii, err = getData(ref)
|
||||
ii, err = getData(ref, authConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ii, nil
|
||||
}
|
||||
|
||||
authConfig, err := getAuthConfig(c, ref)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_ = authConfig
|
||||
// TODO(runcom): ...
|
||||
// both authConfig and unqualified images
|
||||
@ -84,7 +84,7 @@ func inspect(c *cli.Context) (*imageInspect, error) {
|
||||
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)
|
||||
if err != nil {
|
||||
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)
|
||||
|
||||
//fetcher, err := newManifestFetcher(endpoint, repoInfo, config)
|
||||
fetcher, err := newManifestFetcher(endpoint, repoInfo)
|
||||
fetcher, err := newManifestFetcher(endpoint, repoInfo, authConfig, registryService)
|
||||
if err != nil {
|
||||
lastErr = err
|
||||
continue
|
||||
@ -169,13 +169,14 @@ func getData(ref reference.Named) (*imageInspect, error) {
|
||||
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 {
|
||||
case registry.APIVersion2:
|
||||
return &v2ManifestFetcher{
|
||||
endpoint: endpoint,
|
||||
//config: config,
|
||||
repoInfo: repoInfo,
|
||||
endpoint: endpoint,
|
||||
authConfig: authConfig,
|
||||
service: registryService,
|
||||
repoInfo: repoInfo,
|
||||
}, nil
|
||||
//case registry.APIVersion1:
|
||||
//return &v1ManifestFetcher{
|
||||
@ -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
|
||||
// maybe prompt user:passwd?
|
||||
|
||||
//var (
|
||||
//authConfig engineTypes.AuthConfig
|
||||
//username = c.GlobalString("username")
|
||||
//password = c.GlobalString("password")
|
||||
//)
|
||||
//if username != "" && password != "" {
|
||||
//authConfig = engineTypes.AuthConfig{
|
||||
//Username: username,
|
||||
//Password: password,
|
||||
//}
|
||||
//}
|
||||
var (
|
||||
authConfig types.AuthConfig
|
||||
username = c.GlobalString("username")
|
||||
password = c.GlobalString("password")
|
||||
)
|
||||
if username != "" && password != "" {
|
||||
authConfig = types.AuthConfig{
|
||||
Username: username,
|
||||
Password: password,
|
||||
Email: "antonio.murdaca@gmail.com",
|
||||
}
|
||||
}
|
||||
|
||||
return types.AuthConfig{}, nil
|
||||
return authConfig, nil
|
||||
}
|
||||
|
||||
func validateRepoName(name string) error {
|
||||
|
@ -28,21 +28,28 @@ type v2ManifestFetcher struct {
|
||||
repoInfo *registry.RepositoryInfo
|
||||
repo distribution.Repository
|
||||
confirmedV2 bool
|
||||
authConfig types.AuthConfig
|
||||
service *registry.Service
|
||||
}
|
||||
|
||||
func (mf *v2ManifestFetcher) Fetch(ctx context.Context, ref reference.Named) (*imageInspect, error) {
|
||||
var (
|
||||
err error
|
||||
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 = 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 {
|
||||
logrus.Debugf("Error getting v2 registry: %v", err)
|
||||
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)
|
||||
if err != nil {
|
||||
switch t := err.(type) {
|
||||
|
Loading…
Reference in New Issue
Block a user