Esempio n. 1
0
func (s *Storage) Create(obj interface{}) (<-chan interface{}, error) {
	template, ok := obj.(*api.Template)
	if !ok {
		return nil, errors.New("Not a template config.")
	}
	if errs := validation.ValidateTemplate(template); len(errs) > 0 {
		return nil, errors.New(fmt.Sprintf("Invalid template config: %#v", errs))
	}
	return apiserver.MakeAsync(func() (interface{}, error) {
		generators := map[string]Generator{
			"expression": NewExpressionValueGenerator(rand.New(rand.NewSource(time.Now().UnixNano()))),
		}
		processor := NewTemplateProcessor(generators)
		config, err := processor.Process(template)
		return config, err
	}), nil
}
Esempio n. 2
0
// Validate validates a new template.
func (templateStrategy) Validate(ctx kapi.Context, obj runtime.Object) field.ErrorList {
	return validation.ValidateTemplate(obj.(*api.Template))
}