MCPcopy
hub / github.com/containers/toolbox / SetUpConfiguration

Function SetUpConfiguration

src/pkg/utils/utils.go:667–716  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

665}
666
667func SetUpConfiguration() error {
668 logrus.Debug("Setting up configuration")
669
670 configFiles := []string{
671 "/etc/containers/toolbox.conf",
672 }
673
674 userConfigDir, err := os.UserConfigDir()
675 if err != nil {
676 logrus.Debugf("Setting up configuration: failed to get the user config directory: %s", err)
677 return errors.New("failed to get the user config directory")
678 }
679
680 userConfigPath := userConfigDir + "/containers/toolbox.conf"
681 configFiles = append(configFiles, []string{
682 userConfigPath,
683 }...)
684
685 viper.SetConfigType("toml")
686
687 for _, configFile := range configFiles {
688 viper.SetConfigFile(configFile)
689
690 if err := viper.MergeInConfig(); err != nil {
691 var errConfigFileNotFound viper.ConfigFileNotFoundError
692 var errConfigParse viper.ConfigParseError
693
694 if errors.As(err, &errConfigFileNotFound) || errors.Is(err, os.ErrNotExist) {
695 logrus.Debugf("Setting up configuration: file %s not found", configFile)
696 continue
697 } else if errors.As(err, &errConfigParse) {
698 logrus.Debugf("Setting up configuration: failed to parse file %s: %s", configFile, err)
699 return fmt.Errorf("failed to parse file %s", configFile)
700 } else {
701 logrus.Debugf("Setting up configuration: failed to read file %s: %s", configFile, err)
702 return fmt.Errorf("failed to read file %s", configFile)
703 }
704 }
705 }
706
707 container, _, _, err := ResolveContainerAndImageNames("", "", "", "")
708 if err != nil {
709 logrus.Debugf("Setting up configuration: failed to resolve container name: %s", err)
710 return errors.New("failed to resolve container name")
711 }
712
713 ContainerNameDefault = container
714
715 return nil
716}
717
718// ShortID shortens provided id to first 12 characters.
719func ShortID(id string) string {

Callers

nothing calls this directly

Calls 2

IsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…