示例#1
0
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
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)
		}
	}
}