Beispiel #1
0
func applyPostgresUpdates(config *util.MzConfig) error {
	if config.Get("ddl.create", "") != "" ||
		config.GetFlag("ddl.upgrade") ||
		config.Get("ddl.downgrade", "") != "" ||
		config.GetFlag("ddl.log") {
		if config.Get("ddl.create", "") != "" && config.GetFlag("ddl.upgrade") {
			log.Fatalf("Invalid DDL options.  You can only specify one DDL command at a time.")
			return errors.New("Invalid option")
		}

		rcs := new(DBRcs)
		rcs.Init(config)
		if create := config.Get("ddl.create", ""); create != "" {
			if _, _, err := rcs.CreateNextRev("sql/patches", create); err != nil {
				log.Fatalf("Could not create a new revision: %s", err.Error())
			}
			return errors.New("Invalid revision")
		}

		if config.GetFlag("ddl.upgrade") {
			err := rcs.Upgrade("sql/patches", true)
			if err != nil {
				log.Fatalf("Could not upgrade database: %s", err.Error())
			}
			return errors.New("Invalid database upgrade")
		}

		if down := config.Get("ddl.downgrade", ""); down != "" {
			err := rcs.Downgrade("sql/patches", down)
			if err != nil {
				log.Fatalf("Could not downgrade database: %s", err.Error())
			}
			return err
		}

		if config.GetFlag("ddl.log") {
			err := rcs.Changelog("sql/patches")
			if err != nil {
				log.Fatalf("Could not get changelog: %s", err.Error())
			}
			return err
		}
	}
	return nil
}
Beispiel #2
0
func SendPush(devRec *storage.Device, config *util.MzConfig) error {
	// wow, so very tempted to make sure this matches the known push server.
	if config.GetFlag("push.disabled") {
		return nil
	}
	/* Must provide a version value for some push servers. This value
	   is meaningless to FMD. */
	bbody := []byte(fmt.Sprintf("version=%d", time.Now().UTC().Unix()))
	body := bytes.NewReader(bbody)
	/* If your server is not trustfully signed, the following will fail.
	   If partners are unable/unwilling to trustfully sign servers,
	   it is possible to skip validation by using
	    &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}
	   however that is not advised as a general policy for damn good reasons.

	*/
	tr := &http.Transport{
		TLSClientConfig: &tls.Config{
		//NameToCertificate: config["partnerCertPool"],
		//InsecureSkipVerify: true,
		},
	}

	req, err := http.NewRequest("PUT", devRec.PushUrl, body)
	if err != nil {
		return err
	}
	cli := http.Client{Transport: tr}
	resp, err := cli.Do(req)
	// Close the body, otherwise Memory leak!
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	if resp.StatusCode != 200 {
		return errors.New("Push Server Error")
	}
	return nil
}