示例#1
0
func (d packageDefinition) PostUninstall() (*packageUninstall, error) {
	var uninstall *packageUninstall
	var err error

	if len(d.uninstallJson) == 0 {
		return uninstall, nil
	}

	uninstallTemplate := string(d.uninstallJson)
	config, err := d.MergedConfig()
	if err != nil {
		log.Errorf("Unable to retrieve package definition configuration: %v", err)
		return uninstall, err
	}

	// Render uninstallTemplate with config
	tmpl, err := mustache.ParseString(uninstallTemplate)
	if err != nil {
		log.Errorf("Could not parse uninstall template: %v", err)
		return nil, err
	}

	jsonBlob := tmpl.Render(config)

	uninstall = &packageUninstall{}
	err = json.Unmarshal([]byte(jsonBlob), &uninstall)

	return uninstall, err
}
示例#2
0
func (d packageDefinition) Options() (map[string]interface{}, error) {
	var options map[string]interface{}
	if len(d.optionsJson) > 0 {
		// Render options
		optionsTemplate := string(d.optionsJson)
		tmpl, err := mustache.ParseString(optionsTemplate)
		if err != nil {
			log.Errorf("Could not parse options template: %v", err)
			return nil, err
		}

		renderedOptions := tmpl.Render(d.apiConfig)

		err = json.Unmarshal([]byte(renderedOptions), &options)
		if err != nil {
			log.Errorf("Could not unmarshal options json: %v", err)
			return nil, err
		}

		// merge user config
		mergedOptions := mergeConfig(options, d.userConfig)

		// add api config to options
		mergedOptions["mantl"] = d.apiConfig["mantl"]
	}

	return options, nil
}
示例#3
0
func (d packageDefinition) MarathonAppJson() (string, error) {
	marathonTemplate := string(d.marathonJson)
	config, err := d.MergedConfig()
	if err != nil {
		log.Errorf("Unable to retrieve package definition configuration: %v", err)
		return "", err
	}

	// Render marathonTemplate with config
	tmpl, err := mustache.ParseString(marathonTemplate)
	if err != nil {
		log.Errorf("Could not parse marathon template: %v", err)
		return "", err
	}

	json := tmpl.Render(config)

	return json, nil
}
示例#4
0
func (d packageDefinition) renderJsonMustacheTemplate(jsonBlob []byte) (string, error) {
	template := string(jsonBlob)
	config, err := d.MergedConfig()
	if err != nil {
		log.Errorf("Unable to retrieve package definition configuration: %v", err)
		return "", err
	}

	// Render template with config
	tmpl, err := mustache.ParseString(template)
	if err != nil {
		log.Errorf("Could not parse template: %v", err)
		return "", err
	}

	json := tmpl.Render(config)

	return json, nil
}