コード例 #1
0
ファイル: app_test.go プロジェクト: oscarrr110/cert-tools
func TestApp_RunAsSubcommandParseFlags(t *testing.T) {
	var context *cli.Context

	a := cli.NewApp()
	a.Commands = []cli.Command{
		{
			Name: "foo",
			Action: func(c *cli.Context) {
				context = c
			},
			Flags: []cli.Flag{
				cli.StringFlag{
					Name:  "lang",
					Value: "english",
					Usage: "language for the greeting",
				},
			},
			Before: func(_ *cli.Context) error { return nil },
		},
	}
	a.Run([]string{"", "foo", "--lang", "spanish", "abcd"})

	expect(t, context.Args().Get(0), "abcd")
	expect(t, context.String("lang"), "spanish")
}
コード例 #2
0
ファイル: init.go プロジェクト: oscarrr110/cert-tools
func initAction(c *cli.Context) {

	err := utils.GenerateCACertificate(d.Path(caPrefix+crtSuffix), d.Path(caKeyPrefix+crtSuffix), c.String("organization"), c.Int("years"), c.Int("key-bits"))
	//	key, err := pkix.CreateRSAKey(c.Int("key-bits"))
	if err != nil {
		fmt.Fprintln(os.Stderr, "Create CA cert error:", err)
		os.Exit(1)
	} else {
		fmt.Println("Created ca/key complete")
	}
}
コード例 #3
0
ファイル: new_server.go プロジェクト: oscarrr110/cert-tools
func newCertAction(c *cli.Context) {

	if len(c.Args()) != 1 {
		fmt.Fprintln(os.Stderr, "cert file must be provided.")
		os.Exit(1)
	}

	certFileName := c.Args()[0]
	years := c.Int("years")
	bits := c.Int("key-bits")

	if c.IsSet("passphrase") {

	}

	ips := c.String("ips")
	ipArray := strings.Split(ips, ",")

	certFile := certFileName + crtSuffix
	keyFile := certFileName + "-key" + crtSuffix
	caFile := caPrefix + crtSuffix
	caKeyFile := caKeyPrefix + crtSuffix
	org := c.String("organization")
	commonName := c.String("common-name")

	err := utils.GenerateCert(ipArray, d.Path(certFile), d.Path(keyFile), d.Path(caFile), d.Path(caKeyFile), org, commonName, years, bits)
	if err != nil {
		fmt.Fprintln(os.Stderr, "Create Servcer cert error:", err)
		os.Exit(1)
	} else {
		fmt.Println("Create server/key complete")
	}

}