Esempio n. 1
0
File: manifest.go Progetto: nsnt/cli
func setSliceOrEmptyVal(appMap, yamlMap generic.Map, key string, errs *ManifestErrors) {
	if !yamlMap.Has(key) {
		appMap.Set(key, []string{})
		return
	}

	var (
		stringSlice []string
		err         error
	)

	errMsg := fmt.Sprintf("Expected %s to be a list of strings.", key)

	switch input := yamlMap.Get(key).(type) {
	case []interface{}:
		for _, value := range input {
			stringValue, ok := value.(string)
			if !ok {
				err = errors.New(errMsg)
				break
			}
			stringSlice = append(stringSlice, stringValue)
		}
	default:
		err = errors.New(errMsg)
	}

	if err != nil {
		*errs = append(*errs, err)
		return
	}

	appMap.Set(key, stringSlice)
	return
}
Esempio n. 2
0
func envVarOrEmptyMap(yamlMap generic.Map, errs *ManifestErrors) *map[string]string {
	key := "env"
	switch envVars := yamlMap.Get(key).(type) {
	case nil:
		aMap := make(map[string]string, 0)
		return &aMap
	case map[string]interface{}:
		yamlMap.Set(key, generic.NewMap(yamlMap.Get(key)))
		return envVarOrEmptyMap(yamlMap, errs)
	case generic.Map:
		merrs := validateEnvVars(envVars)
		if merrs != nil {
			*errs = append(*errs, merrs)
			return nil
		}

		result := make(map[string]string, envVars.Count())
		generic.Each(envVars, func(key, value interface{}) {
			result[key.(string)] = value.(string)
		})
		return &result
	default:
		*errs = append(*errs, errors.New(fmt.Sprintf("Expected %s to be a set of key => value.", key)))
		return nil
	}
}
Esempio n. 3
0
File: manifest.go Progetto: nsnt/cli
func setBytesVal(appMap, yamlMap generic.Map, key string, errs *ManifestErrors) {
	value, err := formatters.ToMegabytes(yamlMap.Get(key).(string))
	if err != nil {
		*errs = append(*errs, errors.New(fmt.Sprintf("Unexpected value for %s :\n%s", key, err.Error())))
		return
	}
	appMap.Set(key, value)
}
Esempio n. 4
0
func setStringVal(appMap generic.Map, key string, val interface{}, errs *ManifestErrors) {
	stringVal, ok := val.(string)
	if !ok {
		*errs = append(*errs, errors.New(fmt.Sprintf("%s must be a string value", key)))
		return
	}
	appMap.Set(key, stringVal)
}
Esempio n. 5
0
File: manifest.go Progetto: nsnt/cli
func setStringOrNullVal(appMap, yamlMap generic.Map, key string, errs *ManifestErrors) {
	switch val := yamlMap.Get(key).(type) {
	case string:
		appMap.Set(key, val)
	case nil:
		appMap.Set(key, "")
	default:
		*errs = append(*errs, errors.New(fmt.Sprintf("%s must be a string or null value", key)))
	}
}
Esempio n. 6
0
File: manifest.go Progetto: nsnt/cli
func setBoolVal(appMap, yamlMap generic.Map, key string, errs *ManifestErrors) {
	switch val := yamlMap.Get(key).(type) {
	case bool:
		appMap.Set(key, val)
	case string:
		boolVal := val == "true"
		appMap.Set(key, boolVal)
	default:
		*errs = append(*errs, errors.New(fmt.Sprintf("Expected %s to be a boolean.", key)))
	}

	return
}
Esempio n. 7
0
func setEnvVar(appMap generic.Map, env interface{}, errs *ManifestErrors) {
	if !generic.IsMappable(env) {
		*errs = append(*errs, errors.New("Expected env vars to be a set of key => value."))
		return
	}

	merrs := validateEnvVars(env)
	if merrs != nil {
		*errs = append(*errs, merrs)
		return
	}

	appMap.Set("env", generic.NewMap(env))
}
Esempio n. 8
0
File: manifest.go Progetto: nsnt/cli
func setEnvVarOrEmptyMap(appMap, yamlMap generic.Map, key string, errs *ManifestErrors) {
	if !yamlMap.Has(key) {
		appMap.Set(key, generic.NewMap())
		return
	}

	envVars := yamlMap.Get(key)

	if !generic.IsMappable(envVars) {
		*errs = append(*errs, errors.New(fmt.Sprintf("Expected %s to be a set of key => value.", key)))
		return
	}

	merrs := validateEnvVars(envVars)
	if merrs != nil {
		*errs = append(*errs, merrs)
		return
	}

	appMap.Set(key, generic.NewMap(envVars))
}
Esempio n. 9
0
func envVarOrEmptyMap(yamlMap generic.Map, errs *ManifestErrors) *map[string]string {
	key := "env"
	switch envVars := yamlMap.Get(key).(type) {
	case nil:
		aMap := make(map[string]string, 0)
		return &aMap
	case map[string]interface{}:
		yamlMap.Set(key, generic.NewMap(yamlMap.Get(key)))
		return envVarOrEmptyMap(yamlMap, errs)
	case map[interface{}]interface{}:
		yamlMap.Set(key, generic.NewMap(yamlMap.Get(key)))
		return envVarOrEmptyMap(yamlMap, errs)
	case generic.Map:
		merrs := validateEnvVars(envVars)
		if merrs != nil {
			*errs = append(*errs, merrs)
			return nil
		}

		result := make(map[string]string, envVars.Count())
		generic.Each(envVars, func(key, value interface{}) {

			switch value.(type) {
			case string:
				result[key.(string)] = value.(string)
			case int64, int, int32:
				result[key.(string)] = fmt.Sprintf("%d", value)
			case float32, float64:
				result[key.(string)] = fmt.Sprintf("%f", value)
			default:
				*errs = append(*errs, errors.New(fmt.Sprintf("Expected environment variable %s to have a string value, but it was a %T.", key, value)))
			}

		})
		return &result
	default:
		*errs = append(*errs, errors.New(fmt.Sprintf("Expected %s to be a set of key => value, but it was a %T.", key, envVars)))
		return nil
	}
}
Esempio n. 10
0
File: manifest.go Progetto: nsnt/cli
func setTimeoutVal(appMap, yamlMap generic.Map, key string, errs *ManifestErrors) {
	var (
		intVal int
		err    error
	)

	switch val := yamlMap.Get(key).(type) {
	case string:
		intVal, err = strconv.Atoi(val)
	case int:
		intVal = val
	default:
		err = errors.New("Expected health_check_timeout to be a number.")
	}

	if err != nil {
		*errs = append(*errs, err)
		return
	}

	appMap.Set("health_check_timeout", intVal)
}
Esempio n. 11
0
File: manifest.go Progetto: nsnt/cli
func setIntVal(appMap, yamlMap generic.Map, key string, errs *ManifestErrors) {
	var (
		intVal int
		err    error
	)

	switch val := yamlMap.Get(key).(type) {
	case string:
		intVal, err = strconv.Atoi(val)
	case int:
		intVal = val
	default:
		err = errors.New(fmt.Sprintf("Expected %s to be a number.", key))
	}

	if err != nil {
		*errs = append(*errs, err)
		return
	}

	appMap.Set(key, intVal)
}
Esempio n. 12
0
		BeforeEach(func() {
			appRepo.ReadNotFound = true

			manifest := singleAppManifest()
			manifestApp = manifest.Data.Get("applications").([]interface{})[0].(generic.Map)
			manifestApp.Delete("host")
			manifestRepo.ReadManifestReturns.Manifest = manifest
		})

		It("provides a random hostname when the --random-route flag is passed", func() {
			callPush("--random-route", "my-new-app")
			Expect(routeRepo.FindByHostAndDomainHost).To(Equal("my-new-app-laughing-cow"))
		})

		It("provides a random hostname when the random-route option is set in the manifest", func() {
			manifestApp.Set("random-route", true)

			callPush("my-new-app")

			Expect(routeRepo.FindByHostAndDomainHost).To(Equal("my-new-app-laughing-cow"))
		})
	})

	It("creates an app when pushing for the first time", func() {
		routeRepo.FindByHostAndDomainErr = true
		appRepo.ReadNotFound = true

		callPush("-t", "111", "my-new-app")
		Expect(*appRepo.CreatedAppParams().Name).To(Equal("my-new-app"))
		Expect(*appRepo.CreatedAppParams().SpaceGuid).To(Equal("my-space-guid"))