Example #1
0
func (d *Daemon) Start(addr string, dispatch *dispatcher.Dispatcher, done chan<- bool) error {
	conf := http.HttpConfiguration{Dispatcher: dispatch}

	addrUrl, err := url.Parse(addr)
	if err != nil {
		return err
	}
	hostPort := addrUrl.Host

	api, err := conf.Handler()
	if err != nil {
		return err
	}

	if d.keyPath != "" {
		config, err := encrypted.NewTokenConfiguration(filepath.Join(d.keyPath, "server"), filepath.Join(d.keyPath, "client.pub"))
		if err != nil {
			return fmt.Errorf("unable to load token configuration: %s", err.Error())
		}
		nethttp.Handle("/token/", nethttp.StripPrefix("/token", config.Handler(api)))
	}

	nethttp.Handle("/", api)

	log.Printf("Listening (HTTP) on %s ...", hostPort)
	return nethttp.ListenAndServe(hostPort, nil)
}
Example #2
0
func daemon(cmd *cobra.Command, args []string) {
	api := conf.Handler()
	nethttp.Handle("/", api)

	if keyPath != "" {
		config, err := encrypted.NewTokenConfiguration(filepath.Join(keyPath, "server"), filepath.Join(keyPath, "client.pub"))
		if err != nil {
			Fail(1, "Unable to load token configuration: %s", err.Error())
		}
		nethttp.Handle("/token/", nethttp.StripPrefix("/token", config.Handler(api)))
	}

	if err := systemd.Start(); err != nil {
		log.Fatal(err)
	}
	if err := containers.InitializeData(); err != nil {
		log.Fatal(err)
	}
	if err := Initialize(ForDaemon); err != nil {
		log.Fatal(err)
	}

	conf.Dispatcher.Start()

	log.Printf("Listening for HTTP on %s ...", listenAddr)
	log.Fatal(nethttp.ListenAndServe(listenAddr, nil))
}
Example #3
0
File: cmd.go Project: pmorie/geard
func (ctx *CommandContext) createToken(c *cobra.Command, args []string) {
	if len(args) != 1 {
		cmd.Fail(1, "Valid arguments: <content>")
	}

	if ctx.keyPath == "" {
		cmd.Fail(1, "You must specify --key-path to create a token")
	}
	config, err := encrypted.NewTokenConfiguration(filepath.Join(ctx.keyPath, "client"), filepath.Join(ctx.keyPath, "server.pub"))
	if err != nil {
		cmd.Fail(1, "Unable to load token configuration: %s", err.Error())
	}

	value, err := config.Sign(args[0], "key", ctx.expiresAt)
	if err != nil {
		cmd.Fail(1, "Unable to sign this request: %s", err.Error())
	}
	fmt.Printf("%s", value)
	os.Exit(0)
}
Example #4
0
func createToken(cmd *cobra.Command, args []string) {
	if len(args) != 2 {
		Fail(1, "Valid arguments: <type> <content_id>")
	}

	if keyPath == "" {
		Fail(1, "You must specify --key-path to create a token")
	}
	config, err := encrypted.NewTokenConfiguration(filepath.Join(keyPath, "client"), filepath.Join(keyPath, "server.pub"))
	if err != nil {
		Fail(1, "Unable to load token configuration: %s", err.Error())
	}

	job := &cjobs.ContentRequest{Locator: args[1], Type: args[0]}
	value, err := config.Sign(job, "key", expiresAt)
	if err != nil {
		Fail(1, "Unable to sign this request: %s", err.Error())
	}
	fmt.Printf("%s", value)
	os.Exit(0)
}