Automatically determine registry options based on image name (#103)

Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2020-06-22 00:19:59 +00:00
committed by GitHub
parent ca61056b3d
commit c0e3f7e85f
25 changed files with 287 additions and 118 deletions

View File

@@ -60,7 +60,7 @@ func ParseImage(parseOpts ParseImageOptions) (Image, error) {
// Parse the image name and tag.
named, err := reference.ParseNormalizedNamed(parseOpts.Name)
if err != nil {
return Image{}, errors.Wrap(err, fmt.Sprintf("parsing image %s failed", parseOpts.Name))
return Image{}, errors.Wrapf(err, "parsing image %s failed", parseOpts.Name)
}
// Add the latest lag if they did not provide one.
named = reference.TagNameOnly(named)

View File

@@ -32,7 +32,7 @@ type Options struct {
// New creates new docker registry client instance
func New(opts Options) (*Client, error) {
// Auth
auth := &types.DockerAuthConfig{}
var auth *types.DockerAuthConfig
if opts.Username != "" {
auth = &types.DockerAuthConfig{
Username: opts.Username,
@@ -75,6 +75,16 @@ func (c *Client) newImage(ctx context.Context, imageStr string) (types.ImageClos
return nil, errors.Wrap(err, "Invalid image name")
}
if c.sysCtx.DockerAuthConfig == nil {
c.sysCtx.DockerAuthConfig = &types.DockerAuthConfig{}
// TODO: Seek credentials
//auth, err := config.GetCredentials(c.sysCtx, reference.Domain(ref.DockerReference()))
//if err != nil {
// return nil, errors.Wrap(err, "Cannot get registry credentials")
//}
//*c.sysCtx.DockerAuthConfig = auth
}
img, err := ref.NewImage(ctx, c.sysCtx)
if err != nil {
return nil, err