serve

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &cli.Command{
	Name:    "serve",
	Usage:   "Start Komagome PKI HTTPS/gRPC API Server",
	Aliases: []string{"s", "srv"},
	Flags: append(structflags.MustPopulateFlagsFromStruct(serve.Config{}),
		&cli.BoolFlag{
			Name:  "bootstrap",
			Usage: "enable node bootstrapping via (generated) token.",
		},
		&cli.StringFlag{
			Name:  "bootstrap-token",
			Usage: "enable node bootstrapping using the specified token.",
		},
		&cli.PathFlag{
			Name:  "bootstrap-token-file",
			Usage: "enable node bootstrapping using the specified token file.",
		},
	),
	Action: func(c *cli.Context) error {
		env := action.GlobalEnvironment

		cfg, err := serve.DefaultConfig()
		if err != nil {
			return err
		}
		if err := structflags.PopulateStructFromCliContext(cfg, c); err != nil {
			return err
		}

		if !c.IsSet("auto-shutdown") && cfg.IssueHttp > 0 {
			cfg.AutoShutdown = IssueHttpDefaultShutdown
		}

		if c.IsSet("bootstrap") || c.IsSet("bootstrap-token") {
			if c.IsSet("bootstrap-token-file") {
				return errors.New("--bootstrap-token-file can't be specified when --bootstrap,--bootstrap-token is specified.")
			}

			token := c.String("bootstrap-token")
			if token == "" {
				token, err = wcrypto.GenBase64Token(env.Randr, env.Logger)
				if err != nil {
					return err
				}
			}
			cfg.Bootstrap = &serve.FixedTokenAuthProvider{
				Token:    token,
				NotAfter: time.Now().Add(15 * time.Minute),
				Logger:   env.Logger,
			}
		} else if c.IsSet("bootstrap-token-file") {
			ta, err := serve.NewTokenFileAuthProvider(
				c.String("bootstrap-token-file"), env.Logger)
			if err != nil {
				return fmt.Errorf("Failed to initialize tokenFileAuthProvider: %w", err)
			}
			cfg.Bootstrap = ta
		}

		return serve.Run(c.Context, env, cfg)
	},
}
View Source
var IssueHttpDefaultShutdown = 5 * time.Minute

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL