2018-03-19 18:56:51 -04:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/docker/cli/cli/command"
|
|
|
|
"github.com/docker/cli/cli/trust"
|
2018-09-20 14:02:11 -04:00
|
|
|
clitypes "github.com/docker/cli/types"
|
2018-03-19 18:56:51 -04:00
|
|
|
"github.com/docker/distribution/reference"
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
registrytypes "github.com/docker/docker/api/types/registry"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
func getRegistryAuth(cli command.Cli, registryPrefix string) (*types.AuthConfig, error) {
|
|
|
|
if registryPrefix == "" {
|
2018-09-20 14:02:11 -04:00
|
|
|
registryPrefix = clitypes.RegistryPrefix
|
2018-03-19 18:56:51 -04:00
|
|
|
}
|
|
|
|
distributionRef, err := reference.ParseNormalizedNamed(registryPrefix)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrapf(err, "failed to parse image name: %s", registryPrefix)
|
|
|
|
}
|
|
|
|
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(context.Background(), nil, authResolver(cli), distributionRef.String())
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "failed to get imgRefAndAuth")
|
|
|
|
}
|
|
|
|
return imgRefAndAuth.AuthConfig(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func authResolver(cli command.Cli) func(ctx context.Context, index *registrytypes.IndexInfo) types.AuthConfig {
|
|
|
|
return func(ctx context.Context, index *registrytypes.IndexInfo) types.AuthConfig {
|
|
|
|
return command.ResolveAuthConfig(ctx, cli, index)
|
|
|
|
}
|
|
|
|
}
|