boskos/mason/mason.go
func ValidateConfig(configs []common.ResourcesConfig, resources []common.Resource) error {
	resourcesNeeds := map[string]int{}
	actualResources := map[string]int{}

	configNames := map[string]map[string]int{}
	for _, c := range configs {
		_, alreadyExists := configNames[c.Name]
		if alreadyExists {
			return fmt.Errorf("config %s already exists", c.Name)
		}
		configNames[c.Name] = c.Needs
	}

	for _, res := range resources {
		_, useConfig := configNames[res.Type]
		if useConfig {
			c, ok := configNames[res.Type]
			if !ok {
				err := fmt.Errorf("resource type %s does not have associated config", res.Type)
				logrus.WithError(err).Error("using useconfig implies associated config")
				return err
			}
			// Updating resourceNeeds
			for k, v := range c {
				resourcesNeeds[k] += v
			}
		}
		actualResources[res.Type]++
	}

	for rType, needs := range resourcesNeeds {
		actual, ok := actualResources[rType]
		if !ok {
			err := fmt.Errorf("need for resource %s that does not exist", rType)
			logrus.WithError(err).Errorf("invalid configuration")
			return err
		}
		if needs > actual {
			err := fmt.Errorf("not enough resource of type %s for provisioning", rType)
			logrus.WithError(err).Errorf("invalid configuration")
			return err
		}
	}
	return nil
}
func ValidateConfig(configs []common.ResourcesConfig, resources []common.Resource) error {
	resourcesNeeds := map[string]int{}
	actualResources := map[string]int{}

	configNames := map[string]map[string]int{}
	for _, c := range configs {
		_, alreadyExists := configNames[c.Name]
		if alreadyExists {
			return fmt.Errorf("config %s already exists", c.Name)
		}
		configNames[c.Name] = c.Needs
	}

	for _, res := range resources {
		_, useConfig := configNames[res.Type]
		if useConfig {
			c, ok := configNames[res.Type]
			if !ok {
				err := fmt.Errorf("resource type %s does not have associated config", res.Type)
				logrus.WithError(err).Error("using useconfig implies associated config")
				return err
			}
			// Updating resourceNeeds
			for k, v := range c {
				resourcesNeeds[k] += v
			}
		}
		actualResources[res.Type]++
	}

	for rType, needs := range resourcesNeeds {
		actual, ok := actualResources[rType]
		if !ok {
			err := fmt.Errorf("need for resource %s that does not exist", rType)
			logrus.WithError(err).Errorf("invalid configuration")
			return err
		}
		if needs > actual {
			err := fmt.Errorf("not enough resource of type %s for provisioning", rType)
			logrus.WithError(err).Errorf("invalid configuration")
			return err
		}
	}
	return nil
}
func ValidateConfig ( configs [ ] common . ResourcesConfig , resources [ ] common . Resource ) error { resourcesNeeds := map [ string ] int { } actualResources := map [ string ] int { } configNames := map [ string ] map [ string ] int { } for _ , c := range configs { _ , alreadyExists := configNames [ c . Name ] if alreadyExists { return fmt . Errorf ( " " , c . Name ) } configNames [ c . Name ] = c . Needs } for _ , res := range resources { _ , useConfig := configNames [ res . Type ] if useConfig { c , ok := configNames [ res . Type ] if ! ok { err := fmt . Errorf ( " " , res . Type ) logrus . WithError ( err ) . Error ( " " ) return err } // Updating resourceNeeds for k , v := range c { resourcesNeeds [ k ] += v } } actualResources [ res . Type ] ++ } for rType , needs := range resourcesNeeds { actual , ok := actualResources [ rType ] if ! ok { err := fmt . Errorf ( " " , rType ) logrus . WithError ( err ) . Errorf ( " " ) return err } if needs > actual { err := fmt . Errorf ( " " , rType ) logrus . WithError ( err ) . Errorf ( " " ) return err } } return nil }
// ValidateConfig validates config with existing resources
// In: configs   - a list of resources configs
//     resources - a list of resources
// Out: nil on success, error on failure
ValidateConfig validates config with existing resources In : configs - a list of resources configs resources - a list of resources Out : nil on success error on failure