Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v13] Add --silent flag to teleport node configure command #29587

Merged
merged 1 commit into from Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/config/fileconf.go
Expand Up @@ -185,6 +185,8 @@ type SampleFlags struct {
JoinMethod string
// NodeName is the name of the teleport node
NodeName string
// Silent suppresses user hint printed after config has been generated.
Silent bool
}

// MakeSampleFileConfig returns a sample config to start
Expand Down
31 changes: 21 additions & 10 deletions tool/teleport/common/teleport.go
Expand Up @@ -19,6 +19,7 @@ package common
import (
"context"
"fmt"
"io"
"net/url"
"os"
"os/user"
Expand Down Expand Up @@ -410,6 +411,7 @@ func Run(options Options) (app *kingpin.Application, executedCommand string, con
dumpNodeConfigure.Flag("ca-pin", "Comma-separated list of SKPI hashes for the CA used to verify the auth server.").StringVar(&dumpFlags.CAPin)
dumpNodeConfigure.Flag("join-method", "Method to use to join the cluster (token, iam, ec2, kubernetes)").Default("token").EnumVar(&dumpFlags.JoinMethod, "token", "iam", "ec2", "kubernetes", "azure")
dumpNodeConfigure.Flag("node-name", "Name for the Teleport node.").StringVar(&dumpFlags.NodeName)
dumpNodeConfigure.Flag("silent", "Suppress user hint message.").BoolVar(&dumpFlags.Silent)

waitCmd := app.Command(teleport.WaitSubCommand, "Used internally by Teleport to onWait until a specific condition is reached.").Hidden()
waitNoResolveCmd := waitCmd.Command("no-resolve", "Used internally to onWait until a domain stops resolving IP addresses.").Hidden()
Expand Down Expand Up @@ -592,6 +594,7 @@ type dumpFlags struct {
config.SampleFlags
output string
testConfigFile string
stdout io.Writer
}

func (flags *dumpFlags) CheckAndSetDefaults() error {
Expand All @@ -605,6 +608,14 @@ func (flags *dumpFlags) CheckAndSetDefaults() error {
}

flags.output = normalizeOutput(flags.output)

if flags.stdout == nil {
flags.stdout = os.Stdout
}
if flags.Silent {
flags.stdout = io.Discard
}

return nil
}

Expand Down Expand Up @@ -706,26 +717,26 @@ func onConfigDump(flags dumpFlags) error {
}
requiresRoot := !canWriteToDataDir || !canWriteToConfDir

fmt.Printf("\nA Teleport configuration file has been created at %q.\n", configPath)
fmt.Fprintf(flags.stdout, "\nA Teleport configuration file has been created at %q.\n", configPath)
if modules.GetModules().BuildType() != modules.BuildOSS {
fmt.Printf("Add your Teleport license file to %q.\n", flags.LicensePath)
fmt.Fprintf(flags.stdout, "Add your Teleport license file to %q.\n", flags.LicensePath)
}
fmt.Printf("To start Teleport with this configuration file, run:\n\n")
fmt.Fprintf(flags.stdout, "To start Teleport with this configuration file, run:\n\n")
if requiresRoot {
fmt.Printf("sudo teleport start --config=%q\n\n", configPath)
fmt.Printf("Note that starting a Teleport server with this configuration will require root access as:\n")
fmt.Fprintf(flags.stdout, "sudo teleport start --config=%q\n\n", configPath)
fmt.Fprintf(flags.stdout, "Note that starting a Teleport server with this configuration will require root access as:\n")
if !canWriteToConfDir {
fmt.Printf("- The Teleport configuration is located at %q.\n", configPath)
fmt.Fprintf(flags.stdout, "- The Teleport configuration is located at %q.\n", configPath)
}
if !canWriteToDataDir {
fmt.Printf("- Teleport will be storing data at %q. To change that, run \"teleport configure\" with the \"--data-dir\" flag.\n", flags.DataDir)
fmt.Fprintf(flags.stdout, "- Teleport will be storing data at %q. To change that, run \"teleport configure\" with the \"--data-dir\" flag.\n", flags.DataDir)
}
fmt.Println()
fmt.Fprintf(flags.stdout, "\n")
} else {
fmt.Printf("teleport start --config=%q\n\n", configPath)
fmt.Fprintf(flags.stdout, "teleport start --config=%q\n\n", configPath)
}

fmt.Printf("Happy Teleporting!\n")
fmt.Fprintf(flags.stdout, "Happy Teleporting!\n")
}

return nil
Expand Down
15 changes: 15 additions & 0 deletions tool/teleport/common/teleport_test.go
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package common

import (
"bytes"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -187,6 +188,20 @@ func TestConfigure(t *testing.T) {
err := flags.CheckAndSetDefaults()
require.NoError(t, err)
})

t.Run("Suppress output", func(t *testing.T) {
tempDir := t.TempDir()
var stdout bytes.Buffer
err := onConfigDump(dumpFlags{
SampleFlags: config.SampleFlags{
Silent: true,
},
output: filepath.Join(tempDir, "teleport.yaml"),
stdout: &stdout,
})
require.NoError(t, err)
require.Empty(t, stdout.Bytes())
})
}

func TestDumpConfigFile(t *testing.T) {
Expand Down