Example #1
0
func main() {
	kingpin.UsageTemplate(kingpin.CompactUsageTemplate).Version("1.0").Author("Alec Thomas")
	kingpin.CommandLine.Help = "An example implementation of curl."
	switch kingpin.Parse() {
	case "get url":
		kingpin.FatalIfError(apply("GET", (*getURLURL).String()), "GET failed")

	case "post":
		kingpin.FatalIfError(applyPOST(), "POST failed")
	}
}
Example #2
0
func main() {
	kingpin.UsageTemplate(kingpin.DefaultUsageTemplate).Author("Cathal Garvey")
	//kingpin.CommandLine.Help = "miniLock-cli: The miniLock encryption system for terminal/scripted use."
	switch kingpin.Parse() {
	case "encrypt":
		kingpin.FatalIfError(encryptFile(), "Failed to encrypt..")
	case "decrypt":
		{
			kingpin.FatalIfError(decryptFile(), "Failed to decrypt..")
		}
	default:
		{
			fmt.Println("No subcommand provided..")
		}
	}
	if userKey != nil {
		userKey.Wipe()
	}
}
Example #3
0
File: main.go Project: xrstf/raziel
func main() {
	kingpin.UsageTemplate(kingpin.CompactUsageTemplate).Version("1.0").Author("Christoph Mewes")
	kingpin.CommandLine.Help = "HTTP application server to run the Raziel secret management"
	kingpin.Parse()

	if *configFile == "" {
		kingpin.FatalUsage("No configuration file (--config) given!")
	}

	// load config file
	err := loadConfigFile()
	if err != nil {
		kingpin.FatalUsage(err.Error())
	}

	// connect to database
	database, err := sqlx.Connect("mysql", config.Database.Source)
	if err != nil {
		kingpin.FatalUsage(err.Error())
	}

	validateMasterPassword(database)

	// init restriction handlers
	restrictionHandlers = make(map[string]RestrictionHandler)
	addRestrictionHandler(ApiKeyRestriction{})
	addRestrictionHandler(TlsCertRestriction{})
	addRestrictionHandler(OriginIpRestriction{})
	addRestrictionHandler(DateRestriction{})
	addRestrictionHandler(TimeRestriction{})
	addRestrictionHandler(FileRestriction{})
	addRestrictionHandler(HitLimitRestriction{})
	addRestrictionHandler(ThrottleRestriction{})

	// init templates
	templateManager = NewTemplateManager("templates")

	// setup basic Martini server

	martini.Env = martini.Dev

	if config.Environment == "production" || config.Environment == "prod" {
		martini.Env = martini.Prod
	}

	m := martini.New()
	m.Use(martini.Logger())
	m.Use(gzip.All())
	m.Use(martini.Recovery())
	m.Use(martini.Static("www"))
	m.Use(method.Override())

	// force all handlers to run inside a transaction

	m.Use(func(c martini.Context) {
		tx := database.MustBegin()

		defer func() {
			if r := recover(); r != nil {
				tx.Rollback()
				panic(r)
			}
		}()

		c.Map(tx)
		c.Next()

		err := tx.Commit()
		if err != nil {
			panic(err)
		}
	})

	// setup session and CSRF support

	duration, err := time.ParseDuration(config.Session.Lifetime)
	if err != nil {
		log.Fatal("Invalid session lifetime configured: " + err.Error())
	}

	sessions = NewSessionMiddleware(cookieOptions{
		Name:     config.Session.CookieName,
		MaxAge:   duration,
		HttpOnly: true,
		Secure:   config.Session.Secure,
	})

	sessions.Setup(m)

	// re-compile all templates on each hit

	if martini.Env != martini.Prod {
		m.Use(func() {
			templateManager.Init()
		})
	}

	// use a custom return handler to make our mini response structs possible
	// (this overwrites the existing handler)
	m.Map(newReturnHandler())

	r := martini.NewRouter()
	m.MapTo(r, (*martini.Routes)(nil))
	m.Action(r.Handle)

	martini := &martini.ClassicMartini{m, r}
	setupDashboardCtrl(martini)
	setupProfileCtrl(martini)
	setupLoginCtrl(martini)
	setupSecretsCtrl(martini)
	setupUsersCtrl(martini)
	setupConsumersCtrl(martini)
	setupAuditLogCtrl(martini)
	setupAccessLogCtrl(martini)
	setupDeliveryCtrl(martini)

	// setup our own http server and configure TLS
	srv := &http.Server{
		Addr:    config.Server.Listen,
		Handler: martini,
		TLSConfig: &tls.Config{
			CipherSuites: config.CipherSuites(),
		},
	}

	log.Fatal(srv.ListenAndServeTLS(config.Server.Certificate, config.Server.PrivateKey))
}