func main() {
	flag.Parse()

	if *flLdapHost == "" {
		flag.Usage()
		glog.Fatal("kubernetes-ldap: --ldap-host arg is required")
	}

	if *flBaseDN == "" {
		flag.Usage()
		glog.Fatal("kubernetes-ldap: --ldap-base-dn arg is required")
	}

	if *flSearchUserDN == "" {
		flag.Usage()
		glog.Fatal("kubernetes-ldap: --ldap-search-user-dn arg is required")
	}

	if *flSearchUserPassword == "" {
		flag.Usage()
		glog.Fatal("kubernetes-ldap: --ldap-search-user-password arg is required")
	}

	if *flApiserver == "" {
		flag.Usage()
		glog.Fatal("kubernetes-ldap: --apiserver arg is required")
	}

	// glog.CopyStandardLogTo("INFO")

	l := auth.NewLdapAuth(*flLdapHost, *flLdapPort, *flInsecure, *flBaseDN, *flUserLoginAttribute, *flSearchUserDN, *flSearchUserPassword)

	target, err := url.Parse(*flApiserver)
	if err != nil {
		glog.Fatal(err)
	}
	proxy := NewSingleHostReverseProxy(target)

	server := &http.Server{Addr: fmt.Sprintf(":%d", *flPort)}

	http.Handle("/", l.Authenticate(proxy))

	glog.Infof("Serving on %s", fmt.Sprintf(":%d", *flPort))

	// TODO(bc): enable cert-dir flag

	if *flTLSCertFile != "" && *flTLSPrivateKeyFile != "" {

		server.TLSConfig = &tls.Config{
			// Change default from SSLv3 to TLSv1.0 (because of POODLE vulnerability)
			MinVersion: tls.VersionTLS10,
		}
		glog.Fatal(server.ListenAndServeTLS(*flTLSCertFile, *flTLSPrivateKeyFile))

	} else {
		glog.Fatal(server.ListenAndServe())
	}

}
Esempio n. 2
0
func main() {
	flag.Parse()
	httpRE = regexp.MustCompile(*prefix + `(.*\.md)`)

	if *rootDir == "" || *repoRoot == "" || *prefix == "" {
		flag.Usage()
		os.Exit(2)
	}
	invalidLink := false
	if err := filepath.Walk(*rootDir, newWalkFunc(&invalidLink)); err != nil {
		fmt.Fprintf(os.Stderr, "Fail: %v.\n", err)
		os.Exit(2)
	}
	if invalidLink {
		os.Exit(1)
	}
}
Esempio n. 3
0
func parseFlagsAndArgs() []string {
	flag.BoolVarP(&verboseFlag, "verbose", "v", false, "Verbose mode")
	flag.BoolVarP(&helpFlag, "help", "h", false, "help")
	flag.Parse()
	if verboseFlag {
		log.Level = logrus.DebugLevel
	}
	if err := flag.CommandLine.Parse(os.Args[1:]); err != nil {
		flag.Usage()
		os.Exit(1)
	}
	args := flag.Args()
	if len(args) < 2 {
		return []string{args[0], ""}
	}
	return args
}
Esempio n. 4
0
func main() {
	flag.Parse()

	if *rootDir == "" {
		flag.Usage()
		os.Exit(2)
	}
	client := http.Client{
		Timeout: time.Duration(5 * time.Second),
	}
	invalidLink := false
	if err := filepath.Walk(*rootDir, newWalkFunc(&invalidLink, &client)); err != nil {
		fmt.Fprintf(os.Stderr, "Fail: %v.\n", err)
		os.Exit(2)
	}
	if invalidLink {
		os.Exit(1)
	}
}
Esempio n. 5
0
File: main.go Progetto: bryanwb/kh
// This doesn't use a cli argument parser because such libraries typically cannot
// handle subcommands that are dynamically loaded
// For this reason cli parsing is done manually
func main() {
	args, parseErr := parseFlagsAndArgs()
	h, _ := makeHand()
	if fingerInvoked(h, args[0]) {
		executeFinger(h, args[0])
		os.Exit(0)
	}
	cmd := args[0]
	// since not executing our finger, throw an error
	// if we see unknown flags
	if parseErr != nil {
		// flush any parsing errors encountered
		// while parsing command line earlier
		fmt.Fprint(os.Stderr, flagParsingOut.String())
		flag.Usage()
		os.Exit(1)
	}
	switch cmd {
	case "version":
		showVersion()
	case "help":
		showHelp(h)
	case "update":
		executeUpdate(h, kh.StripFlags(os.Args[2:]))
	case "init":
		doInit()
	case "install":
		doInstall(h, os.Args[2:])
	case "":
		showHelp(h)
	case "list":
		showList(h)
	default:
		fmt.Printf("Unknown finger or subcommand \"%s\"\nType `kh list` to see available fingers\n", cmd)
	}

}
Esempio n. 6
0
// Run the server.
func Run() {
	server.CloseOnAbort()

	flag.Usage = printUsage
	flag.Parse()

	if flagVersion != nil && *flagVersion {
		_, _, thisExeAbsPath := gotil.GetThisPathParts()
		fmt.Fprintf(os.Stdout, "Binary: %s\n", thisExeAbsPath)
		fmt.Fprint(os.Stdout, api.Version.String())
		os.Exit(0)
	}

	if flagEnv != nil && *flagEnv {
		for _, v := range os.Environ() {
			fmt.Fprintf(os.Stdout, "%s\n", v)
		}
		os.Exit(0)
	}

	// if a config is specified then do not care about any other options
	if flagConfig != nil && gotil.FileExists(*flagConfig) {

		config = gofigCore.New()

		if err := config.ReadConfigFile(*flagConfig); err != nil {
			fmt.Fprintf(os.Stderr, "%s: error: %v\n", os.Args[0], err)
			os.Exit(1)
		}

		if flagPrintConfig != nil && *flagPrintConfig {
			jstr, err := config.ToJSON()
			if err != nil {
				fmt.Fprintf(os.Stderr, "%s: error: %v\n", os.Args[0], err)
				os.Exit(1)
			}
			fmt.Fprintln(os.Stdout, jstr)
			os.Exit(0)
		}

		s, errs, err := server.Serve(nil, config)
		if err != nil {
			fmt.Fprintf(os.Stderr, "%s: error: %v\n", os.Args[0], err)
			os.Exit(1)
		}

		err = <-errs
		if err != nil {
			fmt.Fprintf(os.Stderr, "%s: error: %v\n", os.Args[0], err)
			os.Exit(1)
		}

		s.Close()
		os.Exit(0)
	}

	cfg, err := apiconfig.NewConfig()
	if err != nil {
		fmt.Fprintf(os.Stderr, "%s: error: %v\n", os.Args[0], err)
		os.Exit(1)
	}

	config = cfg
	for _, fs := range config.FlagSets() {
		flag.CommandLine.AddFlagSet(fs)
	}

	if flagHelp != nil && *flagHelp {
		flag.Usage()
	}

	if len(flag.Args()) == 0 {
		flag.Usage()
	}

	if flagHost != nil {
		os.Setenv("LIBSTORAGE_HOST", *flagHost)
	}

	if flagLogLvl != nil {
		os.Setenv("LIBSTORAGE_LOGGING_LEVEL", *flagLogLvl)
	}

	if lvl, err := log.ParseLevel(
		config.GetString(apitypes.ConfigLogLevel)); err == nil {
		log.SetLevel(lvl)
	}

	if flagPrintConfig != nil && *flagPrintConfig {
		jstr, err := config.ToJSON()
		if err != nil {
			fmt.Fprintf(os.Stderr, "%s: error: %v\n", os.Args[0], err)
			os.Exit(1)
		}
		fmt.Fprintln(os.Stdout, jstr)
		os.Exit(0)
	}

	buf := &bytes.Buffer{}
	fmt.Fprintf(buf, "libstorage:\n  server:\n    services:\n")
	for _, ds := range flag.Args() {
		dsp := strings.Split(ds, ":")
		dn := dsp[0]
		sn := dsp[0]
		if len(dsp) > 1 {
			sn = dsp[1]
		}
		fmt.Fprintf(buf, "      %s:\n        driver: %s\n", sn, dn)
	}
	if err := config.ReadConfig(buf); err != nil {
		fmt.Fprintf(os.Stderr, "%s: error: %v\n", os.Args[0], err)
		os.Exit(1)
	}

	server.CloseOnAbort()

	_, errs, err := server.Serve(nil, config)
	if err != nil {
		fmt.Fprintf(os.Stderr, "%s: error: %v\n", os.Args[0], err)
		os.Exit(1)
	}

	<-errs
}
Esempio n. 7
0
// Usage prints the flag usage
func Usage() {
	pflag.Usage()
}