func()

in app/registry/create.go [591:657]


func (a *App) prepareMailServerConfig(_ *gin.Context, r *registry, _values *Values,
	secretData map[string]map[string]interface{}, mrActions *[]string) (bool, error) {
	values := _values.OriginalYaml

	var email ExternalEmailSettings
	var vaultPath string

	if r.MailServerType == SMTPTypeExternal {
		var smptOptsDict map[string]string
		if err := json.Unmarshal([]byte(r.MailServerOpts), &smptOptsDict); err != nil {
			return false, errors.Wrap(err, "unable to decode mail server opts")
		}

		pwd, ok := smptOptsDict["password"]
		passwordExist := a.isSmtpPasswordSet(_values.Global.Notifications.Email.VaultPath)
		if !ok && !passwordExist {
			return false, errors.New("no password in mail server opts")
		}
		if pwd != "" {
			vaultPath = a.vaultRegistryPathKey(r.Name, fmt.Sprintf("%s-%s", "smtp", time.Now().Format("20060201T150405Z")))
			if _, ok := secretData[vaultPath]; !ok {
				secretData[vaultPath] = make(map[string]interface{})
			}

			secretData[vaultPath][a.Config.VaultRegistrySMTPPwdSecretKey] = pwd
		} else {
			vaultPath = _values.Global.Notifications.Email.VaultPath
		}

		//TODO: remove password from dict

		port, err := strconv.ParseInt(smptOptsDict["port"], 10, 32)
		if err != nil {
			return false, errors.Wrapf(err, "wrong smtp port value: %s", smptOptsDict["port"])
		}

		email = ExternalEmailSettings{
			Type:      "external",
			Host:      smptOptsDict["host"],
			Port:      port,
			Address:   smptOptsDict["address"],
			VaultPath: vaultPath,
			VaultKey:  a.Config.VaultRegistrySMTPPwdSecretKey,
		}
	} else {
		email = ExternalEmailSettings{
			Type: "internal",
		}
	}

	if reflect.DeepEqual(email, _values.Global.Notifications.Email) {
		return false, nil
	}

	globalInterface, ok := values[GlobalValuesIndex]
	if !ok {
		globalInterface = make(map[string]interface{})
	}
	globalDict := globalInterface.(map[string]interface{})

	globalDict["notifications"] = map[string]interface{}{
		"email": email,
	}
	values[GlobalValuesIndex] = globalDict

	return true, nil
}