Ver Fonte

Add --quiet flag

Carl Tashian há 4 anos atrás
pai
commit
91be50cf70
2 ficheiros alterados com 22 adições e 4 exclusões
  1. 15 3
      ca/ca.go
  2. 7 1
      commands/app.go

+ 15 - 3
ca/ca.go

@@ -31,6 +31,7 @@ import (
 type options struct {
 	configFile      string
 	linkedCAToken   string
+	quiet           bool
 	password        []byte
 	issuerPassword  []byte
 	sshHostPassword []byte
@@ -101,6 +102,14 @@ func WithLinkedCAToken(token string) Option {
 	}
 }
 
+// WithQuiet sets the quiet flag.
+func WithQuiet(quiet bool) Option {
+	return func(o *options) {
+		o.quiet = quiet
+	}
+}
+
+
 // CA is the type used to build the complete certificate authority. It builds
 // the HTTP server, set ups the middlewares and the HTTP handlers.
 type CA struct {
@@ -288,9 +297,11 @@ func (ca *CA) Run() error {
 	var wg sync.WaitGroup
 	errs := make(chan error, 1)
 
-	log.Printf("Documentation: https://u.step.sm/docs/ca")
-	log.Printf("Community Discord: https://u.step.sm/discord")
-	log.Printf("Config File: %s", ca.opts.configFile)
+	if !ca.opts.quiet {
+		log.Printf("Documentation: https://u.step.sm/docs/ca")
+		log.Printf("Community Discord: https://u.step.sm/discord")
+		log.Printf("Config File: %s", ca.opts.configFile)
+	}
 
 	if ca.insecureSrv != nil {
 		wg.Add(1)
@@ -359,6 +370,7 @@ func (ca *CA) Reload() error {
 		WithSSHUserPassword(ca.opts.sshUserPassword),
 		WithIssuerPassword(ca.opts.issuerPassword),
 		WithLinkedCAToken(ca.opts.linkedCAToken),
+		WithQuiet(ca.opts.quiet),
 		WithConfigFile(ca.opts.configFile),
 		WithDatabase(ca.auth.GetDatabase()),
 	)

+ 7 - 1
commands/app.go

@@ -57,6 +57,10 @@ certificate issuer private key used in the RA mode.`,
 			Usage:  "token used to enable the linked ca.",
 			EnvVar: "STEP_CA_TOKEN",
 		},
+		cli.BoolFlag{
+			Name: "quiet",
+			Usage: "disable startup information",
+		},
 	},
 }
 
@@ -68,6 +72,7 @@ func appAction(ctx *cli.Context) error {
 	issuerPassFile := ctx.String("issuer-password-file")
 	resolver := ctx.String("resolver")
 	token := ctx.String("token")
+	quiet := ctx.Bool("quiet")
 
 	// If zero cmd line args show help, if >1 cmd line args show error.
 	if ctx.NArg() == 0 {
@@ -141,7 +146,8 @@ To get a linked authority token:
 		ca.WithSSHHostPassword(sshHostPassword),
 		ca.WithSSHUserPassword(sshUserPassword),
 		ca.WithIssuerPassword(issuerPassword),
-		ca.WithLinkedCAToken(token))
+		ca.WithLinkedCAToken(token),
+		ca.WithQuiet(quiet))
 	if err != nil {
 		fatal(err)
 	}