github.com/docker/app@v0.9.1-beta3.0.20210611140623-a48f773ab002/internal/registry.go (about)

     1  package internal
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"github.com/docker/cli/cli/command"
     8  	"github.com/sirupsen/logrus"
     9  )
    10  
    11  // InsecureRegistriesFromEngine reads the registry configuration from the daemon and returns
    12  // a list of all insecure ones.
    13  func InsecureRegistriesFromEngine(dockerCli command.Cli) ([]string, error) {
    14  	registries := []string{}
    15  
    16  	info, err := dockerCli.Client().Info(context.Background())
    17  	if err != nil {
    18  		return nil, fmt.Errorf("could not get docker info: %v", err)
    19  	}
    20  
    21  	for _, reg := range info.RegistryConfig.IndexConfigs {
    22  		if !reg.Secure {
    23  			registries = append(registries, reg.Name)
    24  		}
    25  	}
    26  
    27  	logrus.Debugf("insecure registries: %v", registries)
    28  
    29  	return registries, nil
    30  }