func before(c *cli.Context) error { initLogFormatter() initHelpAndVersionFlags() initAppHelpTemplate() // Log level if logLevel, err := log.ParseLevel(c.String(LogLevelKey)); err != nil { log.Fatal("[BITRISE_CLI] - Failed to parse log level:", err) } else { log.SetLevel(logLevel) } // Befor parsing cli, and running command // we need to decide wich path will be used by envman envman.CurrentEnvStoreFilePath = c.String(PathKey) if envman.CurrentEnvStoreFilePath == "" { if path, err := envStorePathInCurrentDir(); err != nil { log.Fatal("[ENVMAN] - Failed to set envman work path in current dir:", err) } else { envman.CurrentEnvStoreFilePath = path } } envman.ToolMode = c.Bool(ToolKey) if envman.ToolMode { log.Info("[ENVMAN] - Tool mode on") } if _, err := envman.GetConfigs(); err != nil { log.Fatal("[ENVMAN] - Failed to init configs:", err) } return nil }
func validateEnv(key, value string, envList []models.EnvironmentItemModel) (string, error) { if key == "" { return "", errors.New("Key is not specified, required.") } configs, err := envman.GetConfigs() if err != nil { return "", err } valueSizeInBytes := len([]byte(value)) if configs.EnvBytesLimitInKB > 0 { if valueSizeInBytes > configs.EnvBytesLimitInKB*1024 { valueSizeInKB := ((float64)(valueSizeInBytes)) / 1024.0 log.Warnf("environment value (%s...) too large", value[0:100]) log.Warnf("environment value size (%#v KB) - max allowed size: %#v KB", valueSizeInKB, (float64)(configs.EnvBytesLimitInKB)) return "environment value too large - rejected", nil } } if configs.EnvListBytesLimitInKB > 0 { envListSizeInBytes, err := envListSizeInBytes(envList) if err != nil { return "", err } if envListSizeInBytes+valueSizeInBytes > configs.EnvListBytesLimitInKB*1024 { listSizeInKB := (float64)(envListSizeInBytes)/1024 + (float64)(valueSizeInBytes)/1024 log.Warn("environment list too large") log.Warnf("environment list size (%#v KB) - max allowed size: %#v KB", listSizeInKB, (float64)(configs.EnvListBytesLimitInKB)) return "", errors.New("environment list too large") } } return value, nil }