cli: format output in writeOutput

This commit is contained in:
Thomas Tendyck 2022-04-05 09:13:09 +02:00 committed by Thomas Tendyck
parent ea4b9d2d85
commit dbfbdfe3cd

View File

@ -8,6 +8,7 @@ import (
"io"
"io/fs"
"net"
"text/tabwriter"
"github.com/edgelesssys/constellation/cli/azure"
"github.com/edgelesssys/constellation/cli/file"
@ -228,24 +229,34 @@ func (r activationResult) writeWGQuickFile(fileHandler file.Handler, config *con
return fileHandler.Write(*config.WGQuickConfigPath, data, false)
}
func (r activationResult) writeOutput(w io.Writer, fileHandler file.Handler, config *config.Config) error {
fmt.Fprintln(w, "Your Constellation was successfully initialized.")
fmt.Fprintf(w, "Your WireGuard IP is %s\n", r.clientVpnIP)
fmt.Fprintf(w, "The Coordinator's public IP is %s\n", r.coordinatorPubIP)
fmt.Fprintf(w, "The Coordinator's public key is %s\n", r.coordinatorPubKey)
fmt.Fprintf(w, "The Constellation's owner identifier is %s\n", r.ownerID)
fmt.Fprintf(w, "The Constellation's unique identifier is %s\n", r.clusterID)
fmt.Fprintf(w, "Your WireGuard configuration file was written to %s\n", *config.WGQuickConfigPath)
func (r activationResult) writeOutput(wr io.Writer, fileHandler file.Handler, config *config.Config) error {
fmt.Fprint(wr, "Your Constellation was successfully initialized.\n\n")
tw := tabwriter.NewWriter(wr, 0, 0, 2, ' ', 0)
writeRow(tw, "Your WireGuard IP", r.clientVpnIP)
writeRow(tw, "Coordinator's public IP", r.coordinatorPubIP)
writeRow(tw, "Coordinator's public key", r.coordinatorPubKey)
writeRow(tw, "Constellation's owner identifier", r.ownerID)
writeRow(tw, "Constellation's unique identifier", r.clusterID)
writeRow(tw, "WireGuard configuration file", *config.WGQuickConfigPath)
writeRow(tw, "Kubernetes configuration", *config.AdminConfPath)
tw.Flush()
fmt.Fprintln(wr)
if err := fileHandler.Write(*config.AdminConfPath, []byte(r.kubeconfig), false); err != nil {
return err
return fmt.Errorf("write kubeconfig: %w", err)
}
fmt.Fprintf(w, "Your Constellation Kubernetes configuration was successfully written to %s\n", *config.AdminConfPath)
fmt.Fprintln(w, "\nYou can now connect to your Constellation by executing:")
fmt.Fprintf(w, "wg-quick up ./%s\n", *config.WGQuickConfigPath)
fmt.Fprintf(w, "export KUBECONFIG=\"$PWD/%s\"\n", *config.AdminConfPath)
fmt.Fprintln(wr, "You can now connect to your Constellation by executing:")
fmt.Fprintf(wr, "\twg-quick up ./%s\n", *config.WGQuickConfigPath)
fmt.Fprintf(wr, "\texport KUBECONFIG=\"$PWD/%s\"\n", *config.AdminConfPath)
return nil
}
func writeRow(wr io.Writer, col1 string, col2 string) {
fmt.Fprint(wr, col1, "\t", col2, "\n")
}
// evalFlagArgs gets the flag values and does preprocessing of these values like
// reading the content from file path flags and deriving other values from flag combinations.
func evalFlagArgs(cmd *cobra.Command, fileHandler file.Handler, config *config.Config) (flagArgs, error) {