func GetCustomSettings()

in src/terraform/providers/terraform-provider-avere/restore_backup.go [467:518]


func GetCustomSettings(vfxtBackupDirectory string, massToFilerName map[string]string) (map[string][]string, error) {
	_, _, customSettingsConfigFile := GetVfxtBackupFiles(vfxtBackupDirectory)

	results := make(map[string][]string)
	results[GlobalCustomSettingsKey] = []string{}
	results[VserverCustomSettingsKey] = []string{}

	file, err := os.Open(customSettingsConfigFile)
	if err != nil {
		return results, fmt.Errorf("error opening file '%s': '%v'", customSettingsConfigFile, err)
	}
	defer file.Close()
	massRegEx := regexp.MustCompile(`averecmd support.setCustomSetting ([^ ]*) ([^ ]*) ([^ "]*)`)
	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		if scanner.Err() != nil {
			return results, fmt.Errorf("error scanning file '%s': '%v'", customSettingsConfigFile, scanner.Err())
		}
		line := scanner.Text()
		matches := massRegEx.FindStringSubmatch(line)
		if len(matches) == 4 && len(matches[1]) > 0 && len(matches[2]) > 0 && len(matches[3]) > 0 {
			setting := matches[1]
			checkcode := matches[2]
			settingValue := matches[3]
			if strings.Index(matches[1], "mass") == 0 {
				// this is a mass
				mass := setting[:strings.Index(setting, ".")]
				filerName := ""
				if v, ok := massToFilerName[mass]; ok {
					filerName = v
				} else {
					return results, fmt.Errorf("missing filer mapping for massName '%s'", mass)
				}
				customSetting := fmt.Sprintf("%s %s %s", setting[strings.Index(setting, ".")+1:], checkcode, settingValue)
				if _, ok := results[filerName]; !ok {
					results[filerName] = []string{}
				}
				results[filerName] = append(results[filerName], customSetting)
			} else if strings.Index(matches[1], "vserver") == 0 {
				// this is a vserver
				customSetting := fmt.Sprintf("%s %s %s", setting[strings.Index(setting, ".")+1:], checkcode, settingValue)
				results[VserverCustomSettingsKey] = append(results[VserverCustomSettingsKey], customSetting)
			} else {
				// this is a global setting
				customSetting := fmt.Sprintf("%s %s %s", setting, checkcode, settingValue)
				results[GlobalCustomSettingsKey] = append(results[GlobalCustomSettingsKey], customSetting)
			}
		}
	}

	return results, nil
}