コード例 #1
0
ファイル: deceive.go プロジェクト: paultag/deceive
func GetConfig() Deceive {
	conf := Deceive{
		Host:   "localhost",
		Port:   1984,
		Cert:   "/etc/deceive/deceive.crt",
		Key:    "/etc/deceive/deceive.key",
		CaCert: "/etc/deceive/ca.crt",
		Root:   "/var/lib/deceive/",
	}
	flags, err := config.LoadFlags("deceive", &conf)
	if err != nil {
		panic(err)
	}
	flags.Parse(os.Args[1:])

	if !path.IsAbs(conf.Root) {
		cwd, err := os.Getwd()
		if err != nil {
			panic(err)
		}
		conf.Root = path.Clean(path.Join(cwd, conf.Root))
	}

	return conf
}
コード例 #2
0
ファイル: main.go プロジェクト: paultag/minion
func main() {
	conf := minion.MinionConfig{
		Host: "localhost",
		Mode: "minion",
		Port: 8765,
	}

	flags, err := config.LoadFlags("minion", &conf)
	if err != nil {
		panic(err)
	}

	flags.Parse(os.Args[1:])

	args := flags.Args()
	if len(args) == 0 {
		flags.Usage()
		return
	}

	for _, command := range commands {
		if command.Name == args[0] {
			command.Flag.Parse(args[1:])
			args = command.Flag.Args()
			command.Run(conf, command, args)
			return
		}
	}

	flags.Usage()
	return
}
コード例 #3
0
ファイル: main.go プロジェクト: paultag/descend
func main() {
	conf := descend.Descend{
		Host: "localhost",
		Port: 443,
	}
	flags, err := config.LoadFlags("descend", &conf)
	if err != nil {
		panic(err)
	}
	flags.Parse(os.Args[1:])
	Missing(flags, conf.CaCert, conf.Cert, conf.Key)

	client, err := descend.NewClient(conf.CaCert, conf.Cert, conf.Key)
	if err != nil {
		panic(err)
	}

	for _, changesPath := range flags.Args() {
		changes, err := control.ParseChangesFile(changesPath)
		if err != nil {
			panic(err)
		}

		fmt.Printf("Pushing %s\n", changesPath)
		err = descend.DoPutChanges(
			client, changes,
			fmt.Sprintf("%s:%d", conf.Host, conf.Port),
			conf.Archive,
		)
		if err != nil {
			panic(err)
		}
	}
}
コード例 #4
0
ファイル: main.go プロジェクト: paultag/log
func main() {
	when := time.Now()
	conf := Log{Root: "log/", Action: "write"}
	flags, err := config.LoadFlags("log", &conf)
	if err != nil {
		panic(err)
	}
	flags.Parse(os.Args[1:])

	if conf.When != "" {
		nWhen, err := time.Parse("2006-01-02", conf.When)
		if err != nil {
			/* last ditch */
			duration, err := time.ParseDuration(conf.When)
			if err != nil {
				panic(err)
			}
			when = when.Add(duration)
		} else {
			when = nWhen
		}
	}

	switch conf.Action {
	case "ls":
		Listit(conf, when)
		return
	case "write":
		if len(flags.Args()) == 0 {
			Listit(conf, when)
			return
		}
		if err := Logit(conf.Root, when, strings.Join(flags.Args(), " ")); err != nil {
			panic(err)
		}
		return
	default:
		Help()
		return
	}

}
コード例 #5
0
ファイル: enqueued.go プロジェクト: paultag/enqueued
func main() {
	flags, err := config.LoadFlags("enqueued", &conf)
	if err != nil {
		log.Fatal(err)
	}
	flags.Parse(os.Args[1:])
	os.Chdir(conf.Root)

	if conf.Templates != "" {
		enqueuedMailer, err = mailer.NewMailer(conf.Templates)
		if err != nil {
			log.Fatal(err)
		}
	}

	files, err := ioutil.ReadDir(conf.Root)
	if err != nil {
		log.Fatal(err)
	}

	watcher, err := inotify.NewWatcher()
	if err != nil {
		log.Fatal(err)
	}

	for _, file := range files {
		if err := Watch(watcher, file); err != nil {
			log.Fatal(err)
		}
	}

	for {
		select {
		case ev := <-watcher.Event:
			if ev.Mask^inotify.IN_CLOSE_WRITE != 0 ||
				!strings.HasSuffix(ev.Name, ".changes") {
				continue
			}
			Process(ev.Name)
		}
	}
}
コード例 #6
0
ファイル: main.go プロジェクト: paultag/minica
func main() {
	conf := MiniCA{
		Type:      "auto",
		Org:       "Example Organization",
		KeySize:   2048,
		CaCert:    "cacert.crt",
		CaKey:     "cakey.key",
		CaKeySize: 2048,
	}
	flags, err := config.LoadFlags("minica", &conf)
	if err != nil {
		panic(err)
	}

	flags.Parse(os.Args[1:])

	if len(flags.Args()) == 0 {
		flags.Usage()
		return
	}

	if Missing(conf.CaCert, conf.CaKey) {
		if err := GenerateCACertificate(
			conf.CaCert, conf.CaKey,
			conf.Org, conf.CaCommonName,
			conf.CaKeySize,
		); err != nil {
			panic(err)
		}
	}

	var isClientCert bool
	for _, cn := range flags.Args() {
		switch conf.Type {
		case "client":
			isClientCert = true
		case "server":
			isClientCert = false
		case "auto":
			isClientCert = strings.Contains(cn, "@")
		default:
			fmt.Printf(`Unknown cert type!

Currently supported types:

	client
	server
	auto     (guess based on @ in CommonName)

`)
			flags.Usage()
			os.Exit(2)
		}

		newCrt := fmt.Sprintf("%s.crt", cn)
		newKey := fmt.Sprintf("%s.key", cn)

		fmt.Printf(`Creating a %s cert:

Client Cert: %t
Common Name: %s
Org:         %s
Cert Flavor: %s
Output crt:  %s
Output key:  %s
`, conf.Type, isClientCert, cn, conf.Org, conf.Type, newCrt, newKey)

		if err := GenerateCert(
			[]string{cn},
			newCrt, newKey, conf.CaCert, conf.CaKey,
			conf.Org, cn,
			conf.KeySize,
			isClientCert,
		); err != nil {
			panic(err)
		}
	}
}